@sun-protocol/sun-sdk-runtime 0.1.0-beta.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.
@@ -0,0 +1,212 @@
1
+ import { ChainConfig } from '@sun-protocol/sun-sdk-chains';
2
+ import { TronAddress, ContractParameter, ContractCallAction, TransactionIntent, Network, TransactionReceiptFinality } from '@sun-protocol/sun-sdk-core';
3
+
4
+ interface AbiParameter {
5
+ readonly name?: string;
6
+ readonly type: string;
7
+ readonly components?: readonly AbiParameter[];
8
+ readonly [key: string]: unknown;
9
+ }
10
+ interface AbiItem {
11
+ readonly type: string;
12
+ readonly name?: string;
13
+ readonly inputs?: readonly AbiParameter[];
14
+ readonly outputs?: readonly AbiParameter[];
15
+ readonly [key: string]: unknown;
16
+ }
17
+ interface AbiFunction extends AbiItem {
18
+ readonly type: 'function';
19
+ readonly name: string;
20
+ }
21
+ interface UnsignedTronTransaction {
22
+ readonly raw_data?: unknown;
23
+ readonly raw_data_hex?: string;
24
+ readonly txID?: string;
25
+ }
26
+ interface SignedTronTransaction extends UnsignedTronTransaction {
27
+ readonly signature?: readonly string[];
28
+ }
29
+ interface TxResult {
30
+ readonly txid: string;
31
+ readonly raw: unknown;
32
+ }
33
+ interface TransactionReceipt {
34
+ readonly txid: string;
35
+ readonly result: string;
36
+ readonly success: boolean;
37
+ readonly raw: unknown;
38
+ }
39
+ interface WaitForTransactionReceiptOptions {
40
+ /**
41
+ * `included` queries the FullNode latest head and returns after the transaction
42
+ * has been included and executed, but before it is irreversible.
43
+ *
44
+ * `solidified` queries the SolidityNode and returns only after the transaction
45
+ * is part of the irreversible solidified state. It is safer but slower.
46
+ *
47
+ * Defaults to `solidified` for direct callers. Protocol execution always
48
+ * passes the action's explicit `waitForReceipt` policy.
49
+ */
50
+ readonly finality?: TransactionReceiptFinality;
51
+ readonly timeoutMs?: number;
52
+ readonly pollIntervalMs?: number;
53
+ }
54
+ interface TypedDataPayload {
55
+ readonly primaryType: string;
56
+ readonly domain: unknown;
57
+ readonly types: unknown;
58
+ readonly message: unknown;
59
+ }
60
+ interface WalletCapabilities {
61
+ readonly signTransaction: boolean;
62
+ readonly signAndSendTransaction: boolean;
63
+ readonly signTypedData: boolean;
64
+ readonly userInteractive: boolean;
65
+ }
66
+ type WalletSendStrategy = 'sign-then-broadcast' | 'sign-and-send';
67
+ interface WalletAdapter {
68
+ readonly kind: 'privateKey' | 'injected' | 'tronWalletAdapter' | 'custom' | 'mock';
69
+ readonly capabilities: WalletCapabilities;
70
+ readonly sendStrategy?: WalletSendStrategy;
71
+ getAddress(): Promise<TronAddress | string>;
72
+ signTransaction?(tx: UnsignedTronTransaction): Promise<SignedTronTransaction>;
73
+ signAndSendTransaction?(tx: UnsignedTronTransaction): Promise<TxResult | unknown>;
74
+ signTypedData?(payload: TypedDataPayload): Promise<string>;
75
+ signMessage?(message: string): Promise<string>;
76
+ }
77
+ type GetWallet = () => WalletAdapter | undefined | Promise<WalletAdapter | undefined>;
78
+ interface ContractRead {
79
+ readonly target: TronAddress;
80
+ readonly functionSelector: string;
81
+ readonly parameters?: readonly ContractParameter[];
82
+ readonly abiFunction?: unknown;
83
+ readonly outputs?: readonly ContractOutputParameter[];
84
+ readonly from?: TronAddress;
85
+ readonly rawParameter?: string;
86
+ /** Return the raw triggerConstantContract response without ABI lookup or decoding. */
87
+ readonly rawResult?: boolean;
88
+ }
89
+ interface ContractOutputParameter {
90
+ readonly type: string;
91
+ readonly name?: string;
92
+ }
93
+ interface ContractCall extends ContractRead {
94
+ readonly callValue?: ContractCallAction['callValue'];
95
+ readonly feeLimit?: ContractCallAction['feeLimit'];
96
+ readonly tokenId?: string;
97
+ readonly tokenValue?: number;
98
+ readonly permissionId?: number;
99
+ }
100
+ interface ContractAddressInput {
101
+ readonly address: TronAddress | string;
102
+ }
103
+ interface ContractAbiInput extends ContractAddressInput {
104
+ readonly abi: readonly AbiItem[];
105
+ readonly functionName: string;
106
+ readonly args?: readonly unknown[];
107
+ readonly functionSelector?: never;
108
+ readonly parameters?: never;
109
+ readonly rawParameter?: never;
110
+ }
111
+ type SelectorParameters = {
112
+ readonly parameters?: readonly ContractParameter[];
113
+ readonly rawParameter?: never;
114
+ } | {
115
+ readonly parameters?: never;
116
+ readonly rawParameter: string;
117
+ };
118
+ type ContractSelectorInput = ContractAddressInput & SelectorParameters & {
119
+ readonly functionSelector: string;
120
+ readonly abi?: never;
121
+ readonly functionName?: never;
122
+ readonly args?: never;
123
+ };
124
+ type ContractReadInput = (ContractAbiInput & {
125
+ readonly from?: TronAddress | string;
126
+ readonly outputs?: never;
127
+ }) | (ContractSelectorInput & {
128
+ readonly from?: TronAddress | string;
129
+ /** Decode supported static outputs. Omit to receive the raw provider response. */
130
+ readonly outputs?: readonly ContractOutputParameter[];
131
+ });
132
+ interface ContractWriteFields {
133
+ readonly callValue?: bigint;
134
+ readonly feeLimit?: number;
135
+ readonly tokenId?: string;
136
+ readonly tokenValue?: number;
137
+ readonly permissionId?: number;
138
+ }
139
+ type ContractWriteInput = (ContractAbiInput & ContractWriteFields) | (ContractSelectorInput & ContractWriteFields);
140
+ interface SubmittedEvent {
141
+ readonly txid: string;
142
+ readonly network: Network;
143
+ readonly ownerAddress: TronAddress;
144
+ readonly walletKind: WalletAdapter['kind'];
145
+ readonly source: 'contract-write' | 'runtime-action';
146
+ readonly actionId?: string;
147
+ readonly intent?: TransactionIntent;
148
+ }
149
+ type SubmittedCallback = (event: SubmittedEvent) => void;
150
+ interface RuntimeWalletExecutionOptions {
151
+ readonly wallet?: WalletAdapter;
152
+ }
153
+ interface ContractWriteExecutionOptions extends RuntimeWalletExecutionOptions {
154
+ /** Required for semantic submission handling when bypassing a transaction plan. */
155
+ readonly intent?: TransactionIntent;
156
+ }
157
+ interface RuntimeBuildTransactionOptions extends RuntimeWalletExecutionOptions {
158
+ readonly ownerAddress?: TronAddress;
159
+ }
160
+ interface ContractClient {
161
+ read<T = unknown>(input: ContractReadInput): Promise<T>;
162
+ write(input: ContractWriteInput, options?: ContractWriteExecutionOptions): Promise<TxResult>;
163
+ }
164
+ interface BuildTransactionOptions {
165
+ readonly ownerAddress?: TronAddress;
166
+ }
167
+ interface MulticallResult<T = unknown> {
168
+ readonly success: boolean;
169
+ readonly value?: T;
170
+ readonly error?: unknown;
171
+ }
172
+ interface AggregateMulticallCall {
173
+ readonly target: TronAddress;
174
+ readonly callData: string;
175
+ }
176
+ interface AggregateMulticallInput {
177
+ readonly requireSuccess: boolean;
178
+ readonly calls: readonly AggregateMulticallCall[];
179
+ }
180
+ interface AggregateMulticallResult {
181
+ readonly success: boolean;
182
+ readonly returnData: string;
183
+ }
184
+ interface TronClient {
185
+ readonly kind: 'tronweb' | 'custom' | 'mock';
186
+ readonly network: Network;
187
+ getNativeBalance?(owner: TronAddress | string): Promise<string>;
188
+ readContract<T = unknown>(call: ContractRead): Promise<T>;
189
+ buildTransaction(call: ContractCall, options?: BuildTransactionOptions): Promise<UnsignedTronTransaction>;
190
+ broadcastTransaction(tx: SignedTronTransaction): Promise<TxResult>;
191
+ waitForTransactionReceipt?(txid: string, options?: WaitForTransactionReceiptOptions): Promise<TransactionReceipt>;
192
+ }
193
+ interface Runtime {
194
+ readonly network: Network;
195
+ readonly chain: ChainConfig;
196
+ readonly tronClient: TronClient;
197
+ readonly contract: ContractClient;
198
+ /** The fixed wallet supplied at construction time. Dynamic wallets are resolved by getWallet(). */
199
+ readonly wallet?: WalletAdapter;
200
+ getWallet(): Promise<WalletAdapter | undefined>;
201
+ requireWallet(operation: string): Promise<WalletAdapter>;
202
+ getAddress(): Promise<TronAddress | undefined>;
203
+ readContract<T = unknown>(call: ContractRead): Promise<T>;
204
+ buildTransaction(action: ContractCallAction, options?: RuntimeBuildTransactionOptions): Promise<UnsignedTronTransaction>;
205
+ sendAction(action: ContractCallAction, options?: RuntimeWalletExecutionOptions): Promise<TxResult>;
206
+ waitForTransactionReceipt?(txid: string, options?: WaitForTransactionReceiptOptions): Promise<TransactionReceipt>;
207
+ signTypedData(payload: TypedDataPayload, options?: RuntimeWalletExecutionOptions): Promise<string>;
208
+ multicall<T = unknown>(calls: readonly ContractRead[]): Promise<readonly MulticallResult<T>[]>;
209
+ aggregateMulticall(input: AggregateMulticallInput): Promise<readonly AggregateMulticallResult[]>;
210
+ }
211
+
212
+ export type { AggregateMulticallInput as A, BuildTransactionOptions as B, ContractCall as C, GetWallet as G, MulticallResult as M, Runtime as R, SignedTronTransaction as S, TxResult as T, UnsignedTronTransaction as U, WalletSendStrategy as W, TypedDataPayload as a, WalletAdapter as b, WalletCapabilities as c, TronClient as d, SubmittedCallback as e, AggregateMulticallResult as f, AbiFunction as g, AbiItem as h, AbiParameter as i, AggregateMulticallCall as j, ContractClient as k, ContractOutputParameter as l, ContractRead as m, ContractReadInput as n, ContractWriteExecutionOptions as o, ContractWriteInput as p, RuntimeBuildTransactionOptions as q, RuntimeWalletExecutionOptions as r, SubmittedEvent as s, TransactionReceipt as t, WaitForTransactionReceiptOptions as u };
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@sun-protocol/sun-sdk-runtime",
3
+ "version": "0.1.0-beta.0",
4
+ "description": "TRON chain clients, wallet adapters, contract access, signing, and transaction broadcasting for SUN SDK.",
5
+ "keywords": [
6
+ "sun",
7
+ "tron",
8
+ "tronweb",
9
+ "wallet",
10
+ "typescript"
11
+ ],
12
+ "homepage": "https://github.com/sun-protocol/sun-sdk#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/sun-protocol/sun-sdk.git",
16
+ "directory": "packages/runtime"
17
+ },
18
+ "private": false,
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=20"
22
+ },
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "typesVersions": {
27
+ "*": {
28
+ "browser": [
29
+ "./dist/browser.d.ts"
30
+ ],
31
+ "tronweb": [
32
+ "./dist/tronweb.d.ts"
33
+ ],
34
+ "node": [
35
+ "./dist/node.d.ts"
36
+ ],
37
+ "mock": [
38
+ "./dist/mock.d.ts"
39
+ ],
40
+ "*": [
41
+ "./dist/index.d.ts"
42
+ ]
43
+ }
44
+ },
45
+ "sideEffects": false,
46
+ "files": [
47
+ "dist"
48
+ ],
49
+ "exports": {
50
+ ".": {
51
+ "types": "./dist/index.d.ts",
52
+ "import": "./dist/index.js",
53
+ "require": "./dist/index.cjs"
54
+ },
55
+ "./browser": {
56
+ "types": "./dist/browser.d.ts",
57
+ "import": "./dist/browser.js",
58
+ "require": "./dist/browser.cjs"
59
+ },
60
+ "./tronweb": {
61
+ "types": "./dist/tronweb.d.ts",
62
+ "import": "./dist/tronweb.js",
63
+ "require": "./dist/tronweb.cjs"
64
+ },
65
+ "./node": {
66
+ "types": "./dist/node.d.ts",
67
+ "import": "./dist/node.js",
68
+ "require": "./dist/node.cjs"
69
+ },
70
+ "./mock": {
71
+ "types": "./dist/mock.d.ts",
72
+ "import": "./dist/mock.js",
73
+ "require": "./dist/mock.cjs"
74
+ }
75
+ },
76
+ "dependencies": {
77
+ "@sun-protocol/sun-sdk-chains": "0.1.0-beta.0",
78
+ "@sun-protocol/sun-sdk-core": "0.1.0-beta.0"
79
+ },
80
+ "peerDependencies": {
81
+ "tronweb": "*"
82
+ },
83
+ "peerDependenciesMeta": {
84
+ "tronweb": {
85
+ "optional": true
86
+ }
87
+ },
88
+ "scripts": {
89
+ "build": "tsup src/index.ts src/browser.ts src/tronweb.ts src/node.ts src/mock.ts --format esm,cjs --dts --sourcemap --clean --tsconfig ../../tsconfig.base.json",
90
+ "typecheck": "tsc -p tsconfig.json --noEmit",
91
+ "test": "vitest run"
92
+ }
93
+ }