@tatumio/tron 2.0.1-alpha.231

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/package.json +28 -0
  2. package/src/index.d.ts +1 -0
  3. package/src/index.js +5 -0
  4. package/src/index.js.map +1 -0
  5. package/src/lib/services/tron.custodial.d.ts +59 -0
  6. package/src/lib/services/tron.custodial.js +131 -0
  7. package/src/lib/services/tron.custodial.js.map +1 -0
  8. package/src/lib/services/tron.record.d.ts +17 -0
  9. package/src/lib/services/tron.record.js +24 -0
  10. package/src/lib/services/tron.record.js.map +1 -0
  11. package/src/lib/services/tron.trc10.d.ts +39 -0
  12. package/src/lib/services/tron.trc10.js +105 -0
  13. package/src/lib/services/tron.trc10.js.map +1 -0
  14. package/src/lib/services/tron.trc20.d.ts +45 -0
  15. package/src/lib/services/tron.trc20.js +133 -0
  16. package/src/lib/services/tron.trc20.js.map +1 -0
  17. package/src/lib/services/tron.trc721.d.ts +127 -0
  18. package/src/lib/services/tron.trc721.js +396 -0
  19. package/src/lib/services/tron.trc721.js.map +1 -0
  20. package/src/lib/services/tron.tx.d.ts +150 -0
  21. package/src/lib/services/tron.tx.js +236 -0
  22. package/src/lib/services/tron.tx.js.map +1 -0
  23. package/src/lib/services/tron.utils.d.ts +1 -0
  24. package/src/lib/services/tron.utils.js +82 -0
  25. package/src/lib/services/tron.utils.js.map +1 -0
  26. package/src/lib/services/tron.wallet.d.ts +49 -0
  27. package/src/lib/services/tron.wallet.js +76 -0
  28. package/src/lib/services/tron.wallet.js.map +1 -0
  29. package/src/lib/services/tron.web.d.ts +5 -0
  30. package/src/lib/services/tron.web.js +27 -0
  31. package/src/lib/services/tron.web.js.map +1 -0
  32. package/src/lib/tron.sdk.d.ts +230 -0
  33. package/src/lib/tron.sdk.js +25 -0
  34. package/src/lib/tron.sdk.js.map +1 -0
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@tatumio/tron",
3
+ "version": "2.0.1-alpha.231",
4
+ "type": "commonjs",
5
+ "license": "MIT",
6
+ "main": "./src/index.js",
7
+ "typings": "./src/index.d.ts",
8
+ "dependencies": {
9
+ "@tatumio/shared-testing-common": "2.0.1-alpha.231",
10
+ "@tatumio/shared-blockchain-abstract": "2.0.1-alpha.231",
11
+ "@tatumio/api-client": "2.0.1-alpha.231",
12
+ "axios": "^0.24.0",
13
+ "form-data": "^4.0.0",
14
+ "@tatumio/shared-core": "2.0.1-alpha.231",
15
+ "@tatumio/shared-abstract-sdk": "2.0.1-alpha.231",
16
+ "bignumber.js": "^9.0.2",
17
+ "@tatumio/shared-blockchain-evm-based": "2.0.1-alpha.231",
18
+ "ethereumjs-wallet": "^1.0.2",
19
+ "bip39": "^3.0.2",
20
+ "web3": "^1.7.0",
21
+ "web3-core": "^1.7.0",
22
+ "@harmony-js/crypto": "^0.1.56",
23
+ "bip32": "^2.0.5",
24
+ "bitcoinjs-lib": "^5.2.0",
25
+ "tronweb": "^4.1.0"
26
+ },
27
+ "peerDependencies": {}
28
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/tron.sdk';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./lib/tron.sdk"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/blockchain/tron/src/index.ts"],"names":[],"mappings":";;;AAAA,8DAA8B"}
@@ -0,0 +1,59 @@
1
+ import { GenerateCustodialWalletTron, GenerateCustodialWalletTronKMS, TransferCustodialWalletBatchTron, TransferCustodialWalletBatchTronKMS, TransferCustodialWalletTron, TransferCustodialWalletTronKMS } from '@tatumio/api-client';
2
+ import { ITronWeb } from './tron.web';
3
+ export declare const tronCustodial: (args: {
4
+ tronWeb: ITronWeb;
5
+ }) => {
6
+ prepare: {
7
+ /**
8
+ * This method is @Deprecated. Use @link{prepareCustodialWalletBatch} instead
9
+ * Generate new smart contract based custodial wallet. This wallet is able to receive any type of assets, btu transaction costs connected to the withdrawal
10
+ * of assets is covered by the deployer.
11
+ * @param body request data
12
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
13
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
14
+ */
15
+ custodialWallet: (body: GenerateCustodialWalletTron | GenerateCustodialWalletTronKMS, provider?: string) => Promise<string>;
16
+ /**
17
+ * Prepare signed transaction from the custodial SC wallet.
18
+ * @param testnet chain to work with
19
+ * @param body request data
20
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
21
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
22
+ */
23
+ transferFromCustodialWallet: (body: TransferCustodialWalletTron | TransferCustodialWalletTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<string>;
24
+ /**
25
+ * Prepare signed batch transaction from the custodial SC wallet.
26
+ * @param testnet chain to work with
27
+ * @param body request data
28
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
29
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
30
+ */
31
+ batchTransferFromCustodialWallet: (body: TransferCustodialWalletBatchTron | TransferCustodialWalletBatchTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<string>;
32
+ };
33
+ send: {
34
+ /**
35
+ * Generate new smart contract based custodial wallet. This wallet is able to receive any type of assets, btu transaction costs connected to the withdrawal
36
+ * of assets is covered by the deployer.
37
+ * @param body request data
38
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
39
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
40
+ */
41
+ custodialWallet: (body: GenerateCustodialWalletTron | GenerateCustodialWalletTronKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
42
+ /**
43
+ * Send signed transaction from the custodial SC wallet.
44
+ * @param testnet chain to work with
45
+ * @param body request data
46
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
47
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
48
+ */
49
+ transferFromCustodialWallet: (body: TransferCustodialWalletTron | TransferCustodialWalletTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<import("@tatumio/api-client").TransactionHash>;
50
+ /**
51
+ * Send signed batch transaction from the custodial SC wallet.
52
+ * @param testnet chain to work with
53
+ * @param body request data
54
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
55
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
56
+ */
57
+ batchTransferFromCustodialWallet: (body: TransferCustodialWalletBatchTron | TransferCustodialWalletBatchTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<import("@tatumio/api-client").TransactionHash>;
58
+ };
59
+ };
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronCustodial = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_client_1 = require("@tatumio/api-client");
6
+ const tron_tx_1 = require("./tron.tx");
7
+ const shared_blockchain_evm_based_1 = require("@tatumio/shared-blockchain-evm-based");
8
+ const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
9
+ const NATIVE_ASSET_CONTRACT_TYPE = 3;
10
+ const NON_FUNGIBLE_TOKEN_CONTRACT_TYPE = 1;
11
+ const FUNGIBLE_TOKEN_CONTRACT_TYPE = 0;
12
+ const prepareTransferFromCustodialWallet = (body, getContractDecimals, tronWeb, provider, decimals = 18, testnet = false) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
13
+ var _a, _b;
14
+ const methodName = 'transfer';
15
+ let tokenId = new bignumber_js_1.default((_a = body.tokenId) !== null && _a !== void 0 ? _a : 0);
16
+ let amount = new bignumber_js_1.default((_b = body.amount) !== null && _b !== void 0 ? _b : 0);
17
+ if (body.contractType === NATIVE_ASSET_CONTRACT_TYPE) {
18
+ amount = amount.multipliedBy(new bignumber_js_1.default(10).pow(decimals));
19
+ }
20
+ else if (body.contractType === FUNGIBLE_TOKEN_CONTRACT_TYPE) {
21
+ tokenId = new bignumber_js_1.default(0);
22
+ if (!body.tokenAddress) {
23
+ throw new Error('No tokenAddress specified which is needed for FUNGIBLE_TOKEN_CONTRACT_TYPE');
24
+ }
25
+ amount = amount.multipliedBy(new bignumber_js_1.default(10).pow(yield getContractDecimals(body.tokenAddress, provider, testnet)));
26
+ }
27
+ const params = Object.assign(Object.assign({}, body), { methodName, contractAddress: body.custodialAddress, methodABI: shared_blockchain_evm_based_1.CustodialFullTokenWallet.abi.find((abi) => abi.name === methodName), params: [
28
+ body.tokenAddress || '0x000000000000000000000000000000000000dEaD',
29
+ body.contractType,
30
+ body.recipient,
31
+ `0x${amount.toString(16)}`,
32
+ `0x${new bignumber_js_1.default(tokenId).toString(16)}`,
33
+ ] });
34
+ return (0, tron_tx_1.tronTx)({ tronWeb }).prepare.smartContractInvocation(params, provider);
35
+ });
36
+ const prepareBatchTransferFromCustodialWallet = (body, getContractDecimals, tronWeb, provider, decimals = 6, testnet = false) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
37
+ const methodName = 'transferBatch';
38
+ const amounts = [];
39
+ const tokenIds = [];
40
+ for (let i = 0; i < body.contractType.length; i++) {
41
+ let amount = new bignumber_js_1.default(body.amount ? body.amount[i] : 0);
42
+ let tokenId = new bignumber_js_1.default(body.tokenId ? body.tokenId[i] : 0);
43
+ if (body.contractType[i] === NATIVE_ASSET_CONTRACT_TYPE) {
44
+ amount = amount.multipliedBy(new bignumber_js_1.default(10).pow(decimals));
45
+ }
46
+ else if (body.contractType[i] === NON_FUNGIBLE_TOKEN_CONTRACT_TYPE) {
47
+ amount = new bignumber_js_1.default(0);
48
+ }
49
+ else if (body.contractType[i] === FUNGIBLE_TOKEN_CONTRACT_TYPE && body.tokenAddress) {
50
+ tokenId = new bignumber_js_1.default(0);
51
+ amount = amount.multipliedBy(new bignumber_js_1.default(10).pow(yield getContractDecimals(body.tokenAddress[i], provider, testnet)));
52
+ }
53
+ amounts.push(`0x${amount.toString(16)}`);
54
+ tokenIds.push(`0x${tokenId.toString(16)}`);
55
+ }
56
+ const params = Object.assign(Object.assign({}, body), { amount: undefined, methodName, contractAddress: body.custodialAddress, methodABI: shared_blockchain_evm_based_1.CustodialFullTokenWallet.abi.find((abi) => abi.name === methodName), params: [
57
+ (body.tokenAddress || []).map((t) => (t === '0' ? '0x000000000000000000000000000000000000dEaD' : t)),
58
+ body.contractType,
59
+ body.recipient,
60
+ amounts,
61
+ tokenIds,
62
+ ] });
63
+ return (0, tron_tx_1.tronTx)({ tronWeb }).prepare.smartContractInvocation(params, provider);
64
+ });
65
+ const tronCustodial = (args) => {
66
+ return {
67
+ prepare: {
68
+ /**
69
+ * This method is @Deprecated. Use @link{prepareCustodialWalletBatch} instead
70
+ * Generate new smart contract based custodial wallet. This wallet is able to receive any type of assets, btu transaction costs connected to the withdrawal
71
+ * of assets is covered by the deployer.
72
+ * @param body request data
73
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
74
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
75
+ */
76
+ custodialWallet: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return (0, tron_tx_1.tronTx)(args).prepare.generateCustodialWalletSignedTransaction(body, provider); }),
77
+ /**
78
+ * Prepare signed transaction from the custodial SC wallet.
79
+ * @param testnet chain to work with
80
+ * @param body request data
81
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
82
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
83
+ */
84
+ transferFromCustodialWallet: (body, getContractDecimals, provider, decimals = 18, testnet = false) => prepareTransferFromCustodialWallet(body, getContractDecimals, args.tronWeb, provider, decimals, testnet),
85
+ /**
86
+ * Prepare signed batch transaction from the custodial SC wallet.
87
+ * @param testnet chain to work with
88
+ * @param body request data
89
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
90
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
91
+ */
92
+ batchTransferFromCustodialWallet: (body, getContractDecimals, provider, decimals = 6, testnet = false) => prepareBatchTransferFromCustodialWallet(body, getContractDecimals, args.tronWeb, provider, decimals, testnet),
93
+ },
94
+ send: {
95
+ /**
96
+ * Generate new smart contract based custodial wallet. This wallet is able to receive any type of assets, btu transaction costs connected to the withdrawal
97
+ * of assets is covered by the deployer.
98
+ * @param body request data
99
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
100
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
101
+ */
102
+ custodialWallet: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return (0, tron_tx_1.tronTx)(args).send.generateCustodialWalletSignedTransaction(body, provider); }),
103
+ /**
104
+ * Send signed transaction from the custodial SC wallet.
105
+ * @param testnet chain to work with
106
+ * @param body request data
107
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
108
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
109
+ */
110
+ transferFromCustodialWallet: (body, getContractDecimals, provider, decimals = 18, testnet = false) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
111
+ return api_client_1.BlockchainTronService.tronBroadcast({
112
+ txData: yield prepareTransferFromCustodialWallet(body, getContractDecimals, args.tronWeb, provider, decimals, testnet),
113
+ });
114
+ }),
115
+ /**
116
+ * Send signed batch transaction from the custodial SC wallet.
117
+ * @param testnet chain to work with
118
+ * @param body request data
119
+ * @param provider optional provider to enter. if not present, Tatum Web3 will be used.
120
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
121
+ */
122
+ batchTransferFromCustodialWallet: (body, getContractDecimals, provider, decimals = 6, testnet = false) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
123
+ return api_client_1.BlockchainTronService.tronBroadcast({
124
+ txData: yield prepareBatchTransferFromCustodialWallet(body, getContractDecimals, args.tronWeb, provider, decimals, testnet),
125
+ });
126
+ }),
127
+ },
128
+ };
129
+ };
130
+ exports.tronCustodial = tronCustodial;
131
+ //# sourceMappingURL=tron.custodial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.custodial.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.custodial.ts"],"names":[],"mappings":";;;;AAAA,oDAU4B;AAE5B,uCAAkC;AAClC,sFAA+E;AAC/E,6EAAoC;AAEpC,MAAM,0BAA0B,GAAG,CAAC,CAAA;AACpC,MAAM,gCAAgC,GAAG,CAAC,CAAA;AAC1C,MAAM,4BAA4B,GAAG,CAAC,CAAA;AAEtC,MAAM,kCAAkC,GAAG,CACzC,IAAkE,EAClE,mBAAuG,EACvG,OAAiB,EACjB,QAAiB,EACjB,QAAQ,GAAG,EAAE,EACb,OAAO,GAAG,KAAK,EACf,EAAE;;IACF,MAAM,UAAU,GAAG,UAAU,CAAA;IAE7B,IAAI,OAAO,GAAG,IAAI,sBAAS,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,CAAC,CAAC,CAAA;IAC9C,IAAI,MAAM,GAAG,IAAI,sBAAS,CAAC,MAAA,IAAI,CAAC,MAAM,mCAAI,CAAC,CAAC,CAAA;IAC5C,IAAI,IAAI,CAAC,YAAY,KAAK,0BAA0B,EAAE;QACpD,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,sBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;KAC9D;SAAM,IAAI,IAAI,CAAC,YAAY,KAAK,4BAA4B,EAAE;QAC7D,OAAO,GAA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AAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,OAAO,GAAG,KAAK,EACf,EAAE,CACF,uCAAuC,CACrC,IAAI,EACJ,mBAAmB,EACnB,IAAI,CAAC,OAAO,EACZ,QAAQ,EACR,QAAQ,EACR,OAAO,CACR;SACJ;QACD,IAAI,EAAE;YACJ;;;;;;eAMG;YACH,eAAe,EAAE,CACf,IAAkE,EAClE,QAAiB,EACjB,EAAE,+DAAC,OAAA,IAAA,gBAAM,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,wCAAwC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA,GAAA;YAC/E;;;;;;eAMG;YACH,2BAA2B,EAAE,CAC3B,IAAkE,EAClE,mBAIoB,EACpB,QAAiB,EACjB,QAAQ,GAAG,EAAE,EACb,OAAO,GAAG,KAAK,EACf,EAAE;gBACF,OAAA,kCAAqB,CAAC,aAAa,CAAC;oBAClC,MAAM,EAAE,MAAM,kCAAkC,CAC9C,IAAI,EACJ,mBAAmB,EACnB,IAAI,CAAC,OAAO,EACZ,QAAQ,EACR,QAAQ,EACR,OAAO,CACR;iBACF,CAAC,CAAA;cAAA;YACJ;;;;;;eAMG;YACH,gCAAgC,EAAE,CAChC,IAA4E,EAC5E,mBAIoB,EACpB,QAAiB,EACjB,QAAQ,GAAG,CAAC,EACZ,OAAO,GAAG,KAAK,EACf,EAAE;gBACF,OAAA,kCAAqB,CAAC,aAAa,CAAC;oBAClC,MAAM,EAAE,MAAM,uCAAuC,CACnD,IAAI,EACJ,mBAAmB,EACnB,IAAI,CAAC,OAAO,EACZ,QAAQ,EACR,QAAQ,EACR,OAAO,CACR;iBACF,CAAC,CAAA;cAAA;SACL;KACF,CAAA;AACH,CAAC,CAAA;AA1IY,QAAA,aAAa,iBA0IzB"}
@@ -0,0 +1,17 @@
1
+ import { CancelablePromise } from '@tatumio/api-client';
2
+ export declare const tronRecord: () => {
3
+ /**
4
+ * Get log record
5
+ * <h4>1 credit per API call.</h4><br/><p>Gets log data from blockchain.</p>
6
+ * @param chain The blockchain to get the log record from
7
+ * @param id ID of the log record / transaction on the blockchain
8
+ * @returns any OK
9
+ * @throws ApiError
10
+ */
11
+ getLog(id: string): CancelablePromise<{
12
+ /**
13
+ * Data stored in the record.
14
+ */
15
+ data: string;
16
+ }>;
17
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronRecord = void 0;
4
+ const api_client_1 = require("@tatumio/api-client");
5
+ const shared_core_1 = require("@tatumio/shared-core");
6
+ const tronRecord = () => {
7
+ return {
8
+ /**
9
+ * Get log record
10
+ * <h4>1 credit per API call.</h4><br/><p>Gets log data from blockchain.</p>
11
+ * @param chain The blockchain to get the log record from
12
+ * @param id ID of the log record / transaction on the blockchain
13
+ * @returns any OK
14
+ * @throws ApiError
15
+ */
16
+ getLog(id) {
17
+ // TODO: Open API bug
18
+ // @ts-ignore
19
+ return api_client_1.BlockchainRecordService.getLog(shared_core_1.Blockchain.TRON, id);
20
+ },
21
+ };
22
+ };
23
+ exports.tronRecord = tronRecord;
24
+ //# sourceMappingURL=tron.record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.record.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.record.ts"],"names":[],"mappings":";;;AAAA,oDAAgF;AAChF,sDAAiD;AAE1C,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,OAAO;QACL;;;;;;;WAOG;QACH,MAAM,CAAC,EAAU;YAMf,qBAAqB;YACrB,aAAa;YACb,OAAO,oCAAuB,CAAC,MAAM,CAAC,wBAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAC5D,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AArBY,QAAA,UAAU,cAqBtB"}
@@ -0,0 +1,39 @@
1
+ import { CreateTronTrc10Blockchain, CreateTronTrc10BlockchainKMS, TransferTronTrc10Blockchain, TransferTronTrc10BlockchainKMS } from '@tatumio/api-client';
2
+ import { ITronWeb } from './tron.web';
3
+ export declare const tronTrc10: (args: {
4
+ tronWeb: ITronWeb;
5
+ }) => {
6
+ prepare: {
7
+ /**
8
+ * Sign Tron TRC10 transaction with private keys locally. Nothing is broadcast to the blockchain.
9
+ * @param testnet mainnet or testnet version
10
+ * @param body content of the transaction to broadcast
11
+ * @param precision
12
+ * @returns transaction data to be broadcast to blockchain.
13
+ */
14
+ signedTransaction: (body: TransferTronTrc10Blockchain | TransferTronTrc10BlockchainKMS, precision?: number, provider?: string) => Promise<string>;
15
+ /**
16
+ * Sign create Tron TRC10 transaction with private keys locally. Nothing is broadcast to the blockchain.
17
+ * @param body content of the transaction to broadcast
18
+ * @returns transaction data to be broadcast to blockchain.
19
+ */
20
+ createSignedTransaction: (body: CreateTronTrc10Blockchain | CreateTronTrc10BlockchainKMS, provider?: string) => Promise<string>;
21
+ };
22
+ send: {
23
+ /**
24
+ * Send Tron TRC10 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
25
+ * This operation is irreversible.
26
+ * @param testnet mainnet or testnet version
27
+ * @param body content of the transaction to broadcast
28
+ * @returns transaction id of the transaction in the blockchain
29
+ */
30
+ signedTransaction: (body: TransferTronTrc10Blockchain | TransferTronTrc10BlockchainKMS, precision?: number, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
31
+ /**
32
+ * Create Tron TRC10 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
33
+ * This operation is irreversible.
34
+ * @param body content of the transaction to broadcast
35
+ * @returns transaction id of the transaction in the blockchain
36
+ */
37
+ createSignedTransaction: (body: CreateTronTrc10Blockchain | CreateTronTrc10BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
38
+ };
39
+ };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronTrc10 = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_client_1 = require("@tatumio/api-client");
6
+ const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
7
+ function isTransferTronTrc10BlockchainKMS(input) {
8
+ return input.signatureId !== undefined;
9
+ }
10
+ const prepareSignedTransaction = (body, tronWeb, precision, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
11
+ const { to, tokenId, amount } = body;
12
+ const client = tronWeb.getClient(provider);
13
+ const definedPrecision = precision !== null && precision !== void 0 ? precision : (yield api_client_1.BlockchainTronService.tronTrc10Detail(Number.parseInt(tokenId))).precision;
14
+ if (!definedPrecision) {
15
+ throw new Error('Unable to obtain precision');
16
+ }
17
+ if (isTransferTronTrc10BlockchainKMS(body)) {
18
+ const tx = yield client.transactionBuilder.sendToken(to, new bignumber_js_1.default(amount).multipliedBy(new bignumber_js_1.default(10).pow(definedPrecision)), tokenId, body.from);
19
+ return JSON.stringify(tx);
20
+ }
21
+ else {
22
+ const tx = yield client.transactionBuilder.sendToken(to, new bignumber_js_1.default(amount).multipliedBy(new bignumber_js_1.default(10).pow(definedPrecision)), tokenId, client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey)));
23
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
24
+ }
25
+ });
26
+ function isCreateTronTrc10BlockchainKMS(input) {
27
+ return input.signatureId !== undefined;
28
+ }
29
+ const prepareCreateSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
30
+ const { name, abbreviation, description, url, totalSupply, decimals } = body;
31
+ const client = tronWeb.getClient(provider);
32
+ const createTokenParams = {
33
+ name,
34
+ abbreviation,
35
+ description,
36
+ url,
37
+ totalSupply: new bignumber_js_1.default(totalSupply).multipliedBy(new bignumber_js_1.default(10).pow(decimals)),
38
+ trxRatio: 1,
39
+ tokenRatio: 1,
40
+ saleStart: Date.now() + 60000,
41
+ saleEnd: Date.now() + 100000,
42
+ freeBandwidth: 0,
43
+ freeBandwidthLimit: 0,
44
+ frozenAmount: 0,
45
+ frozenDuration: 0,
46
+ precision: decimals,
47
+ };
48
+ if (isCreateTronTrc10BlockchainKMS(body)) {
49
+ const tx = yield client.transactionBuilder.createToken(createTokenParams, body.from);
50
+ return JSON.stringify(tx);
51
+ }
52
+ else {
53
+ const tx = yield client.transactionBuilder.createToken(createTokenParams, client.address.fromPrivateKey(body.fromPrivateKey));
54
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
55
+ }
56
+ });
57
+ const tronTrc10 = (args) => {
58
+ return {
59
+ prepare: {
60
+ /**
61
+ * Sign Tron TRC10 transaction with private keys locally. Nothing is broadcast to the blockchain.
62
+ * @param testnet mainnet or testnet version
63
+ * @param body content of the transaction to broadcast
64
+ * @param precision
65
+ * @returns transaction data to be broadcast to blockchain.
66
+ */
67
+ signedTransaction: (body, precision, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareSignedTransaction(body, args.tronWeb, precision, provider); }),
68
+ /**
69
+ * Sign create Tron TRC10 transaction with private keys locally. Nothing is broadcast to the blockchain.
70
+ * @param body content of the transaction to broadcast
71
+ * @returns transaction data to be broadcast to blockchain.
72
+ */
73
+ createSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareCreateSignedTransaction(body, args.tronWeb, provider); }),
74
+ },
75
+ send: {
76
+ /**
77
+ * Send Tron TRC10 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
78
+ * This operation is irreversible.
79
+ * @param testnet mainnet or testnet version
80
+ * @param body content of the transaction to broadcast
81
+ * @returns transaction id of the transaction in the blockchain
82
+ */
83
+ signedTransaction: (body, precision, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
84
+ return api_client_1.BlockchainTronService.tronBroadcast({
85
+ txData: yield prepareSignedTransaction(body, args.tronWeb, precision, provider),
86
+ // TODO: SignatureID is missing in OpenApi
87
+ });
88
+ }),
89
+ /**
90
+ * Create Tron TRC10 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
91
+ * This operation is irreversible.
92
+ * @param body content of the transaction to broadcast
93
+ * @returns transaction id of the transaction in the blockchain
94
+ */
95
+ createSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
96
+ return api_client_1.BlockchainTronService.tronBroadcast({
97
+ txData: yield prepareCreateSignedTransaction(body, args.tronWeb, provider),
98
+ // TODO: SignatureID is missing in OpenApi
99
+ });
100
+ }),
101
+ },
102
+ };
103
+ };
104
+ exports.tronTrc10 = tronTrc10;
105
+ //# sourceMappingURL=tron.trc10.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.trc10.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.trc10.ts"],"names":[],"mappings":";;;;AAAA,oDAM4B;AAC5B,6EAAoC;AAGpC,SAAS,gCAAgC,CACvC,KAAmE;IAEnE,OAAQ,KAAwC,CAAC,WAAW,KAAK,SAAS,CAAA;AAC5E,CAAC;AAED,MAAM,wBAAwB,GAAG,CAC/B,IAAkE,EAClE,OAAiB,EACjB,SAAkB,EAClB,QAAiB,EACjB,EAAE;IACF,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAEpC,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAE1C,MAAM,gBAAgB,GACpB,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,CAAC,MAAM,kCAAqB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEhG,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;IAED,IAAI,gCAAgC,CAAC,IAAI,CAAC,EAAE;QAC1C,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAClD,EAAE,EACF,IAAI,sBAAS,CAAC,MAAM,CA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CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA,GAAA;SAClE;QACD,IAAI,EAAE;YACJ;;;;;;eAMG;YACH,iBAAiB,EAAE,CACjB,IAAkE,EAClE,SAAkB,EAClB,QAAiB,EACjB,EAAE;gBACF,OAAA,kCAAqB,CAAC,aAAa,CAAC;oBAClC,MAAM,EAAE,MAAM,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;oBAC/E,0CAA0C;iBAC3C,CAAC,CAAA;cAAA;YACJ;;;;;eAKG;YACH,uBAAuB,EAAE,CACvB,IAA8D,EAC9D,QAAiB,EACjB,EAAE;gBACF,OAAA,kCAAqB,CAAC,aAAa,CAAC;oBAClC,MAAM,EAAE,MAAM,8BAA8B,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;oBAC1E,0CAA0C;iBAC3C,CAAC,CAAA;cAAA;SACL;KACF,CAAA;AACH,CAAC,CAAA;AA1DY,QAAA,SAAS,aA0DrB"}
@@ -0,0 +1,45 @@
1
+ import { CreateTronTrc20Blockchain, CreateTronTrc20BlockchainKMS, TransferTronTrc20Blockchain, TransferTronTrc20BlockchainKMS } from '@tatumio/api-client';
2
+ import { ITronWeb } from './tron.web';
3
+ export declare const tronTrc20: (args: {
4
+ tronWeb: ITronWeb;
5
+ }) => {
6
+ /**
7
+ * Get TRC20 balance for the given tron address.
8
+ * @param address the address whose balance is returned
9
+ * @param contractAddress the TRC20 contract address
10
+ * @param provider
11
+ */
12
+ getAccountTrc20Address: (address: string, contractAddress: string, provider?: string) => Promise<any>;
13
+ getTrc20ContractDecimals: (contractAddress: string, provider?: string) => Promise<any>;
14
+ prepare: {
15
+ /**
16
+ * Sign create Tron TRC20 transaction with private keys locally. Nothing is broadcast to the blockchain.
17
+ * @param body content of the transaction to broadcast
18
+ * @returns transaction data to be broadcast to blockchain.
19
+ */
20
+ signedTransaction: (body: TransferTronTrc20Blockchain | TransferTronTrc20BlockchainKMS, provider?: string) => Promise<string>;
21
+ /**
22
+ * Prepare create Tron TRC20 transaction for KMS. Nothing is broadcast to the blockchain.
23
+ * @param body content of the transaction to broadcast
24
+ * @param provider
25
+ * @returns transaction data to be broadcast to blockchain.
26
+ */
27
+ createSignedTransaction: (body: CreateTronTrc20Blockchain | CreateTronTrc20BlockchainKMS, provider?: string) => Promise<string>;
28
+ };
29
+ send: {
30
+ /**
31
+ * Send Tron TRC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
32
+ * This operation is irreversible.
33
+ * @param body content of the transaction to broadcast
34
+ * @returns transaction id of the transaction in the blockchain
35
+ */
36
+ signedTransaction: (body: TransferTronTrc20Blockchain | TransferTronTrc20BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
37
+ /**
38
+ * Create Tron TRC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
39
+ * This operation is irreversible.
40
+ * @param body content of the transaction to broadcast
41
+ * @returns transaction id of the transaction in the blockchain
42
+ */
43
+ createSignedTransaction: (body: CreateTronTrc20Blockchain | CreateTronTrc20BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
44
+ };
45
+ };
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronTrc20 = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_client_1 = require("@tatumio/api-client");
6
+ const bignumber_js_1 = (0, tslib_1.__importDefault)(require("bignumber.js"));
7
+ const shared_blockchain_evm_based_1 = require("@tatumio/shared-blockchain-evm-based");
8
+ function isTransferTronTrc20BlockchainKMS(input) {
9
+ return input.signatureId !== undefined;
10
+ }
11
+ const prepareSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
12
+ const { to, tokenAddress, amount, feeLimit } = body;
13
+ const client = tronWeb.getClient(provider);
14
+ client.setAddress(tokenAddress);
15
+ const contractInstance = yield client.contract().at(tokenAddress);
16
+ const decimals = yield contractInstance.decimals().call();
17
+ const tokenAddressHex = client.address.toHex(tokenAddress);
18
+ const methodName = 'transfer(address,uint256)';
19
+ const params = [
20
+ { type: 'address', value: client.address.toHex(to) },
21
+ {
22
+ type: 'uint256',
23
+ value: `0x${new bignumber_js_1.default(amount).multipliedBy(new bignumber_js_1.default(10).pow(decimals)).toString(16)}`,
24
+ },
25
+ ];
26
+ const feeLimitSun = client.toSun(feeLimit);
27
+ if (isTransferTronTrc20BlockchainKMS(body)) {
28
+ const { transaction } = yield client.transactionBuilder.triggerSmartContract(tokenAddressHex, methodName, {
29
+ feeLimit: feeLimitSun,
30
+ from: body.from,
31
+ }, params, body.from);
32
+ return JSON.stringify(transaction);
33
+ }
34
+ else {
35
+ const { transaction } = yield client.transactionBuilder.triggerSmartContract(tokenAddressHex, methodName, {
36
+ feeLimit: feeLimitSun,
37
+ from: client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey)),
38
+ }, params, client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey)));
39
+ return JSON.stringify(yield client.trx.sign(transaction, body.fromPrivateKey));
40
+ }
41
+ });
42
+ function isCreateTronTrc20BlockchainKMS(input) {
43
+ return input.signatureId !== undefined;
44
+ }
45
+ const prepareCreateSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
46
+ const { name, decimals, recipient, symbol, totalSupply } = body;
47
+ const client = tronWeb.getClient(provider);
48
+ const params = {
49
+ feeLimit: 1000000000,
50
+ callValue: 0,
51
+ userFeePercentage: 100,
52
+ originEnergyLimit: 1,
53
+ abi: JSON.stringify(shared_blockchain_evm_based_1.Trc20Token.abi),
54
+ bytecode: shared_blockchain_evm_based_1.Trc20Token.bytecode,
55
+ parameters: [name, symbol, decimals, client.address.toHex(recipient), totalSupply],
56
+ name,
57
+ };
58
+ if (isCreateTronTrc20BlockchainKMS(body)) {
59
+ const tx = yield client.transactionBuilder.createSmartContract(params, body.from);
60
+ return JSON.stringify(tx);
61
+ }
62
+ else {
63
+ const tx = yield client.transactionBuilder.createSmartContract(params, client.address.fromPrivateKey(body.fromPrivateKey));
64
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
65
+ }
66
+ });
67
+ const tronTrc20 = (args) => {
68
+ return {
69
+ // TODO: return any?
70
+ /**
71
+ * Get TRC20 balance for the given tron address.
72
+ * @param address the address whose balance is returned
73
+ * @param contractAddress the TRC20 contract address
74
+ * @param provider
75
+ */
76
+ getAccountTrc20Address: (address, contractAddress, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
77
+ const client = args.tronWeb.getClient(provider);
78
+ client.setAddress(contractAddress);
79
+ const contractInstance = yield client.contract().at(contractAddress);
80
+ return contractInstance.balanceOf(address).call();
81
+ }),
82
+ // TODO: return any?
83
+ getTrc20ContractDecimals: (contractAddress, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
84
+ const client = args.tronWeb.getClient(provider);
85
+ client.setAddress(contractAddress);
86
+ const contractInstance = yield client.contract().at(contractAddress);
87
+ return contractInstance.decimals().call();
88
+ }),
89
+ prepare: {
90
+ /**
91
+ * Sign create Tron TRC20 transaction with private keys locally. Nothing is broadcast to the blockchain.
92
+ * @param body content of the transaction to broadcast
93
+ * @returns transaction data to be broadcast to blockchain.
94
+ */
95
+ signedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareSignedTransaction(body, args.tronWeb, provider); }),
96
+ /**
97
+ * Prepare create Tron TRC20 transaction for KMS. Nothing is broadcast to the blockchain.
98
+ * @param body content of the transaction to broadcast
99
+ * @param provider
100
+ * @returns transaction data to be broadcast to blockchain.
101
+ */
102
+ createSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareCreateSignedTransaction(body, args.tronWeb, provider); }),
103
+ },
104
+ send: {
105
+ /**
106
+ * Send Tron TRC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
107
+ * This operation is irreversible.
108
+ * @param body content of the transaction to broadcast
109
+ * @returns transaction id of the transaction in the blockchain
110
+ */
111
+ signedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
112
+ return api_client_1.BlockchainTronService.tronBroadcast({
113
+ txData: yield prepareSignedTransaction(body, args.tronWeb, provider),
114
+ // TODO: SignatureID is missing in OpenApi
115
+ });
116
+ }),
117
+ /**
118
+ * Create Tron TRC20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
119
+ * This operation is irreversible.
120
+ * @param body content of the transaction to broadcast
121
+ * @returns transaction id of the transaction in the blockchain
122
+ */
123
+ createSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
124
+ return api_client_1.BlockchainTronService.tronBroadcast({
125
+ txData: yield prepareCreateSignedTransaction(body, args.tronWeb, provider),
126
+ // TODO: SignatureID is missing in OpenApi
127
+ });
128
+ }),
129
+ },
130
+ };
131
+ };
132
+ exports.tronTrc20 = tronTrc20;
133
+ //# sourceMappingURL=tron.trc20.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.trc20.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.trc20.ts"],"names":[],"mappings":";;;;AAAA,oDAM4B;AAC5B,6EAAoC;AAEpC,sFAAiE;AAEjE,SAAS,gCAAgC,CACvC,KAAmE;IAEnE,OAAQ,KAAwC,CAAC,WAAW,KAAK,SAAS,CAAA;AAC5E,CAAC;AAED,MAAM,wBAAwB,GAAG,CAC/B,IAAkE,EAClE,OAAiB,EACjB,QAAiB,EACjB,EAAE;IACF,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IAEnD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAC1C,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;IAC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