@recoillink/tron-sdk 0.0.0-stage → 26.0.1
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/LICENSE.md +193 -0
- package/README.md +44 -2
- package/dist/clients/protocol.d.ts +27 -0
- package/dist/clients/protocol.d.ts.map +1 -0
- package/dist/clients/protocol.js +53 -0
- package/dist/clients/protocol.js.map +1 -0
- package/dist/clients/provider.d.ts +30 -0
- package/dist/clients/provider.d.ts.map +1 -0
- package/dist/clients/provider.js +268 -0
- package/dist/clients/provider.js.map +1 -0
- package/dist/clients/signer.d.ts +16 -0
- package/dist/clients/signer.d.ts.map +1 -0
- package/dist/clients/signer.js +38 -0
- package/dist/clients/signer.js.map +1 -0
- package/dist/ethers/TronContractFactory.d.ts +32 -0
- package/dist/ethers/TronContractFactory.d.ts.map +1 -0
- package/dist/ethers/TronContractFactory.js +54 -0
- package/dist/ethers/TronContractFactory.js.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.d.ts +74 -0
- package/dist/ethers/TronJsonRpcProvider.d.ts.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.integration.test.d.ts +2 -0
- package/dist/ethers/TronJsonRpcProvider.integration.test.d.ts.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.integration.test.js +46 -0
- package/dist/ethers/TronJsonRpcProvider.integration.test.js.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.js +261 -0
- package/dist/ethers/TronJsonRpcProvider.js.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.test.d.ts +2 -0
- package/dist/ethers/TronJsonRpcProvider.test.d.ts.map +1 -0
- package/dist/ethers/TronJsonRpcProvider.test.js +336 -0
- package/dist/ethers/TronJsonRpcProvider.test.js.map +1 -0
- package/dist/ethers/TronWallet.d.ts +69 -0
- package/dist/ethers/TronWallet.d.ts.map +1 -0
- package/dist/ethers/TronWallet.integration.test.d.ts +2 -0
- package/dist/ethers/TronWallet.integration.test.d.ts.map +1 -0
- package/dist/ethers/TronWallet.integration.test.js +151 -0
- package/dist/ethers/TronWallet.integration.test.js.map +1 -0
- package/dist/ethers/TronWallet.js +295 -0
- package/dist/ethers/TronWallet.js.map +1 -0
- package/dist/ethers/TronWallet.test.d.ts +2 -0
- package/dist/ethers/TronWallet.test.d.ts.map +1 -0
- package/dist/ethers/TronWallet.test.js +216 -0
- package/dist/ethers/TronWallet.test.js.map +1 -0
- package/dist/ethers/index.d.ts +4 -0
- package/dist/ethers/index.d.ts.map +1 -0
- package/dist/ethers/index.js +4 -0
- package/dist/ethers/index.js.map +1 -0
- package/dist/ethers/urlUtils.d.ts +32 -0
- package/dist/ethers/urlUtils.d.ts.map +1 -0
- package/dist/ethers/urlUtils.js +67 -0
- package/dist/ethers/urlUtils.js.map +1 -0
- package/dist/ethers/urlUtils.test.d.ts +2 -0
- package/dist/ethers/urlUtils.test.d.ts.map +1 -0
- package/dist/ethers/urlUtils.test.js +106 -0
- package/dist/ethers/urlUtils.test.js.map +1 -0
- package/dist/factories/index.d.ts +2 -0
- package/dist/factories/index.d.ts.map +1 -0
- package/dist/factories/index.js +8 -0
- package/dist/factories/index.js.map +1 -0
- package/dist/hook/hook-query.d.ts +41 -0
- package/dist/hook/hook-query.d.ts.map +1 -0
- package/dist/hook/hook-query.js +79 -0
- package/dist/hook/hook-query.js.map +1 -0
- package/dist/hook/hook-tx.d.ts +39 -0
- package/dist/hook/hook-tx.d.ts.map +1 -0
- package/dist/hook/hook-tx.js +95 -0
- package/dist/hook/hook-tx.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/ism/ism-query.d.ts +70 -0
- package/dist/ism/ism-query.d.ts.map +1 -0
- package/dist/ism/ism-query.js +137 -0
- package/dist/ism/ism-query.js.map +1 -0
- package/dist/ism/ism-tx.d.ts +67 -0
- package/dist/ism/ism-tx.d.ts.map +1 -0
- package/dist/ism/ism-tx.js +110 -0
- package/dist/ism/ism-tx.js.map +1 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +6 -0
- package/dist/runtime.js.map +1 -0
- package/dist/testing/constants.d.ts +7 -0
- package/dist/testing/constants.d.ts.map +1 -0
- package/dist/testing/constants.js +7 -0
- package/dist/testing/constants.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/node.d.ts +41 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +119 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/utils/index.d.ts +68 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +141 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.test.d.ts +2 -0
- package/dist/utils/index.test.d.ts.map +1 -0
- package/dist/utils/index.test.js +85 -0
- package/dist/utils/index.test.js.map +1 -0
- package/dist/utils/types.d.ts +94 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +13 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +74 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/clients/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEjD,OAAO,EACL,oBAAoB,GAErB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,QAAQ,MAAM,oFAAoF,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChI,OAAO,YAAY,MAAM,wEAAwE,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;A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C;YACD,SAAS,CAAC;gBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,GAAiC;QAEjC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,gDAAgD,CAAC,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,6CAA6C,CAAC,CAAC;QAElE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;QAE3E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,QAAQ;aAC9B,mBAAmB,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC;aACvE,IAAI,EAAE,CAAC;QAEV,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,OAAO;gBACL,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;aAClB,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAE5D,OAAO;YACL,KAAK,EAAE,KAAK,KAAK,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK;YAChD,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;SACzB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TronWeb } from 'tronweb';
|
|
2
|
+
import { AltVM } from '@recoillink/provider-sdk';
|
|
3
|
+
import type { ChainMetadataForAltVM } from '@recoillink/provider-sdk/chain';
|
|
4
|
+
import { TronReceipt, TronTransaction } from '../utils/types.js';
|
|
5
|
+
import { TronProvider } from './provider.js';
|
|
6
|
+
export declare class TronSigner extends TronProvider implements AltVM.ISigner<TronTransaction, TronReceipt> {
|
|
7
|
+
static connectWithSigner(metadata: ChainMetadataForAltVM, privateKey: string): Promise<TronSigner>;
|
|
8
|
+
protected constructor(rpcUrls: [string, ...string[]], chainMetadata: ChainMetadataForAltVM, privateKey: string);
|
|
9
|
+
getSignerAddress(): string;
|
|
10
|
+
getTronweb(): TronWeb;
|
|
11
|
+
supportsTransactionBatching(): boolean;
|
|
12
|
+
transactionToPrintableJson(transaction: TronTransaction): Promise<object>;
|
|
13
|
+
sendAndConfirmTransaction(transaction: TronTransaction): Promise<TronReceipt>;
|
|
14
|
+
sendAndConfirmBatchTransactions(_transactions: TronTransaction[]): Promise<TronReceipt>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/clients/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,qBAAa,UACX,SAAQ,YACR,YAAW,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,WAAW,CAAC;IAEtD,OAAa,iBAAiB,CAC5B,QAAQ,EAAE,qBAAqB,EAC/B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CAMrB;IAED,SAAS,aACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAC9B,aAAa,EAAE,qBAAqB,EACpC,UAAU,EAAE,MAAM,EAGnB;IAED,gBAAgB,IAAI,MAAM,CAEzB;IAED,UAAU,IAAI,OAAO,CAEpB;IAED,2BAA2B,IAAI,OAAO,CAErC;IAEK,0BAA0B,CAC9B,WAAW,EAAE,eAAe,GAC3B,OAAO,CAAC,MAAM,CAAC,CAEjB;IAEK,yBAAyB,CAC7B,WAAW,EAAE,eAAe,GAC3B,OAAO,CAAC,WAAW,CAAC,CAatB;IAEK,+BAA+B,CACnC,aAAa,EAAE,eAAe,EAAE,GAC/B,OAAO,CAAC,WAAW,CAAC,CAEtB;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { assert } from '@recoillink/utils';
|
|
2
|
+
import { TronProvider } from './provider.js';
|
|
3
|
+
export class TronSigner extends TronProvider {
|
|
4
|
+
static async connectWithSigner(metadata, privateKey) {
|
|
5
|
+
const rpcUrls = (metadata.rpcUrls ?? []).map((rpc) => rpc.http);
|
|
6
|
+
const [rpcUrl, ...otherRpcUrls] = rpcUrls;
|
|
7
|
+
assert(rpcUrl, `got no rpcUrls`);
|
|
8
|
+
return new TronSigner([rpcUrl, ...otherRpcUrls], metadata, privateKey);
|
|
9
|
+
}
|
|
10
|
+
constructor(rpcUrls, chainMetadata, privateKey) {
|
|
11
|
+
super(rpcUrls, chainMetadata, privateKey);
|
|
12
|
+
}
|
|
13
|
+
getSignerAddress() {
|
|
14
|
+
return this.tronweb.defaultAddress.base58 || '';
|
|
15
|
+
}
|
|
16
|
+
getTronweb() {
|
|
17
|
+
return this.tronweb;
|
|
18
|
+
}
|
|
19
|
+
supportsTransactionBatching() {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
async transactionToPrintableJson(transaction) {
|
|
23
|
+
return transaction;
|
|
24
|
+
}
|
|
25
|
+
async sendAndConfirmTransaction(transaction) {
|
|
26
|
+
const signedTx = await this.tronweb.trx.sign(transaction);
|
|
27
|
+
const result = await this.tronweb.trx.sendRawTransaction(signedTx);
|
|
28
|
+
if (!result?.result || !result.txid) {
|
|
29
|
+
throw new Error(`Failed to broadcast transaction: ${result.code ?? result.message ?? 'unknown error'}`);
|
|
30
|
+
}
|
|
31
|
+
const receipt = await this.waitForTransaction(result.txid);
|
|
32
|
+
return receipt;
|
|
33
|
+
}
|
|
34
|
+
async sendAndConfirmBatchTransactions(_transactions) {
|
|
35
|
+
throw new Error(`${TronSigner.name} does not support transaction batching`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/clients/signer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,OAAO,UACX,SAAQ,YAAY;IAGpB,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAC5B,QAA+B,EAC/B,UAAkB;QAElB,MAAM,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC;QAC1C,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAEjC,OAAO,IAAI,UAAU,CAAC,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACzE,CAAC;IAED,YACE,OAA8B,EAC9B,aAAoC,EACpC,UAAkB;QAElB,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,IAAI,EAAE,CAAC;IAClD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,2BAA2B;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,0BAA0B,CAC9B,WAA4B;QAE5B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,yBAAyB,CAC7B,WAA4B;QAE5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAEnE,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,oCAAoC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,IAAI,eAAe,EAAE,CACvF,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE3D,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,+BAA+B,CACnC,aAAgC;QAEhC,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,wCAAwC,CAAC,CAAC;IAC9E,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ContractFactory } from 'ethers';
|
|
2
|
+
import { TronWallet } from './TronWallet.js';
|
|
3
|
+
/**
|
|
4
|
+
* TronContractFactory wraps a ContractFactory to handle Tron's deployment flow
|
|
5
|
+
* where contract addresses come from TronWeb rather than being predictable via nonce.
|
|
6
|
+
*
|
|
7
|
+
* This class overrides deploy() to extract the correct contract address from the
|
|
8
|
+
* Tron transaction response, since ethers computes the wrong address using
|
|
9
|
+
* Ethereum's CREATE formula.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```ts
|
|
13
|
+
* const factory = new TronContractFactory(new Mailbox__factory(), tronWallet);
|
|
14
|
+
* const contract = await factory.deploy(localDomain);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class TronContractFactory<F extends ContractFactory> extends ContractFactory {
|
|
18
|
+
private readonly factory;
|
|
19
|
+
constructor(factory: F, signer?: TronWallet);
|
|
20
|
+
/**
|
|
21
|
+
* Deploy a contract and return the connected contract instance.
|
|
22
|
+
*
|
|
23
|
+
* Uses the typed CreateSmartContractTransaction from TronWeb to get
|
|
24
|
+
* the contract address directly from the transaction response.
|
|
25
|
+
*/
|
|
26
|
+
deploy(...args: Parameters<F['deploy']>): Promise<Awaited<ReturnType<F['deploy']>>>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a new TronContractFactory connected to the given signer.
|
|
29
|
+
*/
|
|
30
|
+
connect(signer: TronWallet): TronContractFactory<F>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=TronContractFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronContractFactory.d.ts","sourceRoot":"","sources":["../../src/ethers/TronContractFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAKzC,OAAO,EAA2B,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAWtE;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAmB,CAC9B,CAAC,SAAS,eAAe,CACzB,SAAQ,eAAe;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAD1B,YACmB,OAAO,EAAE,CAAC,EAC3B,MAAM,CAAC,EAAE,UAAU,EAGpB;IAED;;;;;OAKG;IACY,MAAM,CACnB,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAoB3C;IAED;;OAEG;IACM,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAE3D;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ContractFactory } from 'ethers';
|
|
2
|
+
import { assert } from '@recoillink/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for CreateSmartContractTransaction
|
|
5
|
+
*/
|
|
6
|
+
function isDeployTransaction(tx) {
|
|
7
|
+
return 'contract_address' in tx;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* TronContractFactory wraps a ContractFactory to handle Tron's deployment flow
|
|
11
|
+
* where contract addresses come from TronWeb rather than being predictable via nonce.
|
|
12
|
+
*
|
|
13
|
+
* This class overrides deploy() to extract the correct contract address from the
|
|
14
|
+
* Tron transaction response, since ethers computes the wrong address using
|
|
15
|
+
* Ethereum's CREATE formula.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const factory = new TronContractFactory(new Mailbox__factory(), tronWallet);
|
|
20
|
+
* const contract = await factory.deploy(localDomain);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class TronContractFactory extends ContractFactory {
|
|
24
|
+
factory;
|
|
25
|
+
constructor(factory, signer) {
|
|
26
|
+
super(factory.interface, factory.bytecode, signer);
|
|
27
|
+
this.factory = factory;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Deploy a contract and return the connected contract instance.
|
|
31
|
+
*
|
|
32
|
+
* Uses the typed CreateSmartContractTransaction from TronWeb to get
|
|
33
|
+
* the contract address directly from the transaction response.
|
|
34
|
+
*/
|
|
35
|
+
async deploy(...args) {
|
|
36
|
+
const contract = await super.deploy(...args);
|
|
37
|
+
const { tronTransaction } = contract.deployTransaction;
|
|
38
|
+
assert(isDeployTransaction(tronTransaction), 'Expected CreateSmartContractTransaction for deployment');
|
|
39
|
+
const tronWallet = this.signer;
|
|
40
|
+
const evmAddress = tronWallet.toEvmAddress(tronTransaction.contract_address);
|
|
41
|
+
// Re-attach to correct address, preserving deployTransaction
|
|
42
|
+
const deployTransaction = contract.deployTransaction;
|
|
43
|
+
const correctedContract = this.attach(evmAddress);
|
|
44
|
+
correctedContract.deployTransaction = deployTransaction;
|
|
45
|
+
return correctedContract;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a new TronContractFactory connected to the given signer.
|
|
49
|
+
*/
|
|
50
|
+
connect(signer) {
|
|
51
|
+
return new TronContractFactory(this.factory, signer);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=TronContractFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronContractFactory.js","sourceRoot":"","sources":["../../src/ethers/TronContractFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C;;GAEG;AACH,SAAS,mBAAmB,CAC1B,EAA8C;IAE9C,OAAO,kBAAkB,IAAI,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,mBAEX,SAAQ,eAAe;IAEJ,OAAO;IAD1B,YACmB,OAAU,EAC3B,MAAmB;QAEnB,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;uBAHlC,OAAO;IAI1B,CAAC;IAED;;;;;OAKG;IACM,KAAK,CAAC,MAAM,CACnB,GAAG,IAA6B;QAEhC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAC7C,MAAM,EAAE,eAAe,EAAE,GACvB,QAAQ,CAAC,iBAA4C,CAAC;QAExD,MAAM,CACJ,mBAAmB,CAAC,eAAe,CAAC,EACpC,wDAAwD,CACzD,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,MAAoB,CAAC;QAC7C,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CACxC,eAAe,CAAC,gBAAgB,CACjC,CAAC;QAEF,6DAA6D;QAC7D,MAAM,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;QACrD,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,iBAAyB,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QACjE,OAAO,iBAAqD,CAAC;IAC/D,CAAC;IAED;;OAEG;IACM,OAAO,CAAC,MAAkB;QACjC,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { BigNumber, providers } from 'ethers';
|
|
2
|
+
/** TronWeb's maximum allowed originEnergyLimit for contract creation. */
|
|
3
|
+
export declare const MAX_TRON_ORIGIN_ENERGY_LIMIT = 10000000;
|
|
4
|
+
/**
|
|
5
|
+
* TronJsonRpcProvider extends ethers JsonRpcProvider for Tron's JSON-RPC API.
|
|
6
|
+
*
|
|
7
|
+
* Tron's JSON-RPC endpoint supports most standard Ethereum JSON-RPC methods,
|
|
8
|
+
* but with a few notable exceptions:
|
|
9
|
+
* - eth_sendRawTransaction: Not supported (must use TronWeb for transactions)
|
|
10
|
+
* - eth_getTransactionCount: Not supported (Tron doesn't use nonces)
|
|
11
|
+
*
|
|
12
|
+
* This provider handles these gaps by returning appropriate defaults
|
|
13
|
+
* and wraps all RPC calls with retry logic to handle transient errors
|
|
14
|
+
* (e.g. TronGrid rate limiting).
|
|
15
|
+
*/
|
|
16
|
+
export declare class TronJsonRpcProvider extends providers.StaticJsonRpcProvider {
|
|
17
|
+
host: string;
|
|
18
|
+
private maxRetries;
|
|
19
|
+
private baseRetryMs;
|
|
20
|
+
private tronWeb;
|
|
21
|
+
constructor(host: string, network?: providers.Networkish, maxRetries?: number, baseRetryMs?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Override network detection to handle Tron nodes that don't support eth_chainId.
|
|
24
|
+
* Falls back to a default network if detection fails.
|
|
25
|
+
*/
|
|
26
|
+
detectNetwork(): Promise<providers.Network>;
|
|
27
|
+
/**
|
|
28
|
+
* Wraps all RPC calls with retry logic to handle transient
|
|
29
|
+
* errors like 503s from TronGrid rate limiting.
|
|
30
|
+
*/
|
|
31
|
+
perform(method: string, params: any): Promise<any>;
|
|
32
|
+
private callContract;
|
|
33
|
+
/**
|
|
34
|
+
* Tron's eth_estimateGas is unreliable — it rejects contract creation (no `to` field)
|
|
35
|
+
* and often returns "method parameters invalid" for contract calls.
|
|
36
|
+
* Return a default gas limit since Tron uses feeLimit (not gasLimit) for execution,
|
|
37
|
+
* and TronWallet.buildTransaction caps feeLimit at 1000 TRX anyway.
|
|
38
|
+
*/
|
|
39
|
+
estimateGas(_transaction: providers.TransactionRequest): Promise<BigNumber>;
|
|
40
|
+
/**
|
|
41
|
+
* Tron doesn't use nonces - always return 0.
|
|
42
|
+
*
|
|
43
|
+
* This is a nonce accessor, not a liveness signal: a live Tron account still
|
|
44
|
+
* reports 0 here. Use {@link isAccountActive} to test whether an account
|
|
45
|
+
* exists on-chain.
|
|
46
|
+
*/
|
|
47
|
+
getTransactionCount(_addressOrName: string, _blockTag?: providers.BlockTag): Promise<number>;
|
|
48
|
+
/**
|
|
49
|
+
* Whether an address has been activated on-chain.
|
|
50
|
+
*
|
|
51
|
+
* Tron accounts must be activated before they exist, and there are no nonces,
|
|
52
|
+
* so activation is read from the native account endpoint rather than inferred
|
|
53
|
+
* from `getTransactionCount` (which is hardcoded to 0, see above). An address
|
|
54
|
+
* that was never activated answers HTTP 200 with an empty object.
|
|
55
|
+
*
|
|
56
|
+
* Presence is deliberately keyed off the response being non-empty rather than
|
|
57
|
+
* off `create_time`: contract accounts omit `create_time` entirely, so keying
|
|
58
|
+
* off it would report every Tron contract inactive.
|
|
59
|
+
*
|
|
60
|
+
* Transport failures propagate. A node we cannot reach is not evidence that
|
|
61
|
+
* an account is missing, and callers gate destructive/reporting decisions on
|
|
62
|
+
* this answer.
|
|
63
|
+
*/
|
|
64
|
+
isAccountActive(address: string): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Tron doesn't support ENS - return the name as-is.
|
|
67
|
+
*/
|
|
68
|
+
resolveName(name: string): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Return legacy gas pricing only - Tron doesn't support EIP-1559.
|
|
71
|
+
*/
|
|
72
|
+
getFeeData(): Promise<providers.FeeData>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=TronJsonRpcProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronJsonRpcProvider.d.ts","sourceRoot":"","sources":["../../src/ethers/TronJsonRpcProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAS,MAAM,QAAQ,CAAC;AAuCrD,yEAAyE;AACzE,eAAO,MAAM,4BAA4B,WAAa,CAAC;AA6EvD;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAAC,qBAAqB;IAC/D,IAAI,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAU;IAEzB,YACE,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,SAAS,CAAC,UAAU,EAC9B,UAAU,SAAsB,EAChC,WAAW,SAAwB,EAYpC;IAED;;;OAGG;IACY,aAAa,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAQzD;IAED;;;OAGG;IACY,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CA4BhE;YAEa,YAAY;IAiE1B;;;;;OAKG;IACY,WAAW,CACxB,YAAY,EAAE,SAAS,CAAC,kBAAkB,GACzC,OAAO,CAAC,SAAS,CAAC,CAOpB;IAED;;;;;;OAMG;IACY,mBAAmB,CAChC,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,SAAS,CAAC,QAAQ,GAC7B,OAAO,CAAC,MAAM,CAAC,CAEjB;IAED;;;;;;;;;;;;;;;OAeG;IACG,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BvD;IAED;;OAEG;IACY,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAExD;IAED;;OAEG;IACY,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAQtD;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronJsonRpcProvider.integration.test.d.ts","sourceRoot":"","sources":["../../src/ethers/TronJsonRpcProvider.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { TronWeb } from 'tronweb';
|
|
3
|
+
import { assert, ensure0x, strip0x } from '@recoillink/utils';
|
|
4
|
+
import { runTronNode, stopTronNode, } from '../testing/node.js';
|
|
5
|
+
import { TronJsonRpcProvider } from './TronJsonRpcProvider.js';
|
|
6
|
+
const TEST_CHAIN = {
|
|
7
|
+
name: 'tron-test-account',
|
|
8
|
+
chainId: 3360022319,
|
|
9
|
+
domainId: 3360022319,
|
|
10
|
+
port: 19091,
|
|
11
|
+
};
|
|
12
|
+
// Never funded by TRE, so the node has no account record for it.
|
|
13
|
+
const UNACTIVATED_ADDRESS = '0xa7eccdb9be08178f896c26b7bbd8c3d4e844d9ba';
|
|
14
|
+
describe('TronJsonRpcProvider Integration Tests', function () {
|
|
15
|
+
this.timeout(120_000);
|
|
16
|
+
let node;
|
|
17
|
+
let provider;
|
|
18
|
+
let fundedAddress;
|
|
19
|
+
before(async () => {
|
|
20
|
+
node = await runTronNode(TEST_CHAIN);
|
|
21
|
+
const host = `http://127.0.0.1:${TEST_CHAIN.port}`;
|
|
22
|
+
provider = new TronJsonRpcProvider(`${host}/jsonrpc`, TEST_CHAIN.chainId);
|
|
23
|
+
const tronWeb = new TronWeb({ fullHost: host });
|
|
24
|
+
const privateKey = node.privateKeys[0];
|
|
25
|
+
assert(privateKey, 'TRE did not expose a funded private key');
|
|
26
|
+
const base58 = tronWeb.address.fromPrivateKey(privateKey);
|
|
27
|
+
assert(base58, 'TRE did not expose a funded account');
|
|
28
|
+
// TronWeb hex is 41-prefixed; the provider is fed the 0x form production uses.
|
|
29
|
+
fundedAddress = ensure0x(strip0x(tronWeb.address.toHex(base58)).slice(2));
|
|
30
|
+
});
|
|
31
|
+
after(async () => {
|
|
32
|
+
await stopTronNode(node);
|
|
33
|
+
});
|
|
34
|
+
describe('isAccountActive', () => {
|
|
35
|
+
it('returns true for an activated (funded) account', async () => {
|
|
36
|
+
expect(await provider.isAccountActive(fundedAddress)).to.be.true;
|
|
37
|
+
});
|
|
38
|
+
it('returns false for an address that was never activated', async () => {
|
|
39
|
+
expect(await provider.isAccountActive(UNACTIVATED_ADDRESS)).to.be.false;
|
|
40
|
+
});
|
|
41
|
+
it('still reports a zero nonce for the activated account', async () => {
|
|
42
|
+
expect(await provider.getTransactionCount(fundedAddress)).to.equal(0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=TronJsonRpcProvider.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronJsonRpcProvider.integration.test.js","sourceRoot":"","sources":["../../src/ethers/TronJsonRpcProvider.integration.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,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CAAC;IAEH,KAAK,CAAC,KAAK,IAAI,EAAE;QACf,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,CAAC,MAAM,QAAQ,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACnE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;YACrE,MAAM,CAAC,MAAM,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAC1E,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;YACpE,MAAM,CAAC,MAAM,QAAQ,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { BigNumber, providers, utils } from 'ethers';
|
|
2
|
+
import { TronWeb } from 'tronweb';
|
|
3
|
+
import { ensure0x, isNullish, retryAsync } from '@recoillink/utils';
|
|
4
|
+
import { buildTronTriggerRequest, toTronHex } from '../utils/index.js';
|
|
5
|
+
import { stripCustomRpcHeaders, toHttpApiUrl } from './urlUtils.js';
|
|
6
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
7
|
+
const DEFAULT_BASE_RETRY_MS = 250;
|
|
8
|
+
/** Raw full-node account-lookup endpoint. */
|
|
9
|
+
const TRON_GET_ACCOUNT_PATH = 'wallet/getaccount';
|
|
10
|
+
/** TronWeb's maximum allowed originEnergyLimit for contract creation. */
|
|
11
|
+
export const MAX_TRON_ORIGIN_ENERGY_LIMIT = 10_000_000;
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === 'object' && !isNullish(value);
|
|
14
|
+
}
|
|
15
|
+
/** Standard EVM/JSON-RPC "execution reverted" error code. */
|
|
16
|
+
const JSON_RPC_REVERT_CODE = 3;
|
|
17
|
+
/**
|
|
18
|
+
* Shapes native constant-call reverts as ethers CALL_EXCEPTION errors so the
|
|
19
|
+
* SDK's missing-selector detection (see @recoillink/sdk contract utils)
|
|
20
|
+
* recognizes them exactly as it would an eth_call revert.
|
|
21
|
+
*/
|
|
22
|
+
const callExceptionLogger = new utils.Logger('tron-sdk');
|
|
23
|
+
function nextInChain(node) {
|
|
24
|
+
return node['error'] ?? node['cause'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True for ethers' synthetic top-level CALL_EXCEPTION wrapper. For the `call`
|
|
28
|
+
* method, @ethersproject/providers `checkError` wraps EVERY failed eth_call —
|
|
29
|
+
* genuine reverts AND transport failures alike — into a CALL_EXCEPTION carrying
|
|
30
|
+
* `data: "0x"` and the generic reason "missing revert data in call exception",
|
|
31
|
+
* nesting the original error under `.error`. Both cases share this wrapper, so
|
|
32
|
+
* it cannot itself distinguish a revert from a 503 and must be skipped when
|
|
33
|
+
* classifying; the truth lives in the nested original error.
|
|
34
|
+
*/
|
|
35
|
+
function isSyntheticCallExceptionWrapper(node) {
|
|
36
|
+
return (node['code'] === utils.Logger.errors.CALL_EXCEPTION &&
|
|
37
|
+
typeof node['message'] === 'string' &&
|
|
38
|
+
node['message'].includes('missing revert data in call exception'));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* True when the error chain positively indicates the VM executed and reverted
|
|
42
|
+
* (including the reasonless / missing-selector case). A reasonless Tron revert
|
|
43
|
+
* surfaces as ethers' CALL_EXCEPTION wrapper over a nested SERVER_ERROR whose
|
|
44
|
+
* message carries "execution reverted" — the SAME code shape as a real 503, so
|
|
45
|
+
* a transport-code scan alone cannot tell them apart. We therefore detect a
|
|
46
|
+
* revert positively, skipping the synthetic wrapper, via any of: a revert
|
|
47
|
+
* message, the JSON-RPC revert code, or non-synthetic hex return data. A revert
|
|
48
|
+
* is re-thrown so the SDK's missing-selector detection sees the CALL_EXCEPTION
|
|
49
|
+
* and JSON-RPC-only proxies never touch the native endpoint.
|
|
50
|
+
*/
|
|
51
|
+
function isRevertError(error) {
|
|
52
|
+
let current = error;
|
|
53
|
+
while (isRecord(current)) {
|
|
54
|
+
if (!isSyntheticCallExceptionWrapper(current)) {
|
|
55
|
+
const messages = [
|
|
56
|
+
current['message'],
|
|
57
|
+
current['reason'],
|
|
58
|
+
current['body'],
|
|
59
|
+
].filter((value) => typeof value === 'string');
|
|
60
|
+
if (messages.some((value) => /revert/i.test(value))) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (current['code'] === JSON_RPC_REVERT_CODE) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (typeof current['data'] === 'string' &&
|
|
67
|
+
current['data'].startsWith('0x')) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
current = nextInChain(current);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* TronJsonRpcProvider extends ethers JsonRpcProvider for Tron's JSON-RPC API.
|
|
77
|
+
*
|
|
78
|
+
* Tron's JSON-RPC endpoint supports most standard Ethereum JSON-RPC methods,
|
|
79
|
+
* but with a few notable exceptions:
|
|
80
|
+
* - eth_sendRawTransaction: Not supported (must use TronWeb for transactions)
|
|
81
|
+
* - eth_getTransactionCount: Not supported (Tron doesn't use nonces)
|
|
82
|
+
*
|
|
83
|
+
* This provider handles these gaps by returning appropriate defaults
|
|
84
|
+
* and wraps all RPC calls with retry logic to handle transient errors
|
|
85
|
+
* (e.g. TronGrid rate limiting).
|
|
86
|
+
*/
|
|
87
|
+
export class TronJsonRpcProvider extends providers.StaticJsonRpcProvider {
|
|
88
|
+
host;
|
|
89
|
+
maxRetries;
|
|
90
|
+
baseRetryMs;
|
|
91
|
+
tronWeb;
|
|
92
|
+
constructor(host, network, maxRetries = DEFAULT_MAX_RETRIES, baseRetryMs = DEFAULT_BASE_RETRY_MS) {
|
|
93
|
+
const { url: cleanUrl, headers } = stripCustomRpcHeaders(host);
|
|
94
|
+
const hasHeaders = Object.keys(headers).length > 0;
|
|
95
|
+
super(hasHeaders ? { url: cleanUrl, headers } : cleanUrl, network);
|
|
96
|
+
this.host = host;
|
|
97
|
+
this.maxRetries = maxRetries;
|
|
98
|
+
this.baseRetryMs = baseRetryMs;
|
|
99
|
+
this.tronWeb = new TronWeb({
|
|
100
|
+
fullHost: toHttpApiUrl(host),
|
|
101
|
+
headers,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Override network detection to handle Tron nodes that don't support eth_chainId.
|
|
106
|
+
* Falls back to a default network if detection fails.
|
|
107
|
+
*/
|
|
108
|
+
async detectNetwork() {
|
|
109
|
+
try {
|
|
110
|
+
return await super.detectNetwork();
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// TRE/TronGrid may not support eth_chainId reliably.
|
|
114
|
+
// Return a default network to avoid blocking all RPC calls.
|
|
115
|
+
return { name: 'tron', chainId: 728126428 };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wraps all RPC calls with retry logic to handle transient
|
|
120
|
+
* errors like 503s from TronGrid rate limiting.
|
|
121
|
+
*/
|
|
122
|
+
async perform(method, params) {
|
|
123
|
+
const performWithRetry = () => retryAsync(() => super.perform(method, params), this.maxRetries, this.baseRetryMs);
|
|
124
|
+
// Contract reads are eth_call-first: standard JSON-RPC lets ethers surface
|
|
125
|
+
// reverts as CALL_EXCEPTION (which the SDK's missing-selector detection
|
|
126
|
+
// recognizes) and keeps JSON-RPC-only proxies working, since a re-thrown
|
|
127
|
+
// revert never touches the native endpoint. A positively-detected revert is
|
|
128
|
+
// re-thrown; ANY other failure — a transport error (503/timeout) or a node
|
|
129
|
+
// that simply doesn't answer eth_call (e.g. -32601) — falls back to the raw
|
|
130
|
+
// constant-call endpoint (see callContract), as used by public RPCs like
|
|
131
|
+
// TronGrid and Alchemy.
|
|
132
|
+
if (method === 'call' && params.blockTag === 'latest') {
|
|
133
|
+
try {
|
|
134
|
+
return await performWithRetry();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (isRevertError(error)) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return this.callContract(params.transaction);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return performWithRetry();
|
|
144
|
+
}
|
|
145
|
+
async callContract(transaction) {
|
|
146
|
+
const { contractAddress, callValue, input, issuerAddress } = buildTronTriggerRequest(this.tronWeb, transaction, transaction.from);
|
|
147
|
+
const args = {
|
|
148
|
+
owner_address: issuerAddress,
|
|
149
|
+
contract_address: contractAddress,
|
|
150
|
+
function_selector: '',
|
|
151
|
+
data: input,
|
|
152
|
+
call_value: callValue,
|
|
153
|
+
visible: false,
|
|
154
|
+
};
|
|
155
|
+
// Post directly to the raw constant-call endpoint instead of TronWeb's
|
|
156
|
+
// triggerConstantContract wrapper, which throws on a reverted read and
|
|
157
|
+
// discards constant_result.
|
|
158
|
+
const response = await retryAsync(() => this.tronWeb.fullNode.request('wallet/triggerconstantcontract', args, 'post'), this.maxRetries, this.baseRetryMs);
|
|
159
|
+
const { result, constant_result } = response;
|
|
160
|
+
// SUCCESS: the VM executed successfully; its return data lands in
|
|
161
|
+
// constant_result[0] (empty -> 0x). Only a successful execution returns
|
|
162
|
+
// data — a revert must not reach ABI decoding as if it were return data.
|
|
163
|
+
if (result?.result === true) {
|
|
164
|
+
return ensure0x(constant_result?.[0] ?? '');
|
|
165
|
+
}
|
|
166
|
+
// EXECUTED-REVERT: a `constant_result` on a non-success means the VM ran and
|
|
167
|
+
// reverted; its revert bytes land in constant_result[0] (empty -> 0x for a
|
|
168
|
+
// reasonless revert). Surface it as a CALL_EXCEPTION carrying that data so
|
|
169
|
+
// the SDK's missing-selector detection recognizes a reasonless (0x) revert
|
|
170
|
+
// as a missing selector, while a revert WITH data propagates as a real
|
|
171
|
+
// revert — mirroring what ethers' eth_call would surface.
|
|
172
|
+
if (constant_result) {
|
|
173
|
+
const data = ensure0x(constant_result[0] ?? '');
|
|
174
|
+
const rawMessage = result?.message;
|
|
175
|
+
const reason = rawMessage
|
|
176
|
+
? this.tronWeb.toUtf8(rawMessage)
|
|
177
|
+
: 'execution reverted';
|
|
178
|
+
throw callExceptionLogger.makeError(`Tron constant call reverted: ${reason}`, utils.Logger.errors.CALL_EXCEPTION, { data });
|
|
179
|
+
}
|
|
180
|
+
// PRE-EXECUTION FAILURE: no constant_result means the call failed before
|
|
181
|
+
// execution (bad request, contract not found, disabled API, malformed
|
|
182
|
+
// response). Surface the node's decoded message rather than masking a real
|
|
183
|
+
// failure as an empty return.
|
|
184
|
+
const rawMessage = result?.message;
|
|
185
|
+
const message = rawMessage
|
|
186
|
+
? this.tronWeb.toUtf8(rawMessage)
|
|
187
|
+
: 'unknown error';
|
|
188
|
+
throw new Error(`Tron constant call failed: ${message}`);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Tron's eth_estimateGas is unreliable — it rejects contract creation (no `to` field)
|
|
192
|
+
* and often returns "method parameters invalid" for contract calls.
|
|
193
|
+
* Return a default gas limit since Tron uses feeLimit (not gasLimit) for execution,
|
|
194
|
+
* and TronWallet.buildTransaction caps feeLimit at 1000 TRX anyway.
|
|
195
|
+
*/
|
|
196
|
+
async estimateGas(_transaction) {
|
|
197
|
+
try {
|
|
198
|
+
return await super.estimateGas(_transaction);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Return a default gas limit for Tron transactions since estimation is unreliable.
|
|
202
|
+
return BigNumber.from(MAX_TRON_ORIGIN_ENERGY_LIMIT);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Tron doesn't use nonces - always return 0.
|
|
207
|
+
*
|
|
208
|
+
* This is a nonce accessor, not a liveness signal: a live Tron account still
|
|
209
|
+
* reports 0 here. Use {@link isAccountActive} to test whether an account
|
|
210
|
+
* exists on-chain.
|
|
211
|
+
*/
|
|
212
|
+
async getTransactionCount(_addressOrName, _blockTag) {
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Whether an address has been activated on-chain.
|
|
217
|
+
*
|
|
218
|
+
* Tron accounts must be activated before they exist, and there are no nonces,
|
|
219
|
+
* so activation is read from the native account endpoint rather than inferred
|
|
220
|
+
* from `getTransactionCount` (which is hardcoded to 0, see above). An address
|
|
221
|
+
* that was never activated answers HTTP 200 with an empty object.
|
|
222
|
+
*
|
|
223
|
+
* Presence is deliberately keyed off the response being non-empty rather than
|
|
224
|
+
* off `create_time`: contract accounts omit `create_time` entirely, so keying
|
|
225
|
+
* off it would report every Tron contract inactive.
|
|
226
|
+
*
|
|
227
|
+
* Transport failures propagate. A node we cannot reach is not evidence that
|
|
228
|
+
* an account is missing, and callers gate destructive/reporting decisions on
|
|
229
|
+
* this answer.
|
|
230
|
+
*/
|
|
231
|
+
async isAccountActive(address) {
|
|
232
|
+
const base58Address = this.tronWeb.address.fromHex(toTronHex(this.tronWeb, address));
|
|
233
|
+
const response = await retryAsync(() => this.tronWeb.fullNode.request(TRON_GET_ACCOUNT_PATH, { address: base58Address, visible: true }, 'post'), this.maxRetries, this.baseRetryMs);
|
|
234
|
+
if (isNullish(response)) {
|
|
235
|
+
throw new Error(`Tron account lookup returned no response body for ${base58Address}`);
|
|
236
|
+
}
|
|
237
|
+
if (response.Error) {
|
|
238
|
+
throw new Error(`Tron account lookup failed: ${response.Error}`);
|
|
239
|
+
}
|
|
240
|
+
return Object.keys(response).length > 0;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Tron doesn't support ENS - return the name as-is.
|
|
244
|
+
*/
|
|
245
|
+
async resolveName(name) {
|
|
246
|
+
return name;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Return legacy gas pricing only - Tron doesn't support EIP-1559.
|
|
250
|
+
*/
|
|
251
|
+
async getFeeData() {
|
|
252
|
+
const gasPrice = await this.getGasPrice();
|
|
253
|
+
return {
|
|
254
|
+
gasPrice,
|
|
255
|
+
maxFeePerGas: null,
|
|
256
|
+
maxPriorityFeePerGas: null,
|
|
257
|
+
lastBaseFeePerGas: null,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=TronJsonRpcProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TronJsonRpcProvider.js","sourceRoot":"","sources":["../../src/ethers/TronJsonRpcProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AA2BlC,6CAA6C;AAC7C,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAElD,yEAAyE;AACzE,MAAM,CAAC,MAAM,4BAA4B,GAAG,UAAU,CAAC;AAEvD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AA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