@ledgerhq/coin-tron 4.5.0-nightly.2 → 4.5.1-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +51 -13
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +2 -3
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/getEstimateFees.d.ts.map +1 -1
- package/lib/bridge/getEstimateFees.js +3 -4
- package/lib/bridge/getEstimateFees.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +3 -3
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.integ.test.js +11 -16
- package/lib/logic/craftTransaction.integ.test.js.map +1 -1
- package/lib/logic/craftTransaction.js +6 -5
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +10 -14
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +2 -2
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/estimateFees.test.js +4 -6
- package/lib/logic/estimateFees.test.js.map +1 -1
- package/lib/logic/getBalance.d.ts +3 -4
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.integ.test.js +4 -1
- package/lib/logic/getBalance.integ.test.js.map +1 -1
- package/lib/logic/getBalance.js +4 -6
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBalance.test.js +60 -20
- package/lib/logic/getBalance.test.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -2
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.integ.test.js +8 -12
- package/lib/logic/listOperations.integ.test.js.map +1 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.unit.test.js.map +1 -1
- package/lib/network/trongrid/trongrid-adapters.d.ts +2 -2
- package/lib/network/trongrid/trongrid-adapters.d.ts.map +1 -1
- package/lib/network/trongrid/trongrid-adapters.js +4 -6
- package/lib/network/trongrid/trongrid-adapters.js.map +1 -1
- package/lib/network/trongrid/trongrid-adapters.test.js +1 -1
- package/lib/network/trongrid/trongrid-adapters.test.js.map +1 -1
- package/lib/types/assets.d.ts +1 -11
- package/lib/types/assets.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +2 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +2 -3
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/getEstimateFees.d.ts.map +1 -1
- package/lib-es/bridge/getEstimateFees.js +3 -4
- package/lib-es/bridge/getEstimateFees.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +3 -3
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.integ.test.js +11 -16
- package/lib-es/logic/craftTransaction.integ.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.js +6 -5
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +10 -14
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +2 -2
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/estimateFees.test.js +4 -6
- package/lib-es/logic/estimateFees.test.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +3 -4
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.integ.test.js +4 -1
- package/lib-es/logic/getBalance.integ.test.js.map +1 -1
- package/lib-es/logic/getBalance.js +4 -6
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBalance.test.js +60 -20
- package/lib-es/logic/getBalance.test.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -2
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.integ.test.js +8 -12
- package/lib-es/logic/listOperations.integ.test.js.map +1 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.unit.test.js.map +1 -1
- package/lib-es/network/trongrid/trongrid-adapters.d.ts +2 -2
- package/lib-es/network/trongrid/trongrid-adapters.d.ts.map +1 -1
- package/lib-es/network/trongrid/trongrid-adapters.js +4 -6
- package/lib-es/network/trongrid/trongrid-adapters.js.map +1 -1
- package/lib-es/network/trongrid/trongrid-adapters.test.js +1 -1
- package/lib-es/network/trongrid/trongrid-adapters.test.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -11
- package/lib-es/types/assets.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/api/index.integ.test.ts +1 -2
- package/src/api/index.test.ts +4 -6
- package/src/api/index.ts +5 -7
- package/src/bridge/getEstimateFees.ts +5 -6
- package/src/logic/craftTransaction.integ.test.ts +11 -16
- package/src/logic/craftTransaction.test.ts +15 -20
- package/src/logic/craftTransaction.ts +11 -11
- package/src/logic/estimateFees.test.ts +7 -10
- package/src/logic/estimateFees.ts +3 -3
- package/src/logic/getBalance.integ.test.ts +4 -1
- package/src/logic/getBalance.test.ts +60 -20
- package/src/logic/getBalance.ts +12 -15
- package/src/logic/listOperations.integ.test.ts +12 -17
- package/src/logic/listOperations.ts +1 -2
- package/src/logic/listOperations.unit.test.ts +5 -5
- package/src/network/trongrid/trongrid-adapters.test.ts +1 -1
- package/src/network/trongrid/trongrid-adapters.ts +8 -10
- package/src/types/assets.ts +1 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trongrid-adapters.test.js","sourceRoot":"","sources":["../../../src/network/trongrid/trongrid-adapters.test.ts"],"names":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MAAM,CAAC,IAAI,CAAC;gBAClB,IAAI,EAAE,UAAU;aACjB;YACD,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;YACnB,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,UAAU,EAAE,CAAC,IAAI,CAAC;YAClB,KAAK,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"trongrid-adapters.test.js","sourceRoot":"","sources":["../../../src/network/trongrid/trongrid-adapters.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAGpE,6BAA6B;AAC7B,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,qBAAqB,EAAE,IAAI,CAAC,EAAE,EAAE;CACjC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,MAAM,eAAe,GAAG,MAAM,CAAC;IAE/B,MAAM,kBAAkB,GAAmB;QACzC,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,EAAE;QACf,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,MAAM,EAAE,uCAAuC;QACpD,KAAK,EAAE,MAAM,EAAE,yCAAyC;QACxD,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,IAAI;QACR,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,KAAK;KACS,CAAC;IAE/B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,qBAAmC,CAAC,kBAAkB,CACrD,CAAC,KAAa,EAAE,YAAoB,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CACxF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,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AC,CAAC;QAEtE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/types/assets.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StringMemo } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
import { MemoNotSupported } from "@ledgerhq/coin-framework/lib-es/api/types";
|
|
3
|
-
export type TronToken = Trc10Token | Trc20Token;
|
|
4
|
-
export type TronAsset = Asset<TronToken>;
|
|
5
|
-
export type Trc10Token = {
|
|
6
|
-
standard: "trc10";
|
|
7
|
-
tokenId: string;
|
|
8
|
-
};
|
|
9
|
-
export type Trc20Token = {
|
|
10
|
-
standard: "trc20";
|
|
11
|
-
contractAddress: string;
|
|
12
|
-
};
|
|
13
3
|
export type TronMemo = MemoNotSupported | StringMemo<"memo">;
|
|
14
4
|
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/types/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAyB7E,MAAM,MAAM,QAAQ,GAAG,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-tron",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1-nightly.0",
|
|
4
4
|
"description": "Ledger Tron Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -96,15 +96,15 @@
|
|
|
96
96
|
"lodash": "^4.17.21",
|
|
97
97
|
"rxjs": "^7.8.1",
|
|
98
98
|
"tronweb": "5.3.2",
|
|
99
|
-
"@ledgerhq/coin-framework": "^5.
|
|
100
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
101
|
-
"@ledgerhq/devices": "8.4.8
|
|
102
|
-
"@ledgerhq/errors": "^6.23.0
|
|
103
|
-
"@ledgerhq/live-network": "^2.0.
|
|
99
|
+
"@ledgerhq/coin-framework": "^5.9.0-nightly.0",
|
|
100
|
+
"@ledgerhq/cryptoassets": "^13.23.0",
|
|
101
|
+
"@ledgerhq/devices": "8.4.8",
|
|
102
|
+
"@ledgerhq/errors": "^6.23.0",
|
|
103
|
+
"@ledgerhq/live-network": "^2.0.14-nightly.0",
|
|
104
104
|
"@ledgerhq/live-promise": "^0.1.1",
|
|
105
105
|
"@ledgerhq/logs": "^6.13.0",
|
|
106
|
-
"@ledgerhq/types-cryptoassets": "^7.24.0
|
|
107
|
-
"@ledgerhq/types-live": "^6.
|
|
106
|
+
"@ledgerhq/types-cryptoassets": "^7.24.0",
|
|
107
|
+
"@ledgerhq/types-live": "^6.79.0"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@agrozyme/types-tronweb": "^5.3.2",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"ts-jest": "^29.1.1",
|
|
119
119
|
"typescript": "^5.4.5",
|
|
120
120
|
"@ledgerhq/disable-network-setup": "^0.0.0",
|
|
121
|
-
"@ledgerhq/types-cryptoassets": "^7.24.0
|
|
121
|
+
"@ledgerhq/types-cryptoassets": "^7.24.0"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"clean": "rimraf lib lib-es",
|
|
@@ -4,7 +4,6 @@ import dotenv from "dotenv";
|
|
|
4
4
|
import TronWeb from "tronweb";
|
|
5
5
|
import { createApi } from ".";
|
|
6
6
|
import { createTronWeb } from "../logic/utils";
|
|
7
|
-
import { TronAsset } from "../types";
|
|
8
7
|
|
|
9
8
|
const TRONGRID_URL = "https://api.shasta.trongrid.io";
|
|
10
9
|
dotenv.config();
|
|
@@ -25,7 +24,7 @@ const wallet = {
|
|
|
25
24
|
* Testnet faucet: https://shasta.tronex.io/
|
|
26
25
|
*/
|
|
27
26
|
describe("API", () => {
|
|
28
|
-
let module: AlpacaApi
|
|
27
|
+
let module: AlpacaApi;
|
|
29
28
|
let tronWeb: TronWeb;
|
|
30
29
|
|
|
31
30
|
beforeAll(() => {
|
package/src/api/index.test.ts
CHANGED
|
@@ -11,7 +11,6 @@ import coinConfig from "../config";
|
|
|
11
11
|
import { TronConfig } from "../config";
|
|
12
12
|
import { AlpacaApi, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
13
13
|
import { createApi } from ".";
|
|
14
|
-
import { TronAsset } from "../types";
|
|
15
14
|
|
|
16
15
|
jest.mock("../config", () => ({
|
|
17
16
|
setCoinConfig: jest.fn(),
|
|
@@ -49,16 +48,15 @@ describe("createApi", () => {
|
|
|
49
48
|
});
|
|
50
49
|
|
|
51
50
|
it("should pass parameters correctly", async () => {
|
|
52
|
-
const api: AlpacaApi
|
|
53
|
-
const intent: TransactionIntent
|
|
51
|
+
const api: AlpacaApi = createApi(mockTronConfig);
|
|
52
|
+
const intent: TransactionIntent = {
|
|
54
53
|
type: "send",
|
|
55
54
|
sender: "sender",
|
|
56
55
|
recipient: "recipient",
|
|
57
56
|
amount: BigInt(10),
|
|
58
57
|
asset: {
|
|
59
|
-
type: "
|
|
60
|
-
|
|
61
|
-
tokenId: "1002000",
|
|
58
|
+
type: "trc10",
|
|
59
|
+
assetReference: "1002000",
|
|
62
60
|
},
|
|
63
61
|
};
|
|
64
62
|
// Simulate calling all methods
|
package/src/api/index.ts
CHANGED
|
@@ -18,9 +18,9 @@ import {
|
|
|
18
18
|
lastBlock,
|
|
19
19
|
Options,
|
|
20
20
|
} from "../logic";
|
|
21
|
-
import type {
|
|
21
|
+
import type { TronMemo } from "../types";
|
|
22
22
|
|
|
23
|
-
export function createApi(config: TronConfig): AlpacaApi<
|
|
23
|
+
export function createApi(config: TronConfig): AlpacaApi<TronMemo> {
|
|
24
24
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
25
25
|
|
|
26
26
|
return {
|
|
@@ -31,7 +31,7 @@ export function createApi(config: TronConfig): AlpacaApi<TronAsset, TronMemo> {
|
|
|
31
31
|
getBalance,
|
|
32
32
|
lastBlock,
|
|
33
33
|
listOperations,
|
|
34
|
-
getBlock(_height): Promise<Block
|
|
34
|
+
getBlock(_height): Promise<Block> {
|
|
35
35
|
throw new Error("getBlock is not supported");
|
|
36
36
|
},
|
|
37
37
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
@@ -40,9 +40,7 @@ export function createApi(config: TronConfig): AlpacaApi<TronAsset, TronMemo> {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async function estimate(
|
|
44
|
-
transactionIntent: TransactionIntent<TronAsset, TronMemo>,
|
|
45
|
-
): Promise<FeeEstimation> {
|
|
43
|
+
async function estimate(transactionIntent: TransactionIntent<TronMemo>): Promise<FeeEstimation> {
|
|
46
44
|
const fees = await estimateFees(transactionIntent);
|
|
47
45
|
return { value: fees };
|
|
48
46
|
}
|
|
@@ -50,7 +48,7 @@ async function estimate(
|
|
|
50
48
|
async function listOperations(
|
|
51
49
|
address: string,
|
|
52
50
|
pagination: Pagination,
|
|
53
|
-
): Promise<[Operation
|
|
51
|
+
): Promise<[Operation[], string]> {
|
|
54
52
|
const { minHeight } = pagination;
|
|
55
53
|
const options: Options = {
|
|
56
54
|
softLimit: 200,
|
|
@@ -2,7 +2,7 @@ import { Account, TokenAccount } from "@ledgerhq/types-live";
|
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { ACTIVATION_FEES, STANDARD_FEES_NATIVE, STANDARD_FEES_TRC_20 } from "../logic/constants";
|
|
4
4
|
import type { AccountTronAPI } from "../network/types";
|
|
5
|
-
import type { Transaction
|
|
5
|
+
import type { Transaction } from "../types";
|
|
6
6
|
import { extractBandwidthInfo, getEstimatedBlockSize } from "./utils";
|
|
7
7
|
import { estimateFees, getAccount } from "../logic";
|
|
8
8
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
@@ -48,7 +48,7 @@ const getFeesFromAccountActivation = async (
|
|
|
48
48
|
return ACTIVATION_FEES; // cost is around 1 TRX
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const transactionIntent: TransactionIntent
|
|
51
|
+
const transactionIntent: TransactionIntent = {
|
|
52
52
|
type: transaction.mode,
|
|
53
53
|
sender: account.freshAddress,
|
|
54
54
|
recipient: transaction.recipient,
|
|
@@ -56,11 +56,10 @@ const getFeesFromAccountActivation = async (
|
|
|
56
56
|
asset:
|
|
57
57
|
tokenAccount?.token.tokenType === "trc20"
|
|
58
58
|
? {
|
|
59
|
-
type: "
|
|
60
|
-
|
|
61
|
-
contractAddress: tokenAccount.token.contractAddress,
|
|
59
|
+
type: "trc20",
|
|
60
|
+
assetReference: tokenAccount.token.contractAddress,
|
|
62
61
|
}
|
|
63
|
-
: { type: "
|
|
62
|
+
: { type: "trc10", assetReference: tokenAccount?.token.id },
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
// if we have a token account but the recipient is either not active or the account does not have a trc20 balance for the given token.
|
|
@@ -25,9 +25,8 @@ describe("Testing craftTransaction function", () => {
|
|
|
25
25
|
const result = await craftTransaction({
|
|
26
26
|
type: "send",
|
|
27
27
|
asset: {
|
|
28
|
-
type: "
|
|
29
|
-
|
|
30
|
-
tokenId: "1002000",
|
|
28
|
+
type: "trc10",
|
|
29
|
+
assetReference: "1002000",
|
|
31
30
|
},
|
|
32
31
|
sender,
|
|
33
32
|
recipient,
|
|
@@ -67,9 +66,8 @@ describe("Testing craftTransaction function", () => {
|
|
|
67
66
|
const result = await craftTransaction({
|
|
68
67
|
type: "send",
|
|
69
68
|
asset: {
|
|
70
|
-
type: "
|
|
71
|
-
|
|
72
|
-
contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
69
|
+
type: "trc20",
|
|
70
|
+
assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
73
71
|
},
|
|
74
72
|
sender,
|
|
75
73
|
recipient,
|
|
@@ -107,9 +105,8 @@ describe("Testing craftTransaction function", () => {
|
|
|
107
105
|
const result = await craftTransaction({
|
|
108
106
|
type: "send",
|
|
109
107
|
asset: {
|
|
110
|
-
type: "
|
|
111
|
-
|
|
112
|
-
contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
108
|
+
type: "trc20",
|
|
109
|
+
assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
113
110
|
},
|
|
114
111
|
sender,
|
|
115
112
|
recipient,
|
|
@@ -136,15 +133,14 @@ describe("Testing craftTransaction function", () => {
|
|
|
136
133
|
{
|
|
137
134
|
type: "send",
|
|
138
135
|
asset: {
|
|
139
|
-
type: "
|
|
140
|
-
|
|
141
|
-
contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
136
|
+
type: "trc20",
|
|
137
|
+
assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
142
138
|
},
|
|
143
139
|
sender,
|
|
144
140
|
recipient,
|
|
145
141
|
amount,
|
|
146
142
|
},
|
|
147
|
-
customFees,
|
|
143
|
+
{ value: customFees },
|
|
148
144
|
);
|
|
149
145
|
|
|
150
146
|
const decodeResult = await decodeTransaction(result);
|
|
@@ -233,9 +229,8 @@ describe("Testing craftTransaction function", () => {
|
|
|
233
229
|
craftTransaction({
|
|
234
230
|
type: "send",
|
|
235
231
|
asset: {
|
|
236
|
-
type: "
|
|
237
|
-
|
|
238
|
-
contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
232
|
+
type: "trc20",
|
|
233
|
+
assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
239
234
|
},
|
|
240
235
|
sender,
|
|
241
236
|
recipient,
|
|
@@ -2,7 +2,6 @@ import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { craftStandardTransaction, craftTrc20Transaction } from "../network";
|
|
4
4
|
import { decode58Check } from "../network/format";
|
|
5
|
-
import { TronAsset } from "../types";
|
|
6
5
|
import { craftTransaction } from "./craftTransaction";
|
|
7
6
|
|
|
8
7
|
jest.mock("../network/format", () => ({
|
|
@@ -22,7 +21,7 @@ describe("craftTransaction", () => {
|
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
it("should craft a standard transaction", async () => {
|
|
25
|
-
const transactionIntent: TransactionIntent
|
|
24
|
+
const transactionIntent: TransactionIntent = {
|
|
26
25
|
asset: { type: "native" },
|
|
27
26
|
type: "send",
|
|
28
27
|
recipient: "recipient",
|
|
@@ -52,12 +51,11 @@ describe("craftTransaction", () => {
|
|
|
52
51
|
});
|
|
53
52
|
|
|
54
53
|
it("should craft a TRC20 transaction", async () => {
|
|
55
|
-
const transactionIntent: TransactionIntent
|
|
54
|
+
const transactionIntent: TransactionIntent = {
|
|
56
55
|
type: "send",
|
|
57
56
|
asset: {
|
|
58
|
-
type: "
|
|
59
|
-
|
|
60
|
-
contractAddress: "contractAddress",
|
|
57
|
+
type: "trc20",
|
|
58
|
+
assetReference: "contractAddress",
|
|
61
59
|
},
|
|
62
60
|
recipient: "recipient",
|
|
63
61
|
sender: "sender",
|
|
@@ -89,19 +87,18 @@ describe("craftTransaction", () => {
|
|
|
89
87
|
const amount: number = 1000;
|
|
90
88
|
const transactionIntent = {
|
|
91
89
|
asset: {
|
|
92
|
-
type: "
|
|
93
|
-
|
|
94
|
-
contractAddress: "contractAddress",
|
|
90
|
+
type: "trc20",
|
|
91
|
+
assetReference: "contractAddress",
|
|
95
92
|
},
|
|
96
93
|
amount: BigInt(amount),
|
|
97
|
-
} as TransactionIntent
|
|
94
|
+
} as TransactionIntent;
|
|
98
95
|
|
|
99
96
|
(decode58Check as jest.Mock).mockImplementation(_address => undefined);
|
|
100
97
|
(craftTrc20Transaction as jest.Mock).mockResolvedValue({
|
|
101
98
|
raw_data_hex: "extendedRawDataHex",
|
|
102
99
|
});
|
|
103
100
|
|
|
104
|
-
await craftTransaction(transactionIntent, customFees);
|
|
101
|
+
await craftTransaction(transactionIntent, { value: customFees });
|
|
105
102
|
expect(craftTrc20Transaction).toHaveBeenCalledWith(
|
|
106
103
|
"contractAddress",
|
|
107
104
|
undefined,
|
|
@@ -116,12 +113,11 @@ describe("craftTransaction", () => {
|
|
|
116
113
|
const amount = 1000;
|
|
117
114
|
const transactionIntent = {
|
|
118
115
|
asset: {
|
|
119
|
-
type: "
|
|
120
|
-
|
|
121
|
-
contractAddress: "contractAddress",
|
|
116
|
+
type: "trc20",
|
|
117
|
+
assetReference: "contractAddress",
|
|
122
118
|
},
|
|
123
119
|
amount: BigInt(amount),
|
|
124
|
-
} as TransactionIntent
|
|
120
|
+
} as TransactionIntent;
|
|
125
121
|
|
|
126
122
|
(decode58Check as jest.Mock).mockImplementation(_address => undefined);
|
|
127
123
|
(craftTrc20Transaction as jest.Mock).mockResolvedValue({
|
|
@@ -146,12 +142,11 @@ describe("craftTransaction", () => {
|
|
|
146
142
|
await craftTransaction(
|
|
147
143
|
{
|
|
148
144
|
asset: {
|
|
149
|
-
type: "
|
|
150
|
-
|
|
151
|
-
contractAddress: "contractAddress",
|
|
145
|
+
type: "trc20",
|
|
146
|
+
assetReference: "contractAddress",
|
|
152
147
|
},
|
|
153
|
-
} as TransactionIntent
|
|
154
|
-
customFees,
|
|
148
|
+
} as TransactionIntent,
|
|
149
|
+
{ value: customFees },
|
|
155
150
|
);
|
|
156
151
|
} catch (error) {
|
|
157
152
|
expect((error as Error).message).toEqual(
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
1
|
+
import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { craftStandardTransaction, craftTrc20Transaction } from "../network";
|
|
4
4
|
import { decode58Check } from "../network/format";
|
|
5
|
-
import {
|
|
5
|
+
import { TronMemo } from "../types";
|
|
6
6
|
import { feesToNumber } from "./utils";
|
|
7
7
|
|
|
8
8
|
export async function craftTransaction(
|
|
9
|
-
transactionIntent: TransactionIntent<
|
|
10
|
-
customFees?:
|
|
9
|
+
transactionIntent: TransactionIntent<TronMemo>,
|
|
10
|
+
customFees?: FeeEstimation,
|
|
11
11
|
): Promise<string> {
|
|
12
12
|
const { asset, recipient, sender, amount, expiration } = transactionIntent;
|
|
13
13
|
const rawMemo = "memo" in transactionIntent ? transactionIntent.memo : undefined;
|
|
@@ -16,8 +16,9 @@ export async function craftTransaction(
|
|
|
16
16
|
const recipientAddress = decode58Check(recipient);
|
|
17
17
|
const senderAddress = decode58Check(sender);
|
|
18
18
|
|
|
19
|
-
if (asset.type === "
|
|
20
|
-
|
|
19
|
+
if (asset.type === "trc20" && asset.assetReference) {
|
|
20
|
+
const fees = customFees?.value;
|
|
21
|
+
if (fees !== undefined && (fees <= 0 || fees > Number.MAX_SAFE_INTEGER)) {
|
|
21
22
|
throw new Error(
|
|
22
23
|
`fees must be between 0 and ${Number.MAX_SAFE_INTEGER} (Typescript Number type value limit)`,
|
|
23
24
|
);
|
|
@@ -28,18 +29,17 @@ export async function craftTransaction(
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
const { raw_data_hex: rawDataHex } = await craftTrc20Transaction(
|
|
31
|
-
asset.
|
|
32
|
+
asset.assetReference,
|
|
32
33
|
recipientAddress,
|
|
33
34
|
senderAddress,
|
|
34
35
|
new BigNumber(amount.toString()),
|
|
35
|
-
feesToNumber(
|
|
36
|
+
feesToNumber(fees),
|
|
36
37
|
expiration,
|
|
37
38
|
);
|
|
38
39
|
return rawDataHex as string;
|
|
39
40
|
} else {
|
|
40
|
-
const isTransferAsset = asset.type === "
|
|
41
|
-
const tokenId =
|
|
42
|
-
asset.type === "token" && asset.standard === "trc10" ? asset.tokenId : undefined;
|
|
41
|
+
const isTransferAsset = asset.type === "trc10";
|
|
42
|
+
const tokenId = asset.type === "trc10" ? asset.assetReference : undefined;
|
|
43
43
|
const { raw_data_hex: rawDataHex } = await craftStandardTransaction(
|
|
44
44
|
tokenId,
|
|
45
45
|
recipientAddress,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { estimateFees } from "./estimateFees";
|
|
2
2
|
import { ACTIVATION_FEES_TRC_20, STANDARD_FEES_NATIVE } from "./constants";
|
|
3
3
|
import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
4
|
-
import { TronAsset } from "../types";
|
|
5
4
|
|
|
6
5
|
describe("estimateFees", () => {
|
|
7
6
|
it("should calculate fees for native trx transactionIntent", async () => {
|
|
8
|
-
const transactionIntent: TransactionIntent
|
|
7
|
+
const transactionIntent: TransactionIntent = {
|
|
9
8
|
type: "send",
|
|
10
9
|
sender: "sender1",
|
|
11
10
|
recipient: "recipient1",
|
|
@@ -18,15 +17,14 @@ describe("estimateFees", () => {
|
|
|
18
17
|
expect(result).toEqual(BigInt(STANDARD_FEES_NATIVE.toString()));
|
|
19
18
|
});
|
|
20
19
|
it("should calculate fees for trc10 transactionIntent", async () => {
|
|
21
|
-
const transactionIntent: TransactionIntent
|
|
20
|
+
const transactionIntent: TransactionIntent = {
|
|
22
21
|
type: "send",
|
|
23
22
|
sender: "sender1",
|
|
24
23
|
recipient: "recipient1",
|
|
25
24
|
amount: BigInt(1000),
|
|
26
25
|
asset: {
|
|
27
|
-
type: "
|
|
28
|
-
|
|
29
|
-
tokenId: "1002000",
|
|
26
|
+
type: "trc10",
|
|
27
|
+
assetReference: "1002000",
|
|
30
28
|
},
|
|
31
29
|
};
|
|
32
30
|
|
|
@@ -36,15 +34,14 @@ describe("estimateFees", () => {
|
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
it("should calculate fees for trc20 transactionIntent", async () => {
|
|
39
|
-
const transactionIntent: TransactionIntent
|
|
37
|
+
const transactionIntent: TransactionIntent = {
|
|
40
38
|
type: "send",
|
|
41
39
|
sender: "sender1",
|
|
42
40
|
recipient: "recipient1",
|
|
43
41
|
amount: BigInt(1000),
|
|
44
42
|
asset: {
|
|
45
|
-
type: "
|
|
46
|
-
|
|
47
|
-
contractAddress: "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
|
|
43
|
+
type: "trc20",
|
|
44
|
+
assetReference: "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
|
|
48
45
|
},
|
|
49
46
|
};
|
|
50
47
|
const result = await estimateFees(transactionIntent);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TronMemo } from "../types";
|
|
2
2
|
import { ACTIVATION_FEES_TRC_20, STANDARD_FEES_NATIVE } from "./constants";
|
|
3
3
|
import type { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
4
4
|
|
|
5
5
|
export async function estimateFees(
|
|
6
|
-
transactionIntent: TransactionIntent<
|
|
6
|
+
transactionIntent: TransactionIntent<TronMemo>,
|
|
7
7
|
): Promise<bigint> {
|
|
8
|
-
if (transactionIntent.asset.type === "
|
|
8
|
+
if (transactionIntent.asset.type === "trc20") {
|
|
9
9
|
return BigInt(ACTIVATION_FEES_TRC_20.toString());
|
|
10
10
|
} else {
|
|
11
11
|
return BigInt(STANDARD_FEES_NATIVE.toString());
|
|
@@ -17,7 +17,10 @@ describe("getBalance", () => {
|
|
|
17
17
|
const balances = await getBalance("TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9");
|
|
18
18
|
|
|
19
19
|
expect(balances[0].asset).toEqual({ type: "native" });
|
|
20
|
-
|
|
20
|
+
// Backend either returns trc10 or trc20 first (randomly)
|
|
21
|
+
balances
|
|
22
|
+
.slice(1)
|
|
23
|
+
.forEach(balance => expect(["trc20", "trc10"].includes(balance.asset.type)).toBe(true));
|
|
21
24
|
balances.forEach(balance => expect(balance.value).toBeGreaterThanOrEqual(0));
|
|
22
25
|
});
|
|
23
26
|
});
|
|
@@ -224,33 +224,73 @@ describe("getBalance", () => {
|
|
|
224
224
|
const balance = await getBalance("41ae18eb0a9e067f8884058470ed187f44135d816d");
|
|
225
225
|
expect(balance).toEqual([
|
|
226
226
|
{ asset: { type: "native" }, value: 27781772n },
|
|
227
|
-
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
{
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
{
|
|
240
|
-
|
|
227
|
+
{
|
|
228
|
+
asset: { type: "trc10", assetReference: "1002897" },
|
|
229
|
+
value: 10000000n,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
asset: { type: "trc10", assetReference: "1002775" },
|
|
233
|
+
value: 5000000n,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
asset: { type: "trc10", assetReference: "1002830" },
|
|
237
|
+
value: 10000000n,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
asset: { type: "trc10", assetReference: "1002962" },
|
|
241
|
+
value: 10000000n,
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
asset: { type: "trc10", assetReference: "1002876" },
|
|
245
|
+
value: 10000000n,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
asset: { type: "trc10", assetReference: "1002398" },
|
|
249
|
+
value: 5000000n,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
asset: { type: "trc10", assetReference: "1002573" },
|
|
253
|
+
value: 5000000n,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
asset: { type: "trc10", assetReference: "1002881" },
|
|
257
|
+
value: 10000000n,
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
asset: { type: "trc10", assetReference: "1002927" },
|
|
261
|
+
value: 10000000n,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
asset: { type: "trc10", assetReference: "1002736" },
|
|
265
|
+
value: 5000000n,
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
asset: { type: "trc10", assetReference: "1002814" },
|
|
269
|
+
value: 10000000n,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
asset: { type: "trc10", assetReference: "1002858" },
|
|
273
|
+
value: 10000000n,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
asset: { type: "trc10", assetReference: "1002000" },
|
|
277
|
+
value: 26888000n,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
asset: { type: "trc10", assetReference: "1004031" },
|
|
281
|
+
value: 9856699n,
|
|
282
|
+
},
|
|
241
283
|
{
|
|
242
284
|
asset: {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
type: "token",
|
|
285
|
+
type: "trc20",
|
|
286
|
+
assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
|
|
246
287
|
},
|
|
247
288
|
value: 46825830n,
|
|
248
289
|
},
|
|
249
290
|
{
|
|
250
291
|
asset: {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
type: "token",
|
|
292
|
+
type: "trc20",
|
|
293
|
+
assetReference: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
254
294
|
},
|
|
255
295
|
value: 376n,
|
|
256
296
|
},
|
package/src/logic/getBalance.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import type { AccountTronAPI } from "../network/types";
|
|
3
3
|
import { getTronResources } from "./utils";
|
|
4
|
-
import {
|
|
4
|
+
import { Balance } from "@ledgerhq/coin-framework/api/index";
|
|
5
5
|
import { fetchTronAccount } from "../network";
|
|
6
|
-
import { Trc10Token, Trc20Token, TronAsset } from "../types";
|
|
7
6
|
|
|
8
7
|
const bigIntOrZero = (val: number | BigNumber | undefined | null): bigint =>
|
|
9
8
|
BigInt(val?.toString() ?? 0);
|
|
10
9
|
|
|
11
|
-
export async function getBalance(address: string): Promise<Balance
|
|
10
|
+
export async function getBalance(address: string): Promise<Balance[]> {
|
|
12
11
|
const accounts = await fetchTronAccount(address);
|
|
13
12
|
|
|
14
13
|
// if account is not activated, an empty array is returned
|
|
@@ -16,43 +15,41 @@ export async function getBalance(address: string): Promise<Balance<TronAsset>[]>
|
|
|
16
15
|
|
|
17
16
|
const account = accounts[0];
|
|
18
17
|
|
|
19
|
-
const nativeBalance: Balance
|
|
20
|
-
const trc10Balance: Balance
|
|
21
|
-
const trc20Balance: Balance
|
|
18
|
+
const nativeBalance: Balance = computeBalance(account);
|
|
19
|
+
const trc10Balance: Balance[] = extractTrc10Balance(account);
|
|
20
|
+
const trc20Balance: Balance[] = extractTrc20Balance(account);
|
|
22
21
|
|
|
23
22
|
return [nativeBalance].concat(trc10Balance).concat(trc20Balance);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
function extractTrc10Balance(account: AccountTronAPI): Balance
|
|
25
|
+
function extractTrc10Balance(account: AccountTronAPI): Balance[] {
|
|
27
26
|
return (
|
|
28
27
|
account.assetV2?.map(trc => {
|
|
29
28
|
return {
|
|
30
29
|
value: BigInt(trc.value),
|
|
31
30
|
asset: {
|
|
32
|
-
type: "
|
|
33
|
-
|
|
34
|
-
tokenId: trc.key,
|
|
31
|
+
type: "trc10",
|
|
32
|
+
assetReference: trc.key,
|
|
35
33
|
},
|
|
36
34
|
};
|
|
37
35
|
}) ?? []
|
|
38
36
|
);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
function extractTrc20Balance(account: AccountTronAPI): Balance
|
|
39
|
+
function extractTrc20Balance(account: AccountTronAPI): Balance[] {
|
|
42
40
|
return account.trc20.map(trc => {
|
|
43
41
|
const [[contractAddress, balance]] = Object.entries(trc);
|
|
44
42
|
return {
|
|
45
43
|
value: BigInt(balance),
|
|
46
44
|
asset: {
|
|
47
|
-
type: "
|
|
48
|
-
|
|
49
|
-
contractAddress,
|
|
45
|
+
type: "trc20",
|
|
46
|
+
assetReference: contractAddress,
|
|
50
47
|
},
|
|
51
48
|
};
|
|
52
49
|
});
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
export function computeBalance(account: AccountTronAPI): Balance
|
|
52
|
+
export function computeBalance(account: AccountTronAPI): Balance {
|
|
56
53
|
const tronResources = getTronResources(account);
|
|
57
54
|
|
|
58
55
|
let balance = bigIntOrZero(account.balance ?? 0);
|