@relayprotocol/relay-tron-wallet-adapter 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Reservoir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ <h3 align="center">Relay Tron Wallet Adapter</h3>
2
+
3
+ ### Installation
4
+
5
+ ```
6
+ yarn add @relayprotocol/relay-tron-wallet-adapter @relayprotocol/relay-sdk
7
+ ```
8
+
9
+ Also make sure to install the peer dependencies required by the adapter if your application doesn't already include them:
10
+
11
+ ```
12
+ yarn add viem @relayprotocol/relay-sdk tronweb
13
+ ```
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adaptTronWallet = void 0;
4
+ const relay_sdk_1 = require("@relayprotocol/relay-sdk");
5
+ const adaptTronWallet = (walletAddress, tronWeb) => {
6
+ const getChainId = async () => {
7
+ return 728126428;
8
+ };
9
+ return {
10
+ vmType: 'tvm',
11
+ getChainId,
12
+ address: async () => {
13
+ return walletAddress;
14
+ },
15
+ handleSignMessageStep: async () => {
16
+ throw new Error('Message signing not implemented for Tron');
17
+ },
18
+ handleSendTransactionStep: async (_chainId, stepItem) => {
19
+ const client = (0, relay_sdk_1.getClient)();
20
+ if (!walletAddress)
21
+ throw new Error('No wallet address provided');
22
+ const strip0x = (s) => (s.startsWith('0x') ? s.slice(2) : s);
23
+ const body = {
24
+ owner_address: stepItem.data.parameter?.owner_address,
25
+ contract_address: stepItem.data.parameter?.contract_address,
26
+ data: strip0x(stepItem.data.parameter?.data),
27
+ visible: false,
28
+ fee_limit: 30_000_000
29
+ };
30
+ client.log(['Building Tron Transaction', body], relay_sdk_1.LogLevel.Verbose);
31
+ const res = await tronWeb.fullNode.request('wallet/triggersmartcontract', body, 'post');
32
+ if (!res?.transaction) {
33
+ const reason = res?.result?.message
34
+ ? Buffer.from(res.result.message, 'hex').toString()
35
+ : 'Unknown trigger error';
36
+ throw new Error(`Trigger failed: ${reason}`);
37
+ }
38
+ const signed = await tronWeb.trx.sign(res.transaction);
39
+ const receipt = await tronWeb.trx.sendRawTransaction(signed);
40
+ client.log(['Tron Transaction Broadcasted', receipt], relay_sdk_1.LogLevel.Verbose);
41
+ return receipt?.txid || signed?.txID || res?.transaction?.txID;
42
+ },
43
+ handleConfirmTransactionStep: async (txId) => {
44
+ const pollMs = 1500;
45
+ const timeoutMs = 60_000;
46
+ const targetConfs = 1;
47
+ const start = Date.now();
48
+ const getTip = async () => (await tronWeb.trx.getCurrentBlock())?.block_header?.raw_data?.number ??
49
+ 0;
50
+ while (true) {
51
+ const info = await tronWeb.trx
52
+ .getTransactionInfo(txId)
53
+ .catch(() => undefined);
54
+ if (info && typeof info.blockNumber === 'number') {
55
+ const tip = await getTip();
56
+ const confirmations = Math.max(0, tip - info.blockNumber + 1);
57
+ const result = info.receipt?.result;
58
+ const success = result === 'SUCCESS';
59
+ if (confirmations >= targetConfs) {
60
+ if (success) {
61
+ return info;
62
+ }
63
+ else {
64
+ throw new Error(`Transaction reverted: ${result}`);
65
+ }
66
+ }
67
+ }
68
+ if (Date.now() - start > timeoutMs) {
69
+ throw new Error('Transaction confirmation timed out');
70
+ }
71
+ await new Promise((r) => setTimeout(r, pollMs));
72
+ }
73
+ },
74
+ switchChain: (_chainId) => {
75
+ return new Promise((res) => res());
76
+ }
77
+ };
78
+ };
79
+ exports.adaptTronWallet = adaptTronWallet;
80
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":";;;AACA,wDAIiC;AAS1B,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,OAAgB,EACD,EAAE;IACjB,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;IAED,OAAO;QACL,MAAM,EAAE,KAAK;QACb,UAAU;QACV,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,aAAa,CAAA;QACtB,CAAC;QACD,qBAAqB,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;QAC7D,CAAC;QACD,yBAAyB,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACtD,MAAM,MAAM,GAAG,IAAA,qBAAS,GAAE,CAAA;YAE1B,IAAI,CAAC,aAAa;gBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAGjE,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAA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AAG,KAAK,GAAG,SAAS,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;gBACvD,CAAC;gBAED,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QACD,WAAW,EAAE,CAAC,QAAgB,EAAE,EAAE;YAChC,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAA;QACpC,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAtGY,QAAA,eAAe,mBAsG3B"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./adapter.js"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}