@ledgerhq/coin-vechain 2.12.1 → 2.12.2-nightly.20251126023856
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +13 -5
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/synchronisation.js +2 -2
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/common-logic/calculateGasFees.d.ts +1 -1
- package/lib/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib/common-logic/calculateGasFees.js +2 -2
- package/lib/common-logic/calculateGasFees.js.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.js +8 -6
- package/lib/common-logic/calculateTransactionInfo.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +13 -5
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/synchronisation.js +2 -2
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/common-logic/calculateGasFees.d.ts +1 -1
- package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib-es/common-logic/calculateGasFees.js +2 -2
- package/lib-es/common-logic/calculateGasFees.js.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.js +8 -6
- package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -1
- package/package.json +6 -6
- package/src/bridge/estimateMaxSpendable.test.ts +18 -3
- package/src/bridge/estimateMaxSpendable.ts +23 -3
- package/src/bridge/synchronisation.test.ts +13 -44
- package/src/bridge/synchronisation.ts +2 -2
- package/src/common-logic/calculateGasFees.test.ts +21 -19
- package/src/common-logic/calculateGasFees.ts +4 -1
- package/src/common-logic/calculateTransactionInfo.test.ts +2 -0
- package/src/common-logic/calculateTransactionInfo.ts +13 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ledgerhq/coin-evm
|
|
2
2
|
|
|
3
|
+
## 2.12.2-nightly.20251126023856
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#12840](https://github.com/LedgerHQ/ledger-live/pull/12840) [`ed580b3`](https://github.com/LedgerHQ/ledger-live/commit/ed580b3b8bee2ad492e40788adb29f90f175bce5) Thanks [@alevito](https://github.com/alevito)! - improve accuracy of gas estimation by setting the transaction caller to origin's address, rather than the recipient's address
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`50aeea1`](https://github.com/LedgerHQ/ledger-live/commit/50aeea1233056e9abff9568eb928927f39e76cff), [`fe81926`](https://github.com/LedgerHQ/ledger-live/commit/fe81926afeb2df8e917e6bd1e4cbab13f09647fd), [`67137eb`](https://github.com/LedgerHQ/ledger-live/commit/67137eb5d7f04dd5f3610fdaa4e463d292654105), [`49ef24c`](https://github.com/LedgerHQ/ledger-live/commit/49ef24cbd1948bfd146af0b20f2128951b2dc170), [`b4a4e16`](https://github.com/LedgerHQ/ledger-live/commit/b4a4e160aae6fd64f944ab25633f6931dc4358d3), [`903ea9c`](https://github.com/LedgerHQ/ledger-live/commit/903ea9cdacf704a0119de2803a4f409b775391a5), [`9251b77`](https://github.com/LedgerHQ/ledger-live/commit/9251b77fcb01709723842f19220a2a41a6fc8f3b), [`02ef98f`](https://github.com/LedgerHQ/ledger-live/commit/02ef98faeb13c182ef255e06a43c39abeb55ecc7), [`6d0c6b2`](https://github.com/LedgerHQ/ledger-live/commit/6d0c6b2eda60049d8eebda5de2c54e8f0be7d009), [`b113920`](https://github.com/LedgerHQ/ledger-live/commit/b11392056bc334fc1813c473569ad3ae7be08045), [`9659a34`](https://github.com/LedgerHQ/ledger-live/commit/9659a34d9998d5c4dff8618bf6cef7d16403680d)]:
|
|
10
|
+
- @ledgerhq/cryptoassets@13.34.0-nightly.20251126023856
|
|
11
|
+
- @ledgerhq/coin-framework@6.10.0-nightly.20251126023856
|
|
12
|
+
- @ledgerhq/live-env@2.21.1-nightly.20251126023856
|
|
13
|
+
- @ledgerhq/live-network@2.1.2-nightly.20251126023856
|
|
14
|
+
|
|
3
15
|
## 2.12.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAO5C,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CA2BnF,CAAC"}
|
|
@@ -6,14 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.estimateMaxSpendable = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
const common_logic_1 = require("../common-logic");
|
|
9
|
-
const
|
|
9
|
+
const PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID = /:(0x\w+):/;
|
|
10
|
+
const getAddressFromTokenAccountId = (tokenAccountId) => PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID.exec(tokenAccountId)?.[1];
|
|
11
|
+
const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
|
|
10
12
|
if (account.type === "Account" || !transaction) {
|
|
11
13
|
return account.balance;
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (account.type === "TokenAccount") {
|
|
16
|
+
const originAddress = parentAccount?.freshAddress || getAddressFromTokenAccountId(account.id);
|
|
17
|
+
if (originAddress) {
|
|
18
|
+
const { estimatedGasFees: maxTokenFees } = await (0, common_logic_1.calculateGasFees)(transaction, true, originAddress);
|
|
19
|
+
const spendable = account.balance.minus(maxTokenFees);
|
|
20
|
+
if (spendable.gt(0)) {
|
|
21
|
+
return spendable;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
17
25
|
return new bignumber_js_1.default(0);
|
|
18
26
|
};
|
|
19
27
|
exports.estimateMaxSpendable = estimateMaxSpendable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAErC,kDAAmD;
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAErC,kDAAmD;AAGnD,MAAM,mCAAmC,GAAG,WAAW,CAAC;AAExD,MAAM,4BAA4B,GAAG,CAAC,cAAsB,EAAsB,EAAE,CAClF,mCAAmC,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEzD,MAAM,oBAAoB,GAAuD,KAAK,EAAE,EAC7F,OAAO,EACP,aAAa,EACb,WAAW,GACZ,EAAsB,EAAE;IACvB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/C,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACpC,MAAM,aAAa,GAAG,aAAa,EAAE,YAAY,IAAI,4BAA4B,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAE9F,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,+BAAgB,EAC/D,WAAW,EACX,IAAI,EACJ,aAAa,CACd,CAAC;YACF,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAEtD,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,sBAAS,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC,CAAC;AA3BW,QAAA,oBAAoB,wBA2B/B"}
|
|
@@ -11,7 +11,7 @@ const network_1 = require("../network");
|
|
|
11
11
|
const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
12
12
|
const helpers_1 = require("./helpers");
|
|
13
13
|
const sdk_core_1 = require("@vechain/sdk-core");
|
|
14
|
-
const
|
|
14
|
+
const state_1 = require("@ledgerhq/cryptoassets/state");
|
|
15
15
|
const getAccountShape = async (info) => {
|
|
16
16
|
const { initialAccount, currency, derivationMode } = info;
|
|
17
17
|
const address = eip55_1.default.encode(info.address);
|
|
@@ -31,7 +31,7 @@ const getAccountShape = async (info) => {
|
|
|
31
31
|
// Merge new operations with the previously synced ones
|
|
32
32
|
const newOperations = await (0, network_1.getOperations)(accountId, address, startAt);
|
|
33
33
|
//Get last token operations
|
|
34
|
-
const vthoToken =
|
|
34
|
+
const vthoToken = await (0, state_1.getCryptoAssetsStore)().findTokenById("vechain/vip180/vtho");
|
|
35
35
|
if (!vthoToken)
|
|
36
36
|
throw new Error("VTHO token not found");
|
|
37
37
|
const vthoAccountId = (0, index_1.encodeTokenAccountId)(accountId, vthoToken);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyC;AAEzC,kDAA0B;AAC1B,kEAIgD;AAEhD,wCAA+F;AAC/F,yEAAsF;AAEtF,uCAA2C;AAC3C,gDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyC;AAEzC,kDAA0B;AAC1B,kEAIgD;AAEhD,wCAA+F;AAC/F,yEAAsF;AAEtF,uCAA2C;AAC3C,gDAAiD;AACjD,wDAAoE;AAE7D,MAAM,eAAe,GAA6B,KAAK,EAAC,IAAI,EAAC,EAAE;IACpE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAC1D,MAAM,OAAO,GAAG,eAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE3C,MAAM,aAAa,GAAG,cAAc,EAAE,UAAU,IAAI,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnF,MAAM,SAAS,GAAG,IAAA,uBAAe,EAAC;QAChC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,GAAG;QACZ,UAAU,EAAE,QAAQ,CAAC,EAAE;QACvB,aAAa,EAAE,OAAO;QACtB,cAAc;KACf,CAAC,CAAC;IAEH,0EAA0E;IAC1E,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,oBAAU,EAAC,OAAO,CAAC,CAAC;IAEtD,+BAA+B;IAC/B,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAkB,GAAE,CAAC;IAE/C,uDAAuD;IACvD,MAAM,aAAa,GA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CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;QAC7D,gBAAgB,EAAE,IAAI,wBAAS,CAAC,OAAO,CAAC;QACxC,eAAe,EAAE,UAAU,CAAC,MAAM;QAClC,UAAU;QACV,WAAW;QACX,YAAY,EAAE,SAAS;QACvB,WAAW,EAAE;YACX;gBACE,IAAI,EAAE,cAAuB;gBAC7B,EAAE,EAAE,aAAa;gBACjB,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,IAAI,wBAAS,CAAC,MAAM,CAAC;gBAC9B,gBAAgB,EAAE,IAAI,wBAAS,CAAC,MAAM,CAAC;gBACvC,YAAY,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;gBAC7D,eAAe,EAAE,cAAc,CAAC,MAAM;gBACtC,UAAU,EAAE,cAAc;gBAC1B,WAAW;gBACX,iBAAiB,EACf,CAAC,cAAc,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,IAAI,EAAE;gBACzF,mBAAmB,EACjB,CAAC,cAAc,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC;oBACnF,yBAAiB;gBACnB,WAAW,EAAE,EAAE;aAChB;SACF;KACF,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,IAAI,EAAE,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC;AA/EW,QAAA,eAAe,mBA+E1B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Transaction } from "../types";
|
|
3
|
-
export declare const calculateGasFees: (transaction: Transaction, isTokenAccount: boolean) => Promise<{
|
|
3
|
+
export declare const calculateGasFees: (transaction: Transaction, isTokenAccount: boolean, originAddress: string) => Promise<{
|
|
4
4
|
estimatedGas: number;
|
|
5
5
|
estimatedGasFees: BigNumber;
|
|
6
6
|
maxFeePerGas: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateGasFees.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,eAAO,MAAM,gBAAgB,gBACd,WAAW,kBACR,OAAO,
|
|
1
|
+
{"version":3,"file":"calculateGasFees.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,eAAO,MAAM,gBAAgB,gBACd,WAAW,kBACR,OAAO,iBACR,MAAM,KACpB,QAAQ;IACT,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CA+BA,CAAC"}
|
|
@@ -9,7 +9,7 @@ const parseAddress_1 = require("./parseAddress");
|
|
|
9
9
|
const calculateClauses_1 = require("./calculateClauses");
|
|
10
10
|
const estimateGas_1 = require("./estimateGas");
|
|
11
11
|
const getThorClient_1 = require("./getThorClient");
|
|
12
|
-
const calculateGasFees = async (transaction, isTokenAccount) => {
|
|
12
|
+
const calculateGasFees = async (transaction, isTokenAccount, originAddress) => {
|
|
13
13
|
if (transaction.recipient && (0, parseAddress_1.parseAddress)(transaction.recipient)) {
|
|
14
14
|
let clauses;
|
|
15
15
|
if (isTokenAccount) {
|
|
@@ -18,7 +18,7 @@ const calculateGasFees = async (transaction, isTokenAccount) => {
|
|
|
18
18
|
else {
|
|
19
19
|
clauses = await (0, calculateClauses_1.calculateClausesVet)(transaction.recipient, transaction.amount);
|
|
20
20
|
}
|
|
21
|
-
const gasEstimation = await (0, estimateGas_1.estimateGas)(clauses,
|
|
21
|
+
const gasEstimation = await (0, estimateGas_1.estimateGas)(clauses, originAddress);
|
|
22
22
|
const thorClient = (0, getThorClient_1.getThorClient)();
|
|
23
23
|
const body = await thorClient.transactions.buildTransactionBody(clauses, gasEstimation.totalGas, {});
|
|
24
24
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateGasFees.js","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAErC,iDAA8C;AAC9C,yDAA+E;AAC/E,+CAA4C;AAC5C,mDAAgD;AAEzC,MAAM,gBAAgB,GAAG,KAAK,EACnC,WAAwB,EACxB,cAAuB,
|
|
1
|
+
{"version":3,"file":"calculateGasFees.js","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAErC,iDAA8C;AAC9C,yDAA+E;AAC/E,+CAA4C;AAC5C,mDAAgD;AAEzC,MAAM,gBAAgB,GAAG,KAAK,EACnC,WAAwB,EACxB,cAAuB,EACvB,aAAqB,EAMpB,EAAE;IACH,IAAI,WAAW,CAAC,SAAS,IAAI,IAAA,2BAAY,EAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACjE,IAAI,OAAO,CAAC;QAEZ,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,GAAG,MAAM,IAAA,uCAAoB,EAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAClF,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,MAAM,IAAA,sCAAmB,EAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACjF,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,IAAA,yBAAW,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAChE,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAE,CAAC;QACnC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,oBAAoB,CAC7D,OAAO,EACP,aAAa,CAAC,QAAQ,EACtB,EAAE,CACH,CAAC;QAEF,OAAO;YACL,YAAY,EAAE,aAAa,CAAC,QAAQ;YACpC,gBAAgB,EAAE,IAAI,sBAAS,CAAC,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;YACvF,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC;YAC9C,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,GAAG,CAAC;SAC/D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,YAAY,EAAE,CAAC;QACf,gBAAgB,EAAE,IAAI,sBAAS,CAAC,CAAC,CAAC;QAClC,YAAY,EAAE,CAAC;QACf,oBAAoB,EAAE,CAAC;KACxB,CAAC;AACJ,CAAC,CAAC;AAxCW,QAAA,gBAAgB,oBAwC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateTransactionInfo.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"calculateTransactionInfo.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAwBxD,eAAO,MAAM,wBAAwB,YAC1B,OAAO,eACH,WAAW,sBACJ;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,KACA,QAAQ,eAAe,CAkEzB,CAAC"}
|
|
@@ -7,6 +7,11 @@ exports.calculateTransactionInfo = void 0;
|
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
const errors_1 = require("../errors");
|
|
9
9
|
const calculateGasFees_1 = require("./calculateGasFees");
|
|
10
|
+
const getTokenAccount = (subAccountId, subAccounts) => subAccountId && subAccounts
|
|
11
|
+
? subAccounts.find(subAccount => {
|
|
12
|
+
return subAccount.id === subAccountId;
|
|
13
|
+
})
|
|
14
|
+
: undefined;
|
|
10
15
|
// Here there is a circular dependency between values, that is why we need the do-while loop
|
|
11
16
|
// dependencies are:
|
|
12
17
|
// useAllAmount: USER
|
|
@@ -19,11 +24,7 @@ const calculateGasFees_1 = require("./calculateGasFees");
|
|
|
19
24
|
const calculateTransactionInfo = async (account, transaction, fixedMaxTokenFees) => {
|
|
20
25
|
const { subAccounts } = account;
|
|
21
26
|
const { amount: oldAmount, subAccountId, useAllAmount } = transaction;
|
|
22
|
-
const tokenAccount = subAccountId
|
|
23
|
-
? subAccounts.find(subAccount => {
|
|
24
|
-
return subAccount.id === subAccountId;
|
|
25
|
-
})
|
|
26
|
-
: undefined;
|
|
27
|
+
const tokenAccount = getTokenAccount(subAccountId, subAccounts);
|
|
27
28
|
const isTokenAccount = !!tokenAccount;
|
|
28
29
|
let amount = oldAmount;
|
|
29
30
|
let amountBackup;
|
|
@@ -39,7 +40,8 @@ const calculateTransactionInfo = async (account, transaction, fixedMaxTokenFees)
|
|
|
39
40
|
let iterations = 0;
|
|
40
41
|
do {
|
|
41
42
|
amountBackup = amount;
|
|
42
|
-
const estimatedGasAndFees = fixedMaxTokenFees ||
|
|
43
|
+
const estimatedGasAndFees = fixedMaxTokenFees ||
|
|
44
|
+
(await (0, calculateGasFees_1.calculateGasFees)(tempTransaction, isTokenAccount, account.freshAddress));
|
|
43
45
|
maxEstimatedGasFees = estimatedGasAndFees.estimatedGasFees;
|
|
44
46
|
maxEstimatedGas = estimatedGasAndFees.estimatedGas;
|
|
45
47
|
maxFeePerGas = estimatedGasAndFees.maxFeePerGas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateTransactionInfo.js","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAGrC,sCAA+D;AAC/D,yDAAsD;AAEtD,4FAA4F;AAC5F,oBAAoB;AACpB,qBAAqB;AACrB,0CAA0C;AAC1C,eAAe;AACf,mCAAmC;AACnC,gBAAgB;AAChB,0BAA0B;AAC1B,+CAA+C;AAExC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAAgB,EAChB,WAAwB,EACxB,iBAKC,EACyB,EAAE;IAC5B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IAEtE,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"calculateTransactionInfo.js","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAGrC,sCAA+D;AAC/D,yDAAsD;AAEtD,MAAM,eAAe,GAAG,CACtB,YAAuC,EACvC,WAAuC,EACvC,EAAE,CACF,YAAY,IAAI,WAAW;IACzB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QAC5B,OAAO,UAAU,CAAC,EAAE,KAAK,YAAY,CAAC;IACxC,CAAC,CAAC;IACJ,CAAC,CAAC,SAAS,CAAC;AAEhB,4FAA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
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAO5C,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CA2BnF,CAAC"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { calculateGasFees } from "../common-logic";
|
|
3
|
-
|
|
3
|
+
const PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID = /:(0x\w+):/;
|
|
4
|
+
const getAddressFromTokenAccountId = (tokenAccountId) => PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID.exec(tokenAccountId)?.[1];
|
|
5
|
+
export const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
|
|
4
6
|
if (account.type === "Account" || !transaction) {
|
|
5
7
|
return account.balance;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
if (account.type === "TokenAccount") {
|
|
10
|
+
const originAddress = parentAccount?.freshAddress || getAddressFromTokenAccountId(account.id);
|
|
11
|
+
if (originAddress) {
|
|
12
|
+
const { estimatedGasFees: maxTokenFees } = await calculateGasFees(transaction, true, originAddress);
|
|
13
|
+
const spendable = account.balance.minus(maxTokenFees);
|
|
14
|
+
if (spendable.gt(0)) {
|
|
15
|
+
return spendable;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
11
19
|
return new BigNumber(0);
|
|
12
20
|
};
|
|
13
21
|
//# sourceMappingURL=estimateMaxSpendable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,MAAM,CAAC,MAAM,oBAAoB,GAAuD,KAAK,EAAE,EAC7F,OAAO,EACP,WAAW,GACZ,EAAsB,EAAE;IACvB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/C,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../../src/bridge/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,MAAM,mCAAmC,GAAG,WAAW,CAAC;AAExD,MAAM,4BAA4B,GAAG,CAAC,cAAsB,EAAsB,EAAE,CAClF,mCAAmC,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,oBAAoB,GAAuD,KAAK,EAAE,EAC7F,OAAO,EACP,aAAa,EACb,WAAW,GACZ,EAAsB,EAAE;IACvB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/C,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACpC,MAAM,aAAa,GAAG,aAAa,EAAE,YAAY,IAAI,4BAA4B,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAE9F,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,gBAAgB,CAC/D,WAAW,EACX,IAAI,EACJ,aAAa,CACd,CAAC;YACF,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAEtD,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { getAccount, getLastBlockHeight, getOperations, getTokenOperations } fro
|
|
|
5
5
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
6
6
|
import { isAccountEmpty } from "./helpers";
|
|
7
7
|
import { VTHO_ADDRESS } from "@vechain/sdk-core";
|
|
8
|
-
import {
|
|
8
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
9
9
|
export const getAccountShape = async (info) => {
|
|
10
10
|
const { initialAccount, currency, derivationMode } = info;
|
|
11
11
|
const address = eip55.encode(info.address);
|
|
@@ -25,7 +25,7 @@ export const getAccountShape = async (info) => {
|
|
|
25
25
|
// Merge new operations with the previously synced ones
|
|
26
26
|
const newOperations = await getOperations(accountId, address, startAt);
|
|
27
27
|
//Get last token operations
|
|
28
|
-
const vthoToken =
|
|
28
|
+
const vthoToken = await getCryptoAssetsStore().findTokenById("vechain/vip180/vtho");
|
|
29
29
|
if (!vthoToken)
|
|
30
30
|
throw new Error("VTHO token not found");
|
|
31
31
|
const vthoAccountId = encodeTokenAccountId(accountId, vthoToken);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAmB,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"synchronisation.js","sourceRoot":"","sources":["../../src/bridge/synchronisation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,EAAmB,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,CAAC,MAAM,eAAe,GAA6B,KAAK,EAAC,IAAI,EAAC,EAAE;IACpE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC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,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,IAAI,EAAE;gBACzF,mBAAmB,EACjB,CAAC,cAAc,EAAE,WAAW,IAAI,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC;oBACnF,iBAAiB;gBACnB,WAAW,EAAE,EAAE;aAChB;SACF;KACF,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,IAAI,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Transaction } from "../types";
|
|
3
|
-
export declare const calculateGasFees: (transaction: Transaction, isTokenAccount: boolean) => Promise<{
|
|
3
|
+
export declare const calculateGasFees: (transaction: Transaction, isTokenAccount: boolean, originAddress: string) => Promise<{
|
|
4
4
|
estimatedGas: number;
|
|
5
5
|
estimatedGasFees: BigNumber;
|
|
6
6
|
maxFeePerGas: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateGasFees.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,eAAO,MAAM,gBAAgB,gBACd,WAAW,kBACR,OAAO,
|
|
1
|
+
{"version":3,"file":"calculateGasFees.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,eAAO,MAAM,gBAAgB,gBACd,WAAW,kBACR,OAAO,iBACR,MAAM,KACpB,QAAQ;IACT,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CA+BA,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { parseAddress } from "./parseAddress";
|
|
|
3
3
|
import { calculateClausesVet, calculateClausesVtho } from "./calculateClauses";
|
|
4
4
|
import { estimateGas } from "./estimateGas";
|
|
5
5
|
import { getThorClient } from "./getThorClient";
|
|
6
|
-
export const calculateGasFees = async (transaction, isTokenAccount) => {
|
|
6
|
+
export const calculateGasFees = async (transaction, isTokenAccount, originAddress) => {
|
|
7
7
|
if (transaction.recipient && parseAddress(transaction.recipient)) {
|
|
8
8
|
let clauses;
|
|
9
9
|
if (isTokenAccount) {
|
|
@@ -12,7 +12,7 @@ export const calculateGasFees = async (transaction, isTokenAccount) => {
|
|
|
12
12
|
else {
|
|
13
13
|
clauses = await calculateClausesVet(transaction.recipient, transaction.amount);
|
|
14
14
|
}
|
|
15
|
-
const gasEstimation = await estimateGas(clauses,
|
|
15
|
+
const gasEstimation = await estimateGas(clauses, originAddress);
|
|
16
16
|
const thorClient = getThorClient();
|
|
17
17
|
const body = await thorClient.transactions.buildTransactionBody(clauses, gasEstimation.totalGas, {});
|
|
18
18
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateGasFees.js","sourceRoot":"","sources":["../../src/common-logic/calculateGasFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,WAAwB,EACxB,cAAuB,
|
|
1
|
+
{"version":3,"file":"calculateGasFees.js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AAC;YAC9C,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,GAAG,CAAC;SAC/D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,YAAY,EAAE,CAAC;QACf,gBAAgB,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC;QAClC,YAAY,EAAE,CAAC;QACf,oBAAoB,EAAE,CAAC;KACxB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateTransactionInfo.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"calculateTransactionInfo.d.ts","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAgB,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAwBxD,eAAO,MAAM,wBAAwB,YAC1B,OAAO,eACH,WAAW,sBACJ;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,KACA,QAAQ,eAAe,CAkEzB,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
3
3
|
import { calculateGasFees } from "./calculateGasFees";
|
|
4
|
+
const getTokenAccount = (subAccountId, subAccounts) => subAccountId && subAccounts
|
|
5
|
+
? subAccounts.find(subAccount => {
|
|
6
|
+
return subAccount.id === subAccountId;
|
|
7
|
+
})
|
|
8
|
+
: undefined;
|
|
4
9
|
// Here there is a circular dependency between values, that is why we need the do-while loop
|
|
5
10
|
// dependencies are:
|
|
6
11
|
// useAllAmount: USER
|
|
@@ -13,11 +18,7 @@ import { calculateGasFees } from "./calculateGasFees";
|
|
|
13
18
|
export const calculateTransactionInfo = async (account, transaction, fixedMaxTokenFees) => {
|
|
14
19
|
const { subAccounts } = account;
|
|
15
20
|
const { amount: oldAmount, subAccountId, useAllAmount } = transaction;
|
|
16
|
-
const tokenAccount = subAccountId
|
|
17
|
-
? subAccounts.find(subAccount => {
|
|
18
|
-
return subAccount.id === subAccountId;
|
|
19
|
-
})
|
|
20
|
-
: undefined;
|
|
21
|
+
const tokenAccount = getTokenAccount(subAccountId, subAccounts);
|
|
21
22
|
const isTokenAccount = !!tokenAccount;
|
|
22
23
|
let amount = oldAmount;
|
|
23
24
|
let amountBackup;
|
|
@@ -33,7 +34,8 @@ export const calculateTransactionInfo = async (account, transaction, fixedMaxTok
|
|
|
33
34
|
let iterations = 0;
|
|
34
35
|
do {
|
|
35
36
|
amountBackup = amount;
|
|
36
|
-
const estimatedGasAndFees = fixedMaxTokenFees ||
|
|
37
|
+
const estimatedGasAndFees = fixedMaxTokenFees ||
|
|
38
|
+
(await calculateGasFees(tempTransaction, isTokenAccount, account.freshAddress));
|
|
37
39
|
maxEstimatedGasFees = estimatedGasAndFees.estimatedGasFees;
|
|
38
40
|
maxEstimatedGas = estimatedGasAndFees.estimatedGas;
|
|
39
41
|
maxFeePerGas = estimatedGasAndFees.maxFeePerGas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateTransactionInfo.js","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,OAAO,EAAE,kCAAkC,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,4FAA4F;AAC5F,oBAAoB;AACpB,qBAAqB;AACrB,0CAA0C;AAC1C,eAAe;AACf,mCAAmC;AACnC,gBAAgB;AAChB,0BAA0B;AAC1B,+CAA+C;AAE/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAAgB,EAChB,WAAwB,EACxB,iBAKC,EACyB,EAAE;IAC5B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IAEtE,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"calculateTransactionInfo.js","sourceRoot":"","sources":["../../src/common-logic/calculateTransactionInfo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,OAAO,EAAE,kCAAkC,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,eAAe,GAAG,CACtB,YAAuC,EACvC,WAAuC,EACvC,EAAE,CACF,YAAY,IAAI,WAAW;IACzB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QAC5B,OAAO,UAAU,CAAC,EAAE,KAAK,YAAY,CAAC;IACxC,CAAC,CAAC;IACJ,CAAC,CAAC,SAAS,CAAC;AAEhB,4FAA4F;AAC5F,oBAAoB;AACpB,qBAAqB;AACrB,0CAA0C;AAC1C,eAAe;AACf,mCAAmC;AACnC,gBAAgB;AAChB,0BAA0B;AAC1B,+CAA+C;AAE/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAAgB,EAChB,WAAwB,EACxB,iBAKC,EACyB,EAAE;IAC5B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE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AC,EAAE,CAAC,CAAC,CAAC;oBACtE,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC;oBACjD,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;gBAC1B,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;YACrC,CAAC;YAED,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;YAErD,eAAe,GAAG;gBAChB,GAAG,eAAe;gBAClB,MAAM;aACP,CAAC;YACF,UAAU,EAAE,CAAC;QACf,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,UAAU,GAAG,cAAc,EAAE;QACzE,IAAI,UAAU,KAAK,cAAc,EAAE,CAAC;YAClC,MAAM,IAAI,kCAAkC,EAAE,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO;QACL,cAAc;QACd,MAAM;QACN,gBAAgB;QAChB,OAAO;QACP,YAAY;QACZ,aAAa,EAAE,mBAAmB,CAAC,QAAQ,EAAE;QAC7C,YAAY,EAAE,eAAe;QAC7B,YAAY,EAAE,YAAY;QAC1B,oBAAoB,EAAE,oBAAoB;KAC3C,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-vechain",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.2-nightly.20251126023856",
|
|
4
4
|
"description": "Ledger VeChain Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -86,12 +86,12 @@
|
|
|
86
86
|
"rxjs": "^7.8.1",
|
|
87
87
|
"@vechain/sdk-core": "2.0.0",
|
|
88
88
|
"@vechain/sdk-network": "2.0.0",
|
|
89
|
-
"@ledgerhq/coin-framework": "^6.
|
|
90
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
89
|
+
"@ledgerhq/coin-framework": "^6.10.0-nightly.20251126023856",
|
|
90
|
+
"@ledgerhq/cryptoassets": "^13.34.0-nightly.20251126023856",
|
|
91
91
|
"@ledgerhq/devices": "8.7.0",
|
|
92
92
|
"@ledgerhq/errors": "^6.27.0",
|
|
93
|
-
"@ledgerhq/live-env": "^2.21.
|
|
94
|
-
"@ledgerhq/live-network": "^2.1.
|
|
93
|
+
"@ledgerhq/live-env": "^2.21.1-nightly.20251126023856",
|
|
94
|
+
"@ledgerhq/live-network": "^2.1.2-nightly.20251126023856"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@faker-js/faker": "^9.6.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"msw": "^2.2.13",
|
|
104
104
|
"ts-jest": "^29.1.1",
|
|
105
105
|
"@ledgerhq/types-cryptoassets": "^7.30.0",
|
|
106
|
-
"@ledgerhq/types-live": "^6.
|
|
106
|
+
"@ledgerhq/types-live": "^6.90.0-nightly.20251126023856",
|
|
107
107
|
"@ledgerhq/disable-network-setup": "^0.1.0"
|
|
108
108
|
},
|
|
109
109
|
"scripts": {
|
|
@@ -116,7 +116,22 @@ describe("estimateMaxSpendable", () => {
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
expect(result).toEqual(new BigNumber("999790000000000000000")); // 1000 - 0.21 VTHO
|
|
119
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true);
|
|
119
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true, "0x123");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should calculate max spendable for token account with sufficient balance, when parentAccount provided", async () => {
|
|
123
|
+
const result = await estimateMaxSpendable({
|
|
124
|
+
account: mockTokenAccount,
|
|
125
|
+
parentAccount: mockAccount,
|
|
126
|
+
transaction: mockTransaction,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(result).toEqual(new BigNumber("999790000000000000000")); // 1000 - 0.21 VTHO
|
|
130
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(
|
|
131
|
+
mockTransaction,
|
|
132
|
+
true,
|
|
133
|
+
mockAccount.freshAddress,
|
|
134
|
+
);
|
|
120
135
|
});
|
|
121
136
|
|
|
122
137
|
it("should return zero when gas fees exceed token balance", async () => {
|
|
@@ -175,7 +190,7 @@ describe("estimateMaxSpendable", () => {
|
|
|
175
190
|
transaction: mockTransaction,
|
|
176
191
|
});
|
|
177
192
|
|
|
178
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true);
|
|
193
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true, "0x123");
|
|
179
194
|
expect(mockedCalculateGasFees).toHaveBeenCalledTimes(1);
|
|
180
195
|
});
|
|
181
196
|
|
|
@@ -248,7 +263,7 @@ describe("estimateMaxSpendable", () => {
|
|
|
248
263
|
transaction: tokenTransaction,
|
|
249
264
|
});
|
|
250
265
|
|
|
251
|
-
expect(mockedCalculateGasFees).toHaveBeenCalledWith(tokenTransaction, true);
|
|
266
|
+
expect(mockedCalculateGasFees).toHaveBeenCalledWith(tokenTransaction, true, "0x123");
|
|
252
267
|
});
|
|
253
268
|
});
|
|
254
269
|
|
|
@@ -3,16 +3,36 @@ import { AccountBridge } from "@ledgerhq/types-live";
|
|
|
3
3
|
import { calculateGasFees } from "../common-logic";
|
|
4
4
|
import type { Transaction } from "../types";
|
|
5
5
|
|
|
6
|
+
const PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID = /:(0x\w+):/;
|
|
7
|
+
|
|
8
|
+
const getAddressFromTokenAccountId = (tokenAccountId: string): string | undefined =>
|
|
9
|
+
PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID.exec(tokenAccountId)?.[1];
|
|
10
|
+
|
|
6
11
|
export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
|
|
7
12
|
account,
|
|
13
|
+
parentAccount,
|
|
8
14
|
transaction,
|
|
9
15
|
}): Promise<BigNumber> => {
|
|
10
16
|
if (account.type === "Account" || !transaction) {
|
|
11
17
|
return account.balance;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
if (account.type === "TokenAccount") {
|
|
21
|
+
const originAddress = parentAccount?.freshAddress || getAddressFromTokenAccountId(account.id);
|
|
22
|
+
|
|
23
|
+
if (originAddress) {
|
|
24
|
+
const { estimatedGasFees: maxTokenFees } = await calculateGasFees(
|
|
25
|
+
transaction,
|
|
26
|
+
true,
|
|
27
|
+
originAddress,
|
|
28
|
+
);
|
|
29
|
+
const spendable = account.balance.minus(maxTokenFees);
|
|
30
|
+
|
|
31
|
+
if (spendable.gt(0)) {
|
|
32
|
+
return spendable;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
17
37
|
return new BigNumber(0);
|
|
18
38
|
};
|
|
@@ -2,17 +2,15 @@ import { faker } from "@faker-js/faker";
|
|
|
2
2
|
import { createEmptyHistoryCache } from "@ledgerhq/coin-framework/account";
|
|
3
3
|
import { makeScanAccounts } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
4
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
5
|
-
import { getCryptoAssetsStore } from "@ledgerhq/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
6
|
+
import { setupMockCryptoAssetsStore } from "@ledgerhq/cryptoassets/cal-client/test-helpers";
|
|
7
|
+
import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
8
8
|
import BigNumber from "bignumber.js";
|
|
9
9
|
import { setupServer } from "msw/node";
|
|
10
10
|
import { firstValueFrom } from "rxjs";
|
|
11
11
|
import { getAccountShape } from "./synchronisation";
|
|
12
12
|
import { Operation } from "@ledgerhq/types-live";
|
|
13
13
|
|
|
14
|
-
jest.mock("@ledgerhq/coin-framework/crypto-assets/index");
|
|
15
|
-
|
|
16
14
|
const mockGetAccount = jest.fn();
|
|
17
15
|
const mockGetOperations = jest.fn();
|
|
18
16
|
const mockGetTokenOperations = jest.fn();
|
|
@@ -35,55 +33,26 @@ describe("scanAccounts", () => {
|
|
|
35
33
|
const currency = getCryptoCurrencyById("vechain");
|
|
36
34
|
|
|
37
35
|
beforeAll(() => {
|
|
38
|
-
|
|
39
|
-
initializeLegacyTokens(addTokens);
|
|
40
|
-
|
|
41
|
-
// Mock the crypto assets store
|
|
42
|
-
const vthoToken = {
|
|
36
|
+
const vthoToken: TokenCurrency = {
|
|
43
37
|
type: "TokenCurrency",
|
|
44
38
|
id: "vechain/vip180/vtho",
|
|
45
39
|
contractAddress: "0x0000000000000000000000000000456E65726779",
|
|
46
|
-
parentCurrency:
|
|
47
|
-
type: "CryptoCurrency",
|
|
48
|
-
id: "vechain",
|
|
49
|
-
coinType: 818,
|
|
50
|
-
name: "Vechain",
|
|
51
|
-
managerAppName: "VeChain",
|
|
52
|
-
ticker: "VET",
|
|
53
|
-
scheme: "vechain",
|
|
54
|
-
color: "#82BE00",
|
|
55
|
-
family: "vechain",
|
|
56
|
-
blockAvgTime: 10,
|
|
57
|
-
tokenTypes: ["vip180"],
|
|
58
|
-
units: [
|
|
59
|
-
{ name: "VET", code: "VET", magnitude: 18 },
|
|
60
|
-
{ name: "Gwei", code: "Gwei", magnitude: 9 },
|
|
61
|
-
{ name: "Mwei", code: "Mwei", magnitude: 6 },
|
|
62
|
-
{ name: "Kwei", code: "Kwei", magnitude: 3 },
|
|
63
|
-
{ name: "wei", code: "wei", magnitude: 0 },
|
|
64
|
-
],
|
|
65
|
-
explorerViews: [
|
|
66
|
-
{
|
|
67
|
-
tx: "https://explore.vechain.org/transactions/$hash",
|
|
68
|
-
address: "https://explore.vechain.org/accounts/$address",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
40
|
+
parentCurrency: currency,
|
|
72
41
|
tokenType: "vip180",
|
|
73
|
-
name: "
|
|
42
|
+
name: "VeThor",
|
|
74
43
|
ticker: "VTHO",
|
|
44
|
+
delisted: false,
|
|
75
45
|
disableCountervalue: false,
|
|
76
|
-
units: [{ name: "
|
|
46
|
+
units: [{ name: "VeThor", code: "VTHO", magnitude: 18 }],
|
|
77
47
|
};
|
|
78
48
|
|
|
79
|
-
(
|
|
80
|
-
findTokenById:
|
|
49
|
+
setupMockCryptoAssetsStore({
|
|
50
|
+
findTokenById: async (id: string) => {
|
|
81
51
|
if (id === "vechain/vip180/vtho") {
|
|
82
|
-
return
|
|
52
|
+
return vthoToken;
|
|
83
53
|
}
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
findTokenByAddressInCurrency: jest.fn().mockResolvedValue(null),
|
|
54
|
+
return undefined;
|
|
55
|
+
},
|
|
87
56
|
});
|
|
88
57
|
|
|
89
58
|
setupServer().listen({ onUnhandledRequest: "error" });
|
|
@@ -12,7 +12,7 @@ import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHel
|
|
|
12
12
|
import { Account } from "@ledgerhq/types-live";
|
|
13
13
|
import { isAccountEmpty } from "./helpers";
|
|
14
14
|
import { VTHO_ADDRESS } from "@vechain/sdk-core";
|
|
15
|
-
import {
|
|
15
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
16
16
|
|
|
17
17
|
export const getAccountShape: GetAccountShape<Account> = async info => {
|
|
18
18
|
const { initialAccount, currency, derivationMode } = info;
|
|
@@ -39,7 +39,7 @@ export const getAccountShape: GetAccountShape<Account> = async info => {
|
|
|
39
39
|
const newOperations = await getOperations(accountId, address, startAt);
|
|
40
40
|
|
|
41
41
|
//Get last token operations
|
|
42
|
-
const vthoToken =
|
|
42
|
+
const vthoToken = await getCryptoAssetsStore().findTokenById("vechain/vip180/vtho");
|
|
43
43
|
if (!vthoToken) throw new Error("VTHO token not found");
|
|
44
44
|
const vthoAccountId = encodeTokenAccountId(accountId, vthoToken);
|
|
45
45
|
const vthoOperations = await getTokenOperations(vthoAccountId, address, VTHO_ADDRESS, 1); // from parameter must be 1 otherwise the response is empty
|
|
@@ -27,6 +27,8 @@ describe("calculateGasFees", () => {
|
|
|
27
27
|
body: {},
|
|
28
28
|
} as Transaction;
|
|
29
29
|
|
|
30
|
+
const mockOriginAddress = "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
|
|
31
|
+
|
|
30
32
|
const mockClauses = [
|
|
31
33
|
{
|
|
32
34
|
to: "0x1234567890123456789012345678901234567890",
|
|
@@ -68,7 +70,7 @@ describe("calculateGasFees", () => {
|
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
it("should calculate gas fees for VET transfer", async () => {
|
|
71
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
73
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
72
74
|
|
|
73
75
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
74
76
|
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
@@ -76,7 +78,7 @@ describe("calculateGasFees", () => {
|
|
|
76
78
|
mockTransaction.amount,
|
|
77
79
|
);
|
|
78
80
|
expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
|
|
79
|
-
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses,
|
|
81
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses, mockOriginAddress);
|
|
80
82
|
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
81
83
|
mockClauses,
|
|
82
84
|
mockGasEstimation.totalGas,
|
|
@@ -97,7 +99,7 @@ describe("calculateGasFees", () => {
|
|
|
97
99
|
maxPriorityFeePerGas: null,
|
|
98
100
|
});
|
|
99
101
|
|
|
100
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
102
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
101
103
|
|
|
102
104
|
expect(result).toEqual({
|
|
103
105
|
estimatedGas: 21000,
|
|
@@ -110,7 +112,7 @@ describe("calculateGasFees", () => {
|
|
|
110
112
|
it("should handle transaction body with undefined gas values", async () => {
|
|
111
113
|
mockThorClient.transactions.buildTransactionBody.mockResolvedValue({});
|
|
112
114
|
|
|
113
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
115
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
114
116
|
|
|
115
117
|
expect(result).toEqual({
|
|
116
118
|
estimatedGas: 21000,
|
|
@@ -129,7 +131,7 @@ describe("calculateGasFees", () => {
|
|
|
129
131
|
};
|
|
130
132
|
mockedEstimateGas.mockResolvedValue(customGasEstimation);
|
|
131
133
|
|
|
132
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
134
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
133
135
|
|
|
134
136
|
expect(result).toEqual({
|
|
135
137
|
estimatedGas: 50000,
|
|
@@ -148,7 +150,7 @@ describe("calculateGasFees", () => {
|
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
it("should calculate gas fees for VTHO transfer", async () => {
|
|
151
|
-
const result = await calculateGasFees(mockTransaction, true);
|
|
153
|
+
const result = await calculateGasFees(mockTransaction, true, mockOriginAddress);
|
|
152
154
|
|
|
153
155
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
154
156
|
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
@@ -156,7 +158,7 @@ describe("calculateGasFees", () => {
|
|
|
156
158
|
mockTransaction.amount,
|
|
157
159
|
);
|
|
158
160
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
159
|
-
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses,
|
|
161
|
+
expect(mockedEstimateGas).toHaveBeenCalledWith(mockClauses, mockOriginAddress);
|
|
160
162
|
expect(mockThorClient.transactions.buildTransactionBody).toHaveBeenCalledWith(
|
|
161
163
|
mockClauses,
|
|
162
164
|
mockGasEstimation.totalGas,
|
|
@@ -177,7 +179,7 @@ describe("calculateGasFees", () => {
|
|
|
177
179
|
amount: new BigNumber("999999999999999999999999"),
|
|
178
180
|
};
|
|
179
181
|
|
|
180
|
-
const result = await calculateGasFees(largeAmountTransaction, true);
|
|
182
|
+
const result = await calculateGasFees(largeAmountTransaction, true, mockOriginAddress);
|
|
181
183
|
|
|
182
184
|
expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
|
|
183
185
|
largeAmountTransaction.recipient,
|
|
@@ -195,7 +197,7 @@ describe("calculateGasFees", () => {
|
|
|
195
197
|
recipient: undefined,
|
|
196
198
|
} as any;
|
|
197
199
|
|
|
198
|
-
const result = await calculateGasFees(transactionWithoutRecipient, false);
|
|
200
|
+
const result = await calculateGasFees(transactionWithoutRecipient, false, mockOriginAddress);
|
|
199
201
|
|
|
200
202
|
expect(mockedParseAddress).not.toHaveBeenCalled();
|
|
201
203
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
@@ -216,7 +218,7 @@ describe("calculateGasFees", () => {
|
|
|
216
218
|
recipient: null,
|
|
217
219
|
} as any;
|
|
218
220
|
|
|
219
|
-
const result = await calculateGasFees(transactionWithNullRecipient, false);
|
|
221
|
+
const result = await calculateGasFees(transactionWithNullRecipient, false, mockOriginAddress);
|
|
220
222
|
|
|
221
223
|
expect(result).toEqual({
|
|
222
224
|
estimatedGas: 0,
|
|
@@ -229,7 +231,7 @@ describe("calculateGasFees", () => {
|
|
|
229
231
|
it("should return zero values when parseAddress returns null/undefined", async () => {
|
|
230
232
|
mockedParseAddress.mockReturnValue(false);
|
|
231
233
|
|
|
232
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
234
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
233
235
|
|
|
234
236
|
expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
|
|
235
237
|
expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
|
|
@@ -247,7 +249,7 @@ describe("calculateGasFees", () => {
|
|
|
247
249
|
it("should return zero values when parseAddress returns empty string", async () => {
|
|
248
250
|
mockedParseAddress.mockReturnValue(false);
|
|
249
251
|
|
|
250
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
252
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
251
253
|
|
|
252
254
|
expect(result).toEqual({
|
|
253
255
|
estimatedGas: 0,
|
|
@@ -267,7 +269,7 @@ describe("calculateGasFees", () => {
|
|
|
267
269
|
const error = new Error("Failed to calculate VET clauses");
|
|
268
270
|
mockedCalculateClausesVet.mockRejectedValue(error);
|
|
269
271
|
|
|
270
|
-
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
272
|
+
await expect(calculateGasFees(mockTransaction, false, mockOriginAddress)).rejects.toThrow(
|
|
271
273
|
"Failed to calculate VET clauses",
|
|
272
274
|
);
|
|
273
275
|
});
|
|
@@ -276,7 +278,7 @@ describe("calculateGasFees", () => {
|
|
|
276
278
|
const error = new Error("Failed to calculate VTHO clauses");
|
|
277
279
|
mockedCalculateClausesVtho.mockRejectedValue(error);
|
|
278
280
|
|
|
279
|
-
await expect(calculateGasFees(mockTransaction, true)).rejects.toThrow(
|
|
281
|
+
await expect(calculateGasFees(mockTransaction, true, mockOriginAddress)).rejects.toThrow(
|
|
280
282
|
"Failed to calculate VTHO clauses",
|
|
281
283
|
);
|
|
282
284
|
});
|
|
@@ -286,7 +288,7 @@ describe("calculateGasFees", () => {
|
|
|
286
288
|
const error = new Error("Failed to estimate gas");
|
|
287
289
|
mockedEstimateGas.mockRejectedValue(error);
|
|
288
290
|
|
|
289
|
-
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
291
|
+
await expect(calculateGasFees(mockTransaction, false, mockOriginAddress)).rejects.toThrow(
|
|
290
292
|
"Failed to estimate gas",
|
|
291
293
|
);
|
|
292
294
|
});
|
|
@@ -297,7 +299,7 @@ describe("calculateGasFees", () => {
|
|
|
297
299
|
const error = new Error("Failed to build transaction body");
|
|
298
300
|
mockThorClient.transactions.buildTransactionBody.mockRejectedValue(error);
|
|
299
301
|
|
|
300
|
-
await expect(calculateGasFees(mockTransaction, false)).rejects.toThrow(
|
|
302
|
+
await expect(calculateGasFees(mockTransaction, false, mockOriginAddress)).rejects.toThrow(
|
|
301
303
|
"Failed to build transaction body",
|
|
302
304
|
);
|
|
303
305
|
});
|
|
@@ -316,7 +318,7 @@ describe("calculateGasFees", () => {
|
|
|
316
318
|
amount: new BigNumber("0"),
|
|
317
319
|
};
|
|
318
320
|
|
|
319
|
-
const result = await calculateGasFees(zeroAmountTransaction, false);
|
|
321
|
+
const result = await calculateGasFees(zeroAmountTransaction, false, mockOriginAddress);
|
|
320
322
|
|
|
321
323
|
expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
|
|
322
324
|
zeroAmountTransaction.recipient,
|
|
@@ -333,7 +335,7 @@ describe("calculateGasFees", () => {
|
|
|
333
335
|
vmErrors: [],
|
|
334
336
|
});
|
|
335
337
|
|
|
336
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
338
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
337
339
|
|
|
338
340
|
expect(result).toEqual({
|
|
339
341
|
estimatedGas: 0,
|
|
@@ -350,7 +352,7 @@ describe("calculateGasFees", () => {
|
|
|
350
352
|
};
|
|
351
353
|
mockThorClient.transactions.buildTransactionBody.mockResolvedValue(highGasTransactionBody);
|
|
352
354
|
|
|
353
|
-
const result = await calculateGasFees(mockTransaction, false);
|
|
355
|
+
const result = await calculateGasFees(mockTransaction, false, mockOriginAddress);
|
|
354
356
|
|
|
355
357
|
expect(result).toEqual({
|
|
356
358
|
estimatedGas: 21000,
|
|
@@ -8,6 +8,7 @@ import { getThorClient } from "./getThorClient";
|
|
|
8
8
|
export const calculateGasFees = async (
|
|
9
9
|
transaction: Transaction,
|
|
10
10
|
isTokenAccount: boolean,
|
|
11
|
+
originAddress: string,
|
|
11
12
|
): Promise<{
|
|
12
13
|
estimatedGas: number;
|
|
13
14
|
estimatedGasFees: BigNumber;
|
|
@@ -16,12 +17,14 @@ export const calculateGasFees = async (
|
|
|
16
17
|
}> => {
|
|
17
18
|
if (transaction.recipient && parseAddress(transaction.recipient)) {
|
|
18
19
|
let clauses;
|
|
20
|
+
|
|
19
21
|
if (isTokenAccount) {
|
|
20
22
|
clauses = await calculateClausesVtho(transaction.recipient, transaction.amount);
|
|
21
23
|
} else {
|
|
22
24
|
clauses = await calculateClausesVet(transaction.recipient, transaction.amount);
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
const gasEstimation = await estimateGas(clauses, originAddress);
|
|
25
28
|
const thorClient = getThorClient();
|
|
26
29
|
const body = await thorClient.transactions.buildTransactionBody(
|
|
27
30
|
clauses,
|
|
@@ -106,6 +106,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
106
106
|
amount: new BigNumber("1000000000000000000"),
|
|
107
107
|
}),
|
|
108
108
|
false,
|
|
109
|
+
mockAccount.freshAddress,
|
|
109
110
|
);
|
|
110
111
|
});
|
|
111
112
|
});
|
|
@@ -172,6 +173,7 @@ describe("calculateTransactionInfo", () => {
|
|
|
172
173
|
amount: new BigNumber("1000000000000000000"),
|
|
173
174
|
}),
|
|
174
175
|
true,
|
|
176
|
+
mockAccount.freshAddress,
|
|
175
177
|
);
|
|
176
178
|
});
|
|
177
179
|
|
|
@@ -4,6 +4,16 @@ import { Transaction, TransactionInfo } from "../types";
|
|
|
4
4
|
import { ImpossibleToCalculateAmountAndFees } from "../errors";
|
|
5
5
|
import { calculateGasFees } from "./calculateGasFees";
|
|
6
6
|
|
|
7
|
+
const getTokenAccount = (
|
|
8
|
+
subAccountId: string | null | undefined,
|
|
9
|
+
subAccounts: TokenAccount[] | undefined,
|
|
10
|
+
) =>
|
|
11
|
+
subAccountId && subAccounts
|
|
12
|
+
? subAccounts.find(subAccount => {
|
|
13
|
+
return subAccount.id === subAccountId;
|
|
14
|
+
})
|
|
15
|
+
: undefined;
|
|
16
|
+
|
|
7
17
|
// Here there is a circular dependency between values, that is why we need the do-while loop
|
|
8
18
|
// dependencies are:
|
|
9
19
|
// useAllAmount: USER
|
|
@@ -27,12 +37,7 @@ export const calculateTransactionInfo = async (
|
|
|
27
37
|
const { subAccounts } = account;
|
|
28
38
|
const { amount: oldAmount, subAccountId, useAllAmount } = transaction;
|
|
29
39
|
|
|
30
|
-
const tokenAccount =
|
|
31
|
-
subAccountId && subAccounts
|
|
32
|
-
? (subAccounts.find(subAccount => {
|
|
33
|
-
return subAccount.id === subAccountId;
|
|
34
|
-
}) as TokenAccount)
|
|
35
|
-
: undefined;
|
|
40
|
+
const tokenAccount = getTokenAccount(subAccountId, subAccounts);
|
|
36
41
|
const isTokenAccount = !!tokenAccount;
|
|
37
42
|
|
|
38
43
|
let amount = oldAmount;
|
|
@@ -52,7 +57,8 @@ export const calculateTransactionInfo = async (
|
|
|
52
57
|
amountBackup = amount;
|
|
53
58
|
|
|
54
59
|
const estimatedGasAndFees =
|
|
55
|
-
fixedMaxTokenFees ||
|
|
60
|
+
fixedMaxTokenFees ||
|
|
61
|
+
(await calculateGasFees(tempTransaction, isTokenAccount, account.freshAddress));
|
|
56
62
|
|
|
57
63
|
maxEstimatedGasFees = estimatedGasAndFees.estimatedGasFees;
|
|
58
64
|
maxEstimatedGas = estimatedGasAndFees.estimatedGas;
|