@ledgerhq/coin-tezos 6.5.0 → 6.6.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/.unimportedrc.json +4 -30
- package/CHANGELOG.md +13 -0
- package/jest.integ.config.js +1 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +188 -40
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +79 -10
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +7 -5
- package/lib/api/types.d.ts.map +1 -1
- package/lib/config.d.ts +4 -3
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +7 -0
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +1 -0
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +8 -2
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +119 -45
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getStakes.d.ts +3 -0
- package/lib/logic/getStakes.d.ts.map +1 -0
- package/lib/logic/getStakes.js +26 -0
- package/lib/logic/getStakes.js.map +1 -0
- package/lib/logic/getStakes.test.d.ts +2 -0
- package/lib/logic/getStakes.test.d.ts.map +1 -0
- package/lib/logic/getStakes.test.js +133 -0
- package/lib/logic/getStakes.test.js.map +1 -0
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +5 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +56 -10
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +14 -10
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +3 -0
- package/lib/logic/validateIntent.d.ts.map +1 -0
- package/lib/logic/validateIntent.js +179 -0
- package/lib/logic/validateIntent.js.map +1 -0
- package/lib/logic/validateIntent.test.d.ts +2 -0
- package/lib/logic/validateIntent.test.d.ts.map +1 -0
- package/lib/logic/validateIntent.test.js +249 -0
- package/lib/logic/validateIntent.test.js.map +1 -0
- package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -0
- package/lib/{bridge/transaction.js → transaction.js} +3 -3
- package/lib/transaction.js.map +1 -0
- package/lib/types/bridge.d.ts +3 -0
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.fixture.d.ts.map +1 -1
- package/lib/types/bridge.fixture.js +1 -0
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib/utils.d.ts +48 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +112 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +189 -41
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +79 -10
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +7 -5
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/config.d.ts +4 -3
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/index.d.ts +1 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +7 -0
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +1 -0
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +8 -2
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +119 -45
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +3 -0
- package/lib-es/logic/getStakes.d.ts.map +1 -0
- package/lib-es/logic/getStakes.js +20 -0
- package/lib-es/logic/getStakes.js.map +1 -0
- package/lib-es/logic/getStakes.test.d.ts +2 -0
- package/lib-es/logic/getStakes.test.d.ts.map +1 -0
- package/lib-es/logic/getStakes.test.js +128 -0
- package/lib-es/logic/getStakes.test.js.map +1 -0
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +2 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +56 -10
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +14 -10
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +3 -0
- package/lib-es/logic/validateIntent.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.js +173 -0
- package/lib-es/logic/validateIntent.js.map +1 -0
- package/lib-es/logic/validateIntent.test.d.ts +2 -0
- package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.test.js +221 -0
- package/lib-es/logic/validateIntent.test.js.map +1 -0
- package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types/bridge.d.ts +3 -0
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.js +1 -0
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/lib-es/utils.d.ts +48 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +105 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +9 -12
- package/src/api/index.test.ts +87 -15
- package/src/api/index.ts +204 -55
- package/src/api/types.ts +11 -6
- package/src/config.ts +9 -2
- package/src/index.ts +1 -2
- package/src/logic/craftTransaction.test.ts +1 -0
- package/src/logic/craftTransaction.ts +8 -0
- package/src/logic/estimateFees.integ.test.ts +8 -2
- package/src/logic/estimateFees.ts +140 -49
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/getStakes.test.ts +145 -0
- package/src/logic/getStakes.ts +20 -0
- package/src/logic/index.ts +2 -0
- package/src/logic/listOperations.test.ts +64 -54
- package/src/logic/listOperations.ts +57 -9
- package/src/logic/validateIntent.test.ts +262 -0
- package/src/logic/validateIntent.ts +207 -0
- package/src/{bridge/transaction.ts → transaction.ts} +4 -4
- package/src/types/bridge.fixture.ts +1 -0
- package/src/types/bridge.ts +6 -1
- package/src/utils.ts +115 -0
- package/lib/bridge/broadcast.d.ts +0 -4
- package/lib/bridge/broadcast.d.ts.map +0 -1
- package/lib/bridge/broadcast.js +0 -11
- package/lib/bridge/broadcast.js.map +0 -1
- package/lib/bridge/broadcast.test.d.ts +0 -2
- package/lib/bridge/broadcast.test.d.ts.map +0 -1
- package/lib/bridge/broadcast.test.js +0 -36
- package/lib/bridge/broadcast.test.js.map +0 -1
- package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib/bridge/buildOptimisticOperation.js +0 -28
- package/lib/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib/bridge/createTransaction.d.ts +0 -4
- package/lib/bridge/createTransaction.d.ts.map +0 -1
- package/lib/bridge/createTransaction.js +0 -24
- package/lib/bridge/createTransaction.js.map +0 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib/bridge/estimateMaxSpendable.js +0 -30
- package/lib/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib/bridge/getFeesForTransaction.js +0 -39
- package/lib/bridge/getFeesForTransaction.js.map +0 -1
- package/lib/bridge/getTransactionStatus.d.ts +0 -4
- package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.js +0 -108
- package/lib/bridge/getTransactionStatus.js.map +0 -1
- package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.test.js +0 -107
- package/lib/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib/bridge/index.d.ts +0 -10
- package/lib/bridge/index.d.ts.map +0 -1
- package/lib/bridge/index.js +0 -59
- package/lib/bridge/index.js.map +0 -1
- package/lib/bridge/logic.d.ts +0 -10
- package/lib/bridge/logic.d.ts.map +0 -1
- package/lib/bridge/logic.js +0 -155
- package/lib/bridge/logic.js.map +0 -1
- package/lib/bridge/preload.d.ts +0 -9
- package/lib/bridge/preload.d.ts.map +0 -1
- package/lib/bridge/preload.js +0 -23
- package/lib/bridge/preload.js.map +0 -1
- package/lib/bridge/prepareTransaction.d.ts +0 -5
- package/lib/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.js +0 -34
- package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib/bridge/prepareTransaction.js +0 -57
- package/lib/bridge/prepareTransaction.js.map +0 -1
- package/lib/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.test.js +0 -178
- package/lib/bridge/prepareTransaction.test.js.map +0 -1
- package/lib/bridge/serialization.d.ts +0 -7
- package/lib/bridge/serialization.d.ts.map +0 -1
- package/lib/bridge/serialization.js +0 -26
- package/lib/bridge/serialization.js.map +0 -1
- package/lib/bridge/signOperation.d.ts +0 -16
- package/lib/bridge/signOperation.d.ts.map +0 -1
- package/lib/bridge/signOperation.js +0 -88
- package/lib/bridge/signOperation.js.map +0 -1
- package/lib/bridge/signOperation.test.d.ts +0 -2
- package/lib/bridge/signOperation.test.d.ts.map +0 -1
- package/lib/bridge/signOperation.test.js +0 -283
- package/lib/bridge/signOperation.test.js.map +0 -1
- package/lib/bridge/synchronization.d.ts +0 -5
- package/lib/bridge/synchronization.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.js +0 -32
- package/lib/bridge/synchronization.integ.test.js.map +0 -1
- package/lib/bridge/synchronization.js +0 -100
- package/lib/bridge/synchronization.js.map +0 -1
- package/lib/bridge/transaction.d.ts.map +0 -1
- package/lib/bridge/transaction.js.map +0 -1
- package/lib-es/bridge/broadcast.d.ts +0 -4
- package/lib-es/bridge/broadcast.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.js +0 -7
- package/lib-es/bridge/broadcast.js.map +0 -1
- package/lib-es/bridge/broadcast.test.d.ts +0 -2
- package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.test.js +0 -31
- package/lib-es/bridge/broadcast.test.js.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.js +0 -21
- package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib-es/bridge/createTransaction.d.ts +0 -4
- package/lib-es/bridge/createTransaction.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.js +0 -17
- package/lib-es/bridge/createTransaction.js.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.js +0 -23
- package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.js +0 -33
- package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
- package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.js +0 -101
- package/lib-es/bridge/getTransactionStatus.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.js +0 -102
- package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib-es/bridge/index.d.ts +0 -10
- package/lib-es/bridge/index.d.ts.map +0 -1
- package/lib-es/bridge/index.js +0 -53
- package/lib-es/bridge/index.js.map +0 -1
- package/lib-es/bridge/logic.d.ts +0 -10
- package/lib-es/bridge/logic.d.ts.map +0 -1
- package/lib-es/bridge/logic.js +0 -145
- package/lib-es/bridge/logic.js.map +0 -1
- package/lib-es/bridge/preload.d.ts +0 -9
- package/lib-es/bridge/preload.d.ts.map +0 -1
- package/lib-es/bridge/preload.js +0 -17
- package/lib-es/bridge/preload.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.d.ts +0 -5
- package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.js +0 -50
- package/lib-es/bridge/prepareTransaction.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.js +0 -173
- package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
- package/lib-es/bridge/serialization.d.ts +0 -7
- package/lib-es/bridge/serialization.d.ts.map +0 -1
- package/lib-es/bridge/serialization.js +0 -20
- package/lib-es/bridge/serialization.js.map +0 -1
- package/lib-es/bridge/signOperation.d.ts +0 -16
- package/lib-es/bridge/signOperation.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.js +0 -83
- package/lib-es/bridge/signOperation.js.map +0 -1
- package/lib-es/bridge/signOperation.test.d.ts +0 -2
- package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.test.js +0 -255
- package/lib-es/bridge/signOperation.test.js.map +0 -1
- package/lib-es/bridge/synchronization.d.ts +0 -5
- package/lib-es/bridge/synchronization.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.js +0 -27
- package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
- package/lib-es/bridge/synchronization.js +0 -70
- package/lib-es/bridge/synchronization.js.map +0 -1
- package/lib-es/bridge/transaction.d.ts.map +0 -1
- package/lib-es/bridge/transaction.js.map +0 -1
- package/src/bridge/broadcast.test.ts +0 -36
- package/src/bridge/broadcast.ts +0 -13
- package/src/bridge/buildOptimisticOperation.ts +0 -28
- package/src/bridge/createTransaction.ts +0 -19
- package/src/bridge/estimateMaxSpendable.ts +0 -37
- package/src/bridge/getFeesForTransaction.ts +0 -49
- package/src/bridge/getTransactionStatus.test.ts +0 -124
- package/src/bridge/getTransactionStatus.ts +0 -123
- package/src/bridge/index.ts +0 -74
- package/src/bridge/logic.ts +0 -171
- package/src/bridge/preload.ts +0 -18
- package/src/bridge/prepareTransaction.integ.test.ts +0 -35
- package/src/bridge/prepareTransaction.test.ts +0 -205
- package/src/bridge/prepareTransaction.ts +0 -69
- package/src/bridge/serialization.ts +0 -27
- package/src/bridge/signOperation.test.ts +0 -284
- package/src/bridge/signOperation.ts +0 -130
- package/src/bridge/synchronization.integ.test.ts +0 -33
- package/src/bridge/synchronization.ts +0 -100
package/src/api/index.ts
CHANGED
|
@@ -21,11 +21,20 @@ import {
|
|
|
21
21
|
lastBlock,
|
|
22
22
|
listOperations,
|
|
23
23
|
rawEncode,
|
|
24
|
+
validateIntent,
|
|
25
|
+
getStakes,
|
|
24
26
|
} from "../logic";
|
|
25
27
|
import api from "../network/tzkt";
|
|
26
28
|
import type { TezosApi, TezosFeeEstimation } from "./types";
|
|
27
|
-
import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
28
|
-
import {
|
|
29
|
+
import type { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
30
|
+
import { RecommendUndelegation } from "@ledgerhq/errors";
|
|
31
|
+
import { validatePublicKey, ValidationResult, getPkhfromPk } from "@taquito/utils";
|
|
32
|
+
import { getRevealFee } from "@taquito/taquito";
|
|
33
|
+
import {
|
|
34
|
+
DUST_MARGIN_MUTEZ,
|
|
35
|
+
mapIntentTypeToTezosMode,
|
|
36
|
+
normalizePublicKeyForAddress,
|
|
37
|
+
} from "../utils";
|
|
29
38
|
|
|
30
39
|
export function createApi(config: TezosConfig): TezosApi {
|
|
31
40
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
@@ -38,31 +47,54 @@ export function createApi(config: TezosConfig): TezosApi {
|
|
|
38
47
|
getBalance: balance,
|
|
39
48
|
lastBlock,
|
|
40
49
|
listOperations: operations,
|
|
50
|
+
getStakes,
|
|
51
|
+
validateIntent,
|
|
52
|
+
// required by signer to compute next valid sequence/counter
|
|
53
|
+
getSequence: async (address: string) => {
|
|
54
|
+
const accountInfo = await api.getAccountByAddress(address);
|
|
55
|
+
return accountInfo.type === "user" ? accountInfo.counter + 1 : 0;
|
|
56
|
+
},
|
|
41
57
|
getBlock(_height): Promise<Block> {
|
|
42
58
|
throw new Error("getBlock is not supported");
|
|
43
59
|
},
|
|
44
60
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
45
61
|
throw new Error("getBlockInfo is not supported");
|
|
46
62
|
},
|
|
47
|
-
getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
|
|
48
|
-
throw new Error("getStakes is not supported");
|
|
49
|
-
},
|
|
50
63
|
getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
|
|
51
64
|
throw new Error("getRewards is not supported");
|
|
52
65
|
},
|
|
53
66
|
};
|
|
54
67
|
}
|
|
55
68
|
|
|
56
|
-
function isTezosTransactionType(
|
|
57
|
-
|
|
69
|
+
function isTezosTransactionType(
|
|
70
|
+
type: string,
|
|
71
|
+
): type is "send" | "delegate" | "undelegate" | "stake" | "unstake" {
|
|
72
|
+
return ["send", "delegate", "undelegate", "stake", "unstake"].includes(type);
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
async function balance(address: string): Promise<Balance[]> {
|
|
61
76
|
const value = await getBalance(address);
|
|
77
|
+
const accountInfo = await api.getAccountByAddress(address);
|
|
78
|
+
// tzkt returns `type: "empty"` for untouched accounts; legacy logic returns -1 in that case
|
|
79
|
+
// the generic bridge expects non-negative balances
|
|
80
|
+
const normalized = value < 0n ? 0n : value;
|
|
81
|
+
// include stake information so ui can reflect delegation on account page
|
|
82
|
+
const stake: Stake | undefined =
|
|
83
|
+
accountInfo.type === "user" && accountInfo.delegate?.address
|
|
84
|
+
? {
|
|
85
|
+
uid: address,
|
|
86
|
+
address,
|
|
87
|
+
delegate: accountInfo.delegate.address,
|
|
88
|
+
state: "active",
|
|
89
|
+
asset: { type: "native" },
|
|
90
|
+
amount: BigInt(accountInfo.balance ?? 0),
|
|
91
|
+
}
|
|
92
|
+
: undefined;
|
|
62
93
|
return [
|
|
63
94
|
{
|
|
64
|
-
value,
|
|
95
|
+
value: normalized,
|
|
65
96
|
asset: { type: "native" },
|
|
97
|
+
stake,
|
|
66
98
|
},
|
|
67
99
|
];
|
|
68
100
|
}
|
|
@@ -75,64 +107,180 @@ async function craft(
|
|
|
75
107
|
throw new IncorrectTypeError(transactionIntent.type);
|
|
76
108
|
}
|
|
77
109
|
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
// Always estimate to get gasLimit/storageLimit
|
|
111
|
+
const estimation = await estimate(transactionIntent);
|
|
112
|
+
const fee = {
|
|
113
|
+
fees: (customFees?.value ?? estimation.value).toString(),
|
|
114
|
+
gasLimit: estimation.parameters?.gasLimit?.toString(),
|
|
115
|
+
storageLimit: estimation.parameters?.storageLimit?.toString(),
|
|
116
|
+
};
|
|
84
117
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
type: transactionIntent.type,
|
|
89
|
-
recipient: transactionIntent.recipient,
|
|
90
|
-
amount: transactionIntent.amount,
|
|
91
|
-
fee,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
118
|
+
// Map generic staking intents to tezos modes
|
|
119
|
+
const mappedType = mapIntentTypeToTezosMode(transactionIntent.type);
|
|
94
120
|
|
|
95
|
-
|
|
121
|
+
// Guard: send max is incompatible with delegated accounts
|
|
122
|
+
let amountToUse = transactionIntent.amount;
|
|
123
|
+
if (mappedType === "send" && transactionIntent.useAllAmount) {
|
|
124
|
+
const senderInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
125
|
+
if (senderInfo.type === "user" && senderInfo.delegate?.address) {
|
|
126
|
+
throw new RecommendUndelegation();
|
|
127
|
+
}
|
|
128
|
+
if (senderInfo.type === "user") {
|
|
129
|
+
// Use the amount calculated by the estimation which includes proper buffers and adjustments
|
|
130
|
+
if (estimation.parameters?.amount !== undefined) {
|
|
131
|
+
amountToUse = estimation.parameters.amount;
|
|
132
|
+
} else {
|
|
133
|
+
// Fallback to the original calculation if estimation doesn't provide amount
|
|
134
|
+
const bal = BigInt(senderInfo.balance);
|
|
135
|
+
const feeBI = BigInt(fee.fees || "0");
|
|
136
|
+
const dustMargin = BigInt(DUST_MARGIN_MUTEZ);
|
|
137
|
+
const totalToDeduct = feeBI + dustMargin;
|
|
138
|
+
amountToUse = bal > totalToDeduct ? bal - totalToDeduct : 0n;
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
amountToUse = 0n;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const accountForCraft = {
|
|
146
|
+
address: transactionIntent.sender,
|
|
147
|
+
};
|
|
148
|
+
const senderApiAcc = await api.getAccountByAddress(transactionIntent.sender);
|
|
149
|
+
const needsReveal = senderApiAcc.type === "user" && !senderApiAcc.revealed;
|
|
150
|
+
const totalFee = Number(fee.fees || "0");
|
|
151
|
+
|
|
152
|
+
let txFee: number;
|
|
153
|
+
if (customFees) {
|
|
154
|
+
txFee = totalFee;
|
|
155
|
+
} else if (estimation.parameters?.txFee !== undefined) {
|
|
156
|
+
txFee = Number(estimation.parameters.txFee);
|
|
157
|
+
} else {
|
|
158
|
+
txFee = needsReveal ? Math.max(totalFee - getRevealFee(transactionIntent.sender), 0) : totalFee;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const txForCraft = {
|
|
162
|
+
type: mappedType,
|
|
163
|
+
recipient: transactionIntent.recipient,
|
|
164
|
+
amount: amountToUse,
|
|
165
|
+
fee: { ...fee, fees: txFee.toString() },
|
|
166
|
+
};
|
|
167
|
+
const publicKeyForCraft =
|
|
168
|
+
needsReveal && transactionIntent.senderPublicKey
|
|
169
|
+
? (() => {
|
|
170
|
+
// Accept either base58 or hex from device, and map curve using sender address
|
|
171
|
+
let pk = transactionIntent.senderPublicKey;
|
|
172
|
+
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
173
|
+
pk = normalizePublicKeyForAddress(pk, transactionIntent.sender) || pk;
|
|
174
|
+
}
|
|
175
|
+
// Verify the public key matches the sender address to avoid inconsistent_hash
|
|
176
|
+
let isPublicKeyValid = false;
|
|
177
|
+
try {
|
|
178
|
+
const derived = getPkhfromPk(pk);
|
|
179
|
+
isPublicKeyValid = derived === transactionIntent.sender;
|
|
180
|
+
} catch {
|
|
181
|
+
// getPkhfromPk failed = will fallback to basic validation below
|
|
182
|
+
isPublicKeyValid = false;
|
|
183
|
+
}
|
|
96
184
|
|
|
185
|
+
if (!isPublicKeyValid) {
|
|
186
|
+
// If derivation failed/doesn't match, check if the key is atleast valid format
|
|
187
|
+
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
188
|
+
throw new Error("Unable to normalize sender public key");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { publicKey: pk, publicKeyHash: transactionIntent.sender };
|
|
192
|
+
})()
|
|
193
|
+
: undefined;
|
|
194
|
+
const { contents } = await craftTransaction(accountForCraft, txForCraft, publicKeyForCraft);
|
|
195
|
+
const tx = await rawEncode(contents);
|
|
97
196
|
return { transaction: tx };
|
|
98
197
|
}
|
|
99
198
|
|
|
100
199
|
async function estimate(transactionIntent: TransactionIntent): Promise<TezosFeeEstimation> {
|
|
200
|
+
// avoid taquito error when estimating a 0-amount transfer during input
|
|
201
|
+
if (
|
|
202
|
+
transactionIntent.type === "send" &&
|
|
203
|
+
transactionIntent.amount === 0n &&
|
|
204
|
+
!transactionIntent.useAllAmount
|
|
205
|
+
) {
|
|
206
|
+
return {
|
|
207
|
+
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
208
|
+
parameters: {
|
|
209
|
+
gasLimit: 10000n,
|
|
210
|
+
storageLimit: 300n,
|
|
211
|
+
amount: 0n,
|
|
212
|
+
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
101
216
|
const senderAccountInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
217
|
+
// If the sender is not a user account, return default estimation values
|
|
218
|
+
if (senderAccountInfo.type !== "user") {
|
|
219
|
+
return {
|
|
220
|
+
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
221
|
+
parameters: {
|
|
222
|
+
gasLimit: 10000n,
|
|
223
|
+
storageLimit: 300n,
|
|
224
|
+
amount: 0n,
|
|
225
|
+
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
102
229
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
transactionIntent.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
amount: transactionIntent.amount,
|
|
122
|
-
},
|
|
123
|
-
});
|
|
230
|
+
try {
|
|
231
|
+
const estimation = await estimateFees({
|
|
232
|
+
account: {
|
|
233
|
+
address: transactionIntent.sender,
|
|
234
|
+
revealed: senderAccountInfo.revealed,
|
|
235
|
+
balance: BigInt(senderAccountInfo.balance),
|
|
236
|
+
// try intent public key first and fallback to tzkt public key
|
|
237
|
+
xpub: transactionIntent.senderPublicKey ?? senderAccountInfo.publicKey,
|
|
238
|
+
},
|
|
239
|
+
transaction: {
|
|
240
|
+
// reuse the same mapping as craft
|
|
241
|
+
mode: mapIntentTypeToTezosMode(transactionIntent.type),
|
|
242
|
+
recipient: transactionIntent.recipient,
|
|
243
|
+
amount: transactionIntent.amount,
|
|
244
|
+
// legacy estimator needs this flag to pre-estimate fees
|
|
245
|
+
useAllAmount: !!transactionIntent.useAllAmount,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
124
248
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
249
|
+
if (
|
|
250
|
+
estimation.taquitoError &&
|
|
251
|
+
!estimation.taquitoError.includes("delegate.unchanged") &&
|
|
252
|
+
!estimation.taquitoError.includes("subtraction_underflow") &&
|
|
253
|
+
!estimation.taquitoError.includes("balance_too_low")
|
|
254
|
+
) {
|
|
255
|
+
throw new Error(`Fees estimation failed: ${estimation.taquitoError}`);
|
|
256
|
+
}
|
|
128
257
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
258
|
+
return {
|
|
259
|
+
value: estimation.estimatedFees,
|
|
260
|
+
parameters: {
|
|
261
|
+
gasLimit: estimation.gasLimit,
|
|
262
|
+
storageLimit: estimation.storageLimit,
|
|
263
|
+
amount: estimation.amount,
|
|
264
|
+
txFee: estimation.fees,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
} catch (error: any) {
|
|
268
|
+
// Handle PublicKeyNotFoundError
|
|
269
|
+
if (error?.message?.includes("Public key not found")) {
|
|
270
|
+
return {
|
|
271
|
+
value: 1000n, // Safe default with reveal fees (500 + 374 reveal + buffer)
|
|
272
|
+
parameters: {
|
|
273
|
+
gasLimit: 10000n,
|
|
274
|
+
storageLimit: 300n,
|
|
275
|
+
amount: 0n,
|
|
276
|
+
txFee: 1000n,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
} else {
|
|
280
|
+
// Re-throw other errors
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
136
284
|
}
|
|
137
285
|
|
|
138
286
|
async function operations(
|
|
@@ -145,5 +293,6 @@ async function operations(
|
|
|
145
293
|
sort: pagination.order === "asc" ? "Ascending" : "Descending",
|
|
146
294
|
minHeight: pagination.minHeight,
|
|
147
295
|
});
|
|
296
|
+
|
|
148
297
|
return [operations, newNextCursor || ""];
|
|
149
298
|
}
|
package/src/api/types.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Api, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
|
|
3
|
-
export type TezosFeeParameters = {
|
|
4
|
-
|
|
3
|
+
export type TezosFeeParameters = {
|
|
4
|
+
gasLimit: bigint;
|
|
5
|
+
storageLimit: bigint;
|
|
6
|
+
amount?: bigint;
|
|
7
|
+
txFee?: bigint;
|
|
8
|
+
};
|
|
9
|
+
export type TezosFeeEstimation = FeeEstimation & {
|
|
10
|
+
parameters?: TezosFeeParameters & Record<string, unknown>;
|
|
11
|
+
};
|
|
5
12
|
|
|
6
13
|
export type TezosSender = { address: string; xpub?: string };
|
|
7
14
|
export type TezosTransactionIntent = TransactionIntent;
|
|
8
15
|
|
|
9
|
-
export type TezosApi =
|
|
10
|
-
estimateFees: (transactionIntent: TezosTransactionIntent) => Promise<TezosFeeEstimation>;
|
|
11
|
-
};
|
|
16
|
+
export type TezosApi = Api;
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import buildCoinConfig, {
|
|
1
|
+
import buildCoinConfig, {
|
|
2
|
+
type CoinConfig,
|
|
3
|
+
type CurrencyConfig,
|
|
4
|
+
} from "@ledgerhq/coin-framework/config";
|
|
5
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
6
|
|
|
3
7
|
export type TezosConfig = {
|
|
4
8
|
baker: {
|
|
@@ -22,6 +26,9 @@ export type TezosConfig = {
|
|
|
22
26
|
|
|
23
27
|
export type TezosCoinConfig = CurrencyConfig & TezosConfig;
|
|
24
28
|
|
|
25
|
-
const coinConfig
|
|
29
|
+
const coinConfig: {
|
|
30
|
+
setCoinConfig: (config: CoinConfig<TezosCoinConfig>) => void;
|
|
31
|
+
getCoinConfig: (currency?: CryptoCurrency) => TezosCoinConfig;
|
|
32
|
+
} = buildCoinConfig<TezosCoinConfig>();
|
|
26
33
|
|
|
27
34
|
export default coinConfig;
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { getRevealFee } from "@taquito/taquito";
|
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
5
5
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
6
|
+
import { createMockSigner } from "../utils";
|
|
6
7
|
|
|
7
8
|
export type TransactionFee = {
|
|
8
9
|
fees?: string;
|
|
@@ -37,6 +38,13 @@ export async function craftTransaction(
|
|
|
37
38
|
|
|
38
39
|
const tezosToolkit = getTezosToolkit();
|
|
39
40
|
|
|
41
|
+
// Configure signer for Taquito operations (same as in estimateFees)
|
|
42
|
+
if (publicKey) {
|
|
43
|
+
tezosToolkit.setProvider({
|
|
44
|
+
signer: createMockSigner(publicKey.publicKeyHash, publicKey.publicKey),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
const sourceData = await tezosToolkit.rpc.getContract(address);
|
|
41
49
|
const counter = account.counter ?? Number(sourceData.counter);
|
|
42
50
|
|
|
@@ -22,7 +22,10 @@ describe("estimateFees", () => {
|
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
-
it.each(
|
|
25
|
+
it.each([
|
|
26
|
+
[accounts[0], "with xpub"],
|
|
27
|
+
[accounts[1], "without xpub"],
|
|
28
|
+
])("returns correct value %s", async (account, _description) => {
|
|
26
29
|
// Given
|
|
27
30
|
const transaction = {
|
|
28
31
|
mode: "send",
|
|
@@ -42,7 +45,10 @@ describe("estimateFees", () => {
|
|
|
42
45
|
});
|
|
43
46
|
});
|
|
44
47
|
|
|
45
|
-
it.each(
|
|
48
|
+
it.each([
|
|
49
|
+
[accounts[0], "with xpub"],
|
|
50
|
+
[accounts[1], "without xpub"],
|
|
51
|
+
])("returns correct value when useAllAmount %s", async (account, _description) => {
|
|
46
52
|
// Given
|
|
47
53
|
const transaction = {
|
|
48
54
|
mode: "send",
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { DerivationType } from "@taquito/ledger-signer";
|
|
2
|
-
import { compressPublicKey } from "@taquito/ledger-signer/dist/lib/utils";
|
|
3
1
|
import { COST_PER_BYTE, getRevealFee, ORIGINATION_SIZE, Estimate } from "@taquito/taquito";
|
|
4
|
-
import {
|
|
2
|
+
import { validatePublicKey, ValidationResult } from "@taquito/utils";
|
|
5
3
|
import { log } from "@ledgerhq/logs";
|
|
6
4
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
7
5
|
import { TezosOperationMode } from "../types/model";
|
|
8
6
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
7
|
+
import {
|
|
8
|
+
createFallbackEstimation,
|
|
9
|
+
createMockSigner,
|
|
10
|
+
DUST_MARGIN_MUTEZ,
|
|
11
|
+
MIN_SUGGESTED_FEE_SMALL_TRANSFER,
|
|
12
|
+
OP_SIZE_XTZ_TRANSFER,
|
|
13
|
+
normalizePublicKeyForAddress,
|
|
14
|
+
} from "../utils";
|
|
9
15
|
|
|
10
16
|
export type CoreAccountInfo = {
|
|
11
17
|
address: string;
|
|
@@ -41,54 +47,43 @@ export async function estimateFees({
|
|
|
41
47
|
account: CoreAccountInfo;
|
|
42
48
|
transaction: CoreTransactionInfo;
|
|
43
49
|
}): Promise<EstimatedFees> {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else if (account.address?.startsWith("tz2")) {
|
|
50
|
-
derivationType = DerivationType.SECP256K1;
|
|
51
|
-
prefix = PrefixV2.Secp256k1PublicKey;
|
|
52
|
-
} else if (account.address?.startsWith("tz3")) {
|
|
53
|
-
derivationType = DerivationType.P256;
|
|
54
|
-
prefix = PrefixV2.P256PublicKey;
|
|
55
|
-
} else {
|
|
56
|
-
throw Error(`Failed detecting key derivation type from address ${account.address}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const encodedPubKey = b58Encode(
|
|
60
|
-
compressPublicKey(Buffer.from(account.xpub || "", "hex"), derivationType),
|
|
61
|
-
prefix,
|
|
62
|
-
);
|
|
50
|
+
// Normalize public key (hex -> base58) when provided (may be undefined for unrevealed accounts)
|
|
51
|
+
// before the device is connected
|
|
52
|
+
const encodedPubKey = account.xpub
|
|
53
|
+
? normalizePublicKeyForAddress(account.xpub, account.address)
|
|
54
|
+
: undefined;
|
|
63
55
|
|
|
64
56
|
const tezosToolkit = getTezosToolkit();
|
|
65
|
-
|
|
66
|
-
signer:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
secretKey: () => Promise.reject(new Error("unsupported")),
|
|
71
|
-
},
|
|
72
|
-
});
|
|
57
|
+
if (encodedPubKey && validatePublicKey(encodedPubKey) === ValidationResult.VALID) {
|
|
58
|
+
tezosToolkit.setProvider({ signer: createMockSigner(account.address, encodedPubKey) });
|
|
59
|
+
} else {
|
|
60
|
+
tezosToolkit.setProvider({ signer: createMockSigner(account.address, "") });
|
|
61
|
+
}
|
|
73
62
|
|
|
74
63
|
const estimation: EstimatedFees = {
|
|
75
|
-
fees:
|
|
76
|
-
gasLimit:
|
|
77
|
-
storageLimit:
|
|
78
|
-
estimatedFees:
|
|
64
|
+
fees: 0n,
|
|
65
|
+
gasLimit: 0n,
|
|
66
|
+
storageLimit: 0n,
|
|
67
|
+
estimatedFees: 0n,
|
|
79
68
|
};
|
|
80
69
|
|
|
81
70
|
// For legacy compatibility
|
|
82
|
-
if (account.balance ===
|
|
83
|
-
return transaction.useAllAmount ? { ...estimation, amount:
|
|
71
|
+
if (account.balance === 0n) {
|
|
72
|
+
return transaction.useAllAmount ? { ...estimation, amount: 0n } : estimation;
|
|
84
73
|
}
|
|
85
74
|
|
|
86
75
|
let amount = transaction.amount;
|
|
87
|
-
if (transaction.useAllAmount) {
|
|
88
|
-
amount =
|
|
76
|
+
if (transaction.useAllAmount || amount === 0n) {
|
|
77
|
+
amount = 1n; // send max do a pre-estimation with minimum amount (taquito refuses 0)
|
|
89
78
|
}
|
|
90
79
|
|
|
91
80
|
try {
|
|
81
|
+
if (transaction.mode === "send" && !transaction.recipient) {
|
|
82
|
+
return {
|
|
83
|
+
...estimation,
|
|
84
|
+
...createFallbackEstimation(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
92
87
|
let estimate: Estimate;
|
|
93
88
|
switch (transaction.mode) {
|
|
94
89
|
case "send":
|
|
@@ -96,6 +91,7 @@ export async function estimateFees({
|
|
|
96
91
|
mutez: true,
|
|
97
92
|
to: transaction.recipient,
|
|
98
93
|
amount: Number(amount),
|
|
94
|
+
source: account.address, // avoid requiring signer for estimation
|
|
99
95
|
storageLimit: ORIGINATION_SIZE, // https://github.com/TezTech/eztz/blob/master/PROTO_003_FEES.md for originating an account
|
|
100
96
|
});
|
|
101
97
|
break;
|
|
@@ -129,16 +125,14 @@ export async function estimateFees({
|
|
|
129
125
|
// NOTE: from https://github.com/ecadlabs/taquito/blob/a70c64c4b105381bb9f1d04c9c70e8ef26e9241c/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts#L33
|
|
130
126
|
// Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
|
|
131
127
|
// we need to increase the gasLimit and fee returned by the estimation
|
|
132
|
-
const gasBuffer = 500;
|
|
133
128
|
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
134
129
|
const increasedFee = (gasBuffer: number, opSize: number) => {
|
|
135
130
|
return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
|
|
136
131
|
};
|
|
137
|
-
const incr = increasedFee(
|
|
138
|
-
|
|
139
|
-
const maxMinusBuff = maxAmount - (gasBuffer - incr);
|
|
140
|
-
estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : BigInt(0);
|
|
132
|
+
const incr = increasedFee(DUST_MARGIN_MUTEZ, Number(estimate.opSize));
|
|
141
133
|
|
|
134
|
+
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
135
|
+
estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : 0n;
|
|
142
136
|
estimation.fees = BigInt(estimate.suggestedFeeMutez);
|
|
143
137
|
estimation.gasLimit = BigInt(estimate.gasLimit);
|
|
144
138
|
} else {
|
|
@@ -146,6 +140,7 @@ export async function estimateFees({
|
|
|
146
140
|
estimation.gasLimit = BigInt(estimate.gasLimit);
|
|
147
141
|
estimation.amount = transaction.amount;
|
|
148
142
|
}
|
|
143
|
+
|
|
149
144
|
estimation.storageLimit = BigInt(estimate.storageLimit);
|
|
150
145
|
estimation.estimatedFees = estimation.fees;
|
|
151
146
|
if (!account.revealed) {
|
|
@@ -157,13 +152,109 @@ export async function estimateFees({
|
|
|
157
152
|
estimation.taquitoError = (e as { id: string }).id;
|
|
158
153
|
log("taquito-error", "taquito got error " + e.id);
|
|
159
154
|
} else if ("status" in e) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
const errorMessage = String((e as unknown as { message: string }).message || "");
|
|
156
|
+
if (
|
|
157
|
+
errorMessage.includes("Public key not found") ||
|
|
158
|
+
errorMessage.includes("wallet or contract API")
|
|
159
|
+
) {
|
|
160
|
+
log(
|
|
161
|
+
"taquito-network-error",
|
|
162
|
+
"Recipient address not found (new account), using default fees",
|
|
163
|
+
{
|
|
164
|
+
transaction: transaction,
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
const fallback = createFallbackEstimation();
|
|
168
|
+
estimation.fees = fallback.fees;
|
|
169
|
+
estimation.gasLimit = fallback.gasLimit;
|
|
170
|
+
estimation.storageLimit = fallback.storageLimit;
|
|
171
|
+
estimation.estimatedFees = fallback.fees;
|
|
172
|
+
if (!account.revealed) {
|
|
173
|
+
estimation.estimatedFees =
|
|
174
|
+
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
175
|
+
}
|
|
176
|
+
// Handle useAllAmount also for send mode when estimation falls back
|
|
177
|
+
if (transaction.useAllAmount) {
|
|
178
|
+
// Approximate Taquito behavior for send-max using stable constants
|
|
179
|
+
const suggestedFee =
|
|
180
|
+
transaction.mode === "send"
|
|
181
|
+
? MIN_SUGGESTED_FEE_SMALL_TRANSFER
|
|
182
|
+
: Number(estimation.fees);
|
|
183
|
+
|
|
184
|
+
// For display consistency in tests, align fees to suggestedFee in send-max
|
|
185
|
+
if (transaction.mode === "send") {
|
|
186
|
+
estimation.fees = BigInt(suggestedFee);
|
|
187
|
+
estimation.estimatedFees = BigInt(suggestedFee);
|
|
188
|
+
if (!account.revealed) {
|
|
189
|
+
estimation.estimatedFees =
|
|
190
|
+
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
|
|
195
|
+
const totalFees =
|
|
196
|
+
suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
|
|
197
|
+
|
|
198
|
+
const revealFee = account.revealed ? 0 : getRevealFee(account.address);
|
|
199
|
+
const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
|
|
200
|
+
|
|
201
|
+
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
202
|
+
const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
|
|
203
|
+
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
204
|
+
estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
|
|
205
|
+
} else {
|
|
206
|
+
// preserve input amount in fallback for readability/tests
|
|
207
|
+
estimation.amount = transaction.amount;
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
log("taquito-network-error", errorMessage, {
|
|
211
|
+
transaction: transaction,
|
|
212
|
+
});
|
|
213
|
+
throw e;
|
|
214
|
+
}
|
|
165
215
|
} else {
|
|
166
|
-
|
|
216
|
+
const msg = String((e as any).message || "");
|
|
217
|
+
if (msg.includes("No signer has been configured")) {
|
|
218
|
+
const fallback = createFallbackEstimation();
|
|
219
|
+
estimation.fees = fallback.fees;
|
|
220
|
+
estimation.gasLimit = fallback.gasLimit;
|
|
221
|
+
estimation.storageLimit = fallback.storageLimit;
|
|
222
|
+
estimation.estimatedFees = fallback.estimatedFees;
|
|
223
|
+
if (!account.revealed) {
|
|
224
|
+
estimation.estimatedFees =
|
|
225
|
+
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
226
|
+
}
|
|
227
|
+
if (transaction.useAllAmount) {
|
|
228
|
+
const suggestedFee =
|
|
229
|
+
transaction.mode === "send"
|
|
230
|
+
? MIN_SUGGESTED_FEE_SMALL_TRANSFER
|
|
231
|
+
: Number(estimation.fees);
|
|
232
|
+
|
|
233
|
+
if (transaction.mode === "send") {
|
|
234
|
+
estimation.fees = BigInt(suggestedFee);
|
|
235
|
+
estimation.estimatedFees = BigInt(suggestedFee);
|
|
236
|
+
if (!account.revealed) {
|
|
237
|
+
estimation.estimatedFees =
|
|
238
|
+
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
|
|
243
|
+
const totalFees =
|
|
244
|
+
suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
|
|
245
|
+
const revealFee = account.revealed ? 0 : getRevealFee(account.address);
|
|
246
|
+
const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
|
|
247
|
+
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
248
|
+
const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
|
|
249
|
+
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
250
|
+
estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
|
|
251
|
+
} else {
|
|
252
|
+
// preserve input amount in fallback for readability/tests
|
|
253
|
+
estimation.amount = transaction.amount;
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
throw e;
|
|
257
|
+
}
|
|
167
258
|
}
|
|
168
259
|
}
|
|
169
260
|
return estimation;
|