genlayer-js 0.18.10 → 0.18.12
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/dist/chains/index.cjs +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/{chunk-PPBY3UXF.cjs → chunk-5TKVNHAO.cjs} +1118 -305
- package/dist/{chunk-WZNF2WK4.js → chunk-NOFMB7RP.js} +1118 -305
- package/dist/{index-D9ONjYgl.d.cts → index-DsN7LGHA.d.cts} +1615 -459
- package/dist/{index-ZDqJWXj0.d.ts → index-sw3NAvBf.d.ts} +1615 -459
- package/dist/index.cjs +58 -58
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -28
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +11 -1
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -59
- package/.github/pull_request_template.md +0 -43
- package/.github/workflows/publish.yml +0 -41
- package/.github/workflows/test.yml +0 -33
- package/.prettierignore +0 -19
- package/.prettierrc +0 -12
- package/.release-it.json +0 -64
- package/CHANGELOG.md +0 -304
- package/CLAUDE.md +0 -66
- package/CONTRIBUTING.md +0 -87
- package/renovate.json +0 -20
- package/src/abi/calldata/consts.ts +0 -14
- package/src/abi/calldata/decoder.ts +0 -86
- package/src/abi/calldata/encoder.ts +0 -178
- package/src/abi/calldata/index.ts +0 -3
- package/src/abi/calldata/string.ts +0 -83
- package/src/abi/index.ts +0 -6
- package/src/abi/staking.ts +0 -687
- package/src/abi/transactions.ts +0 -11
- package/src/accounts/IAccountActions.ts +0 -5
- package/src/accounts/account.ts +0 -9
- package/src/accounts/actions.ts +0 -34
- package/src/chains/actions.ts +0 -40
- package/src/chains/index.ts +0 -4
- package/src/chains/localnet.ts +0 -4016
- package/src/chains/studionet.ts +0 -4017
- package/src/chains/testnetAsimov.ts +0 -4013
- package/src/client/client.ts +0 -139
- package/src/config/snapID.ts +0 -4
- package/src/config/transactions.ts +0 -9
- package/src/contracts/actions.ts +0 -387
- package/src/global.d.ts +0 -9
- package/src/index.ts +0 -12
- package/src/staking/actions.ts +0 -691
- package/src/staking/index.ts +0 -2
- package/src/staking/utils.ts +0 -22
- package/src/transactions/ITransactionActions.ts +0 -15
- package/src/transactions/actions.ts +0 -113
- package/src/transactions/decoders.ts +0 -275
- package/src/types/accounts.ts +0 -1
- package/src/types/calldata.ts +0 -31
- package/src/types/chains.ts +0 -22
- package/src/types/clients.ts +0 -106
- package/src/types/contracts.ts +0 -32
- package/src/types/index.ts +0 -9
- package/src/types/metamaskClientResult.ts +0 -5
- package/src/types/network.ts +0 -1
- package/src/types/snapSource.ts +0 -1
- package/src/types/staking.ts +0 -225
- package/src/types/transactions.ts +0 -312
- package/src/utils/async.ts +0 -3
- package/src/utils/jsonifier.ts +0 -119
- package/src/wallet/actions.ts +0 -10
- package/src/wallet/connect.ts +0 -67
- package/src/wallet/metamaskClient.ts +0 -50
- package/tests/client.test-d.ts +0 -67
- package/tests/client.test.ts +0 -197
- package/tests/smoke.test.ts +0 -59
- package/tests/transactions.test.ts +0 -142
- package/tsconfig.json +0 -119
- package/tsconfig.vitest-temp.json +0 -41
- package/vitest.config.ts +0 -18
package/src/client/client.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Account,
|
|
3
|
-
createClient as createViemClient,
|
|
4
|
-
createPublicClient as createPublicViemClient,
|
|
5
|
-
publicActions,
|
|
6
|
-
custom,
|
|
7
|
-
Address,
|
|
8
|
-
walletActions,
|
|
9
|
-
Transport,
|
|
10
|
-
PublicClient,
|
|
11
|
-
Chain,
|
|
12
|
-
} from "viem";
|
|
13
|
-
import {accountActions} from "../accounts/actions";
|
|
14
|
-
import {contractActions} from "../contracts/actions";
|
|
15
|
-
import {receiptActions, transactionActions} from "../transactions/actions";
|
|
16
|
-
import {walletActions as genlayerWalletActions} from "../wallet/actions";
|
|
17
|
-
import {stakingActions} from "../staking/actions";
|
|
18
|
-
import {GenLayerClient, GenLayerChain} from "@/types";
|
|
19
|
-
import {chainActions} from "@/chains/actions";
|
|
20
|
-
import {localnet} from "@/chains";
|
|
21
|
-
|
|
22
|
-
// Define the configuration interface for the client
|
|
23
|
-
interface ClientConfig {
|
|
24
|
-
chain?: {
|
|
25
|
-
id: number;
|
|
26
|
-
name: string;
|
|
27
|
-
rpcUrls: {default: {http: readonly string[]}};
|
|
28
|
-
nativeCurrency: {name: string; symbol: string; decimals: number};
|
|
29
|
-
blockExplorers?: {default: {name: string; url: string}};
|
|
30
|
-
};
|
|
31
|
-
endpoint?: string; // Custom RPC endpoint
|
|
32
|
-
account?: Account | Address;
|
|
33
|
-
provider?: EthereumProvider; // Custom provider for wallet framework integration
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const getCustomTransportConfig = (config: ClientConfig, chainConfig: GenLayerChain) => {
|
|
37
|
-
const isAddress = typeof config.account !== "object";
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
async request({method, params = []}: {method: string; params: any[]}) {
|
|
41
|
-
if (method.startsWith("eth_") && isAddress) {
|
|
42
|
-
const provider = config.provider || (typeof window !== "undefined" ? window.ethereum : undefined);
|
|
43
|
-
if (provider) {
|
|
44
|
-
try {
|
|
45
|
-
return await provider.request({method, params});
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.warn(`Error using provider for method ${method}:`, err);
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
try {
|
|
55
|
-
const response = await fetch(chainConfig.rpcUrls.default.http[0], {
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: {
|
|
58
|
-
"Content-Type": "application/json",
|
|
59
|
-
},
|
|
60
|
-
body: JSON.stringify({
|
|
61
|
-
jsonrpc: "2.0",
|
|
62
|
-
id: Date.now(),
|
|
63
|
-
method,
|
|
64
|
-
params,
|
|
65
|
-
}),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const data = await response.json();
|
|
69
|
-
|
|
70
|
-
if (data.error) {
|
|
71
|
-
throw data.error
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return data.result;
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error(`Error fetching ${method} from GenLayer RPC`);
|
|
77
|
-
throw err;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const createClient = (config: ClientConfig = {chain: localnet}): GenLayerClient<GenLayerChain> => {
|
|
85
|
-
const chainConfig = config.chain || localnet;
|
|
86
|
-
if (config.endpoint) {
|
|
87
|
-
chainConfig.rpcUrls.default.http = [config.endpoint];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const customTransport = custom(getCustomTransportConfig(config, chainConfig as GenLayerChain), {retryCount: 0, retryDelay: 0});
|
|
91
|
-
const publicClient = createPublicClient(chainConfig as GenLayerChain, customTransport).extend(
|
|
92
|
-
publicActions,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const baseClient = createViemClient({
|
|
96
|
-
chain: chainConfig,
|
|
97
|
-
transport: customTransport,
|
|
98
|
-
...(config.account ? {account: config.account} : {}),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const clientWithBasicActions = baseClient
|
|
102
|
-
.extend(publicActions)
|
|
103
|
-
.extend(walletActions)
|
|
104
|
-
.extend(client => accountActions(client as unknown as GenLayerClient<GenLayerChain>));
|
|
105
|
-
|
|
106
|
-
const clientWithTransactionActions = {
|
|
107
|
-
...clientWithBasicActions,
|
|
108
|
-
...transactionActions(clientWithBasicActions as unknown as GenLayerClient<GenLayerChain>, publicClient),
|
|
109
|
-
...chainActions(clientWithBasicActions as unknown as GenLayerClient<GenLayerChain>),
|
|
110
|
-
...genlayerWalletActions(clientWithBasicActions as unknown as GenLayerClient<GenLayerChain>),
|
|
111
|
-
} as unknown as GenLayerClient<GenLayerChain>;
|
|
112
|
-
|
|
113
|
-
const clientWithAllActions = {
|
|
114
|
-
...clientWithTransactionActions,
|
|
115
|
-
...contractActions(clientWithTransactionActions as unknown as GenLayerClient<GenLayerChain>, publicClient),
|
|
116
|
-
} as unknown as GenLayerClient<GenLayerChain>;
|
|
117
|
-
|
|
118
|
-
const clientWithReceiptActions = {
|
|
119
|
-
...clientWithAllActions,
|
|
120
|
-
...receiptActions(clientWithAllActions as unknown as GenLayerClient<GenLayerChain>, publicClient),
|
|
121
|
-
} as unknown as GenLayerClient<GenLayerChain>;
|
|
122
|
-
|
|
123
|
-
const finalClient = {
|
|
124
|
-
...clientWithReceiptActions,
|
|
125
|
-
...stakingActions(clientWithReceiptActions as unknown as GenLayerClient<GenLayerChain>, publicClient),
|
|
126
|
-
} as unknown as GenLayerClient<GenLayerChain>;
|
|
127
|
-
|
|
128
|
-
finalClient.initializeConsensusSmartContract().catch(error => {
|
|
129
|
-
console.error("Failed to initialize consensus smart contract:", error);
|
|
130
|
-
});
|
|
131
|
-
return finalClient;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const createPublicClient = (
|
|
135
|
-
chainConfig: GenLayerChain,
|
|
136
|
-
customTransport: Transport,
|
|
137
|
-
): PublicClient<Transport, Chain> => {
|
|
138
|
-
return createPublicViemClient({chain: chainConfig, transport: customTransport});
|
|
139
|
-
};
|
package/src/config/snapID.ts
DELETED
package/src/contracts/actions.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import * as calldata from "@/abi/calldata";
|
|
2
|
-
import {serialize} from "@/abi/transactions";
|
|
3
|
-
import {localnet} from "@/chains/localnet";
|
|
4
|
-
import {
|
|
5
|
-
Account,
|
|
6
|
-
ContractSchema,
|
|
7
|
-
GenLayerChain,
|
|
8
|
-
GenLayerClient,
|
|
9
|
-
CalldataEncodable,
|
|
10
|
-
Address,
|
|
11
|
-
TransactionHashVariant,
|
|
12
|
-
} from "@/types";
|
|
13
|
-
import {fromHex, toHex, zeroAddress, encodeFunctionData, PublicClient, parseEventLogs} from "viem";
|
|
14
|
-
import {toJsonSafeDeep, b64ToArray} from "@/utils/jsonifier";
|
|
15
|
-
|
|
16
|
-
export const contractActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => {
|
|
17
|
-
return {
|
|
18
|
-
getContractCode: async (address: Address): Promise<string> => {
|
|
19
|
-
if (client.chain.id !== localnet.id) {
|
|
20
|
-
throw new Error("Getting contract code is not supported on this network");
|
|
21
|
-
}
|
|
22
|
-
const result = (await client.request({
|
|
23
|
-
method: "gen_getContractCode",
|
|
24
|
-
params: [address],
|
|
25
|
-
})) as string;
|
|
26
|
-
const codeBytes = b64ToArray(result);
|
|
27
|
-
return new TextDecoder().decode(codeBytes);
|
|
28
|
-
},
|
|
29
|
-
getContractSchema: async (address: Address): Promise<ContractSchema> => {
|
|
30
|
-
if (client.chain.id !== localnet.id) {
|
|
31
|
-
throw new Error("Contract schema is not supported on this network");
|
|
32
|
-
}
|
|
33
|
-
const schema = (await client.request({
|
|
34
|
-
method: "gen_getContractSchema",
|
|
35
|
-
params: [address],
|
|
36
|
-
})) as string;
|
|
37
|
-
return schema as unknown as ContractSchema;
|
|
38
|
-
},
|
|
39
|
-
getContractSchemaForCode: async (contractCode: string | Uint8Array): Promise<ContractSchema> => {
|
|
40
|
-
if (client.chain.id !== localnet.id) {
|
|
41
|
-
throw new Error("Contract schema is not supported on this network");
|
|
42
|
-
}
|
|
43
|
-
const schema = (await client.request({
|
|
44
|
-
method: "gen_getContractSchemaForCode",
|
|
45
|
-
params: [toHex(contractCode)],
|
|
46
|
-
})) as string;
|
|
47
|
-
return schema as unknown as ContractSchema;
|
|
48
|
-
},
|
|
49
|
-
readContract: async <RawReturn extends boolean | undefined>(args: {
|
|
50
|
-
account?: Account;
|
|
51
|
-
address: Address;
|
|
52
|
-
functionName: string;
|
|
53
|
-
args?: CalldataEncodable[];
|
|
54
|
-
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
55
|
-
rawReturn?: RawReturn;
|
|
56
|
-
jsonSafeReturn?: boolean;
|
|
57
|
-
leaderOnly?: boolean;
|
|
58
|
-
transactionHashVariant?: TransactionHashVariant;
|
|
59
|
-
}): Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable> => {
|
|
60
|
-
const {
|
|
61
|
-
account,
|
|
62
|
-
address,
|
|
63
|
-
functionName,
|
|
64
|
-
args: callArgs,
|
|
65
|
-
kwargs,
|
|
66
|
-
jsonSafeReturn = false,
|
|
67
|
-
leaderOnly = false,
|
|
68
|
-
transactionHashVariant = TransactionHashVariant.LATEST_NONFINAL,
|
|
69
|
-
} = args;
|
|
70
|
-
|
|
71
|
-
const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
72
|
-
const serializedData = serialize(encodedData);
|
|
73
|
-
|
|
74
|
-
const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
|
|
75
|
-
|
|
76
|
-
const requestParams = {
|
|
77
|
-
type: "read",
|
|
78
|
-
to: address,
|
|
79
|
-
from: senderAddress,
|
|
80
|
-
data: serializedData,
|
|
81
|
-
transaction_hash_variant: transactionHashVariant,
|
|
82
|
-
};
|
|
83
|
-
const result = await client.request({
|
|
84
|
-
method: "gen_call",
|
|
85
|
-
params: [requestParams],
|
|
86
|
-
});
|
|
87
|
-
const prefixedResult = `0x${result}` as `0x${string}`;
|
|
88
|
-
|
|
89
|
-
if (args.rawReturn) {
|
|
90
|
-
return prefixedResult;
|
|
91
|
-
}
|
|
92
|
-
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
93
|
-
const decoded = calldata.decode(resultBinary) as any;
|
|
94
|
-
if (!jsonSafeReturn) {
|
|
95
|
-
return decoded;
|
|
96
|
-
}
|
|
97
|
-
// If jsonSafeReturn is requested, convert to JSON-safe recursively
|
|
98
|
-
return toJsonSafeDeep(decoded) as any;
|
|
99
|
-
},
|
|
100
|
-
simulateWriteContract: async <RawReturn extends boolean | undefined>(args: {
|
|
101
|
-
account?: Account;
|
|
102
|
-
address: Address;
|
|
103
|
-
functionName: string;
|
|
104
|
-
args?: CalldataEncodable[];
|
|
105
|
-
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
106
|
-
rawReturn?: RawReturn;
|
|
107
|
-
leaderOnly?: boolean;
|
|
108
|
-
transactionHashVariant?: TransactionHashVariant;
|
|
109
|
-
}): Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable> => {
|
|
110
|
-
const {
|
|
111
|
-
account,
|
|
112
|
-
address,
|
|
113
|
-
functionName,
|
|
114
|
-
args: callArgs,
|
|
115
|
-
kwargs,
|
|
116
|
-
leaderOnly = false,
|
|
117
|
-
transactionHashVariant = TransactionHashVariant.LATEST_NONFINAL,
|
|
118
|
-
} = args;
|
|
119
|
-
|
|
120
|
-
const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
121
|
-
const serializedData = serialize(encodedData);
|
|
122
|
-
|
|
123
|
-
const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
|
|
124
|
-
|
|
125
|
-
const requestParams = {
|
|
126
|
-
type: "write",
|
|
127
|
-
to: address,
|
|
128
|
-
from: senderAddress,
|
|
129
|
-
data: serializedData,
|
|
130
|
-
transaction_hash_variant: transactionHashVariant,
|
|
131
|
-
};
|
|
132
|
-
const result = await client.request({
|
|
133
|
-
method: "gen_call",
|
|
134
|
-
params: [requestParams],
|
|
135
|
-
});
|
|
136
|
-
const prefixedResult = `0x${result}` as `0x${string}`;
|
|
137
|
-
|
|
138
|
-
if (args.rawReturn) {
|
|
139
|
-
return prefixedResult;
|
|
140
|
-
}
|
|
141
|
-
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
142
|
-
return calldata.decode(resultBinary) as any;
|
|
143
|
-
},
|
|
144
|
-
writeContract: async (args: {
|
|
145
|
-
account?: Account;
|
|
146
|
-
address: Address;
|
|
147
|
-
functionName: string;
|
|
148
|
-
args?: CalldataEncodable[];
|
|
149
|
-
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
150
|
-
value: bigint;
|
|
151
|
-
leaderOnly?: boolean;
|
|
152
|
-
consensusMaxRotations?: number;
|
|
153
|
-
}): Promise<`0x${string}`> => {
|
|
154
|
-
const {
|
|
155
|
-
account,
|
|
156
|
-
address,
|
|
157
|
-
functionName,
|
|
158
|
-
args: callArgs,
|
|
159
|
-
kwargs,
|
|
160
|
-
value = 0n,
|
|
161
|
-
leaderOnly = false,
|
|
162
|
-
consensusMaxRotations = client.chain.defaultConsensusMaxRotations,
|
|
163
|
-
} = args;
|
|
164
|
-
const data = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
165
|
-
const serializedData = serialize(data);
|
|
166
|
-
const senderAccount = account || client.account;
|
|
167
|
-
const encodedData = _encodeAddTransactionData({
|
|
168
|
-
client,
|
|
169
|
-
senderAccount,
|
|
170
|
-
recipient: address,
|
|
171
|
-
data: serializedData,
|
|
172
|
-
consensusMaxRotations,
|
|
173
|
-
});
|
|
174
|
-
return _sendTransaction({
|
|
175
|
-
client,
|
|
176
|
-
publicClient,
|
|
177
|
-
encodedData,
|
|
178
|
-
senderAccount,
|
|
179
|
-
value,
|
|
180
|
-
});
|
|
181
|
-
},
|
|
182
|
-
deployContract: async (args: {
|
|
183
|
-
account?: Account;
|
|
184
|
-
code: string | Uint8Array;
|
|
185
|
-
args?: CalldataEncodable[];
|
|
186
|
-
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
187
|
-
leaderOnly?: boolean;
|
|
188
|
-
consensusMaxRotations?: number;
|
|
189
|
-
}) => {
|
|
190
|
-
const {
|
|
191
|
-
account,
|
|
192
|
-
code,
|
|
193
|
-
args: constructorArgs,
|
|
194
|
-
kwargs,
|
|
195
|
-
leaderOnly = false,
|
|
196
|
-
consensusMaxRotations = client.chain.defaultConsensusMaxRotations,
|
|
197
|
-
} = args;
|
|
198
|
-
const data = [
|
|
199
|
-
code,
|
|
200
|
-
calldata.encode(calldata.makeCalldataObject(undefined, constructorArgs, kwargs)),
|
|
201
|
-
leaderOnly,
|
|
202
|
-
];
|
|
203
|
-
const serializedData = serialize(data);
|
|
204
|
-
const senderAccount = account || client.account;
|
|
205
|
-
const encodedData = _encodeAddTransactionData({
|
|
206
|
-
client,
|
|
207
|
-
senderAccount,
|
|
208
|
-
recipient: zeroAddress,
|
|
209
|
-
data: serializedData,
|
|
210
|
-
consensusMaxRotations,
|
|
211
|
-
});
|
|
212
|
-
return _sendTransaction({
|
|
213
|
-
client,
|
|
214
|
-
publicClient,
|
|
215
|
-
encodedData,
|
|
216
|
-
senderAccount,
|
|
217
|
-
});
|
|
218
|
-
},
|
|
219
|
-
appealTransaction: async (args: {
|
|
220
|
-
account?: Account;
|
|
221
|
-
txId: `0x${string}`;
|
|
222
|
-
}) => {
|
|
223
|
-
const {account, txId} = args;
|
|
224
|
-
const senderAccount = account || client.account;
|
|
225
|
-
const encodedData = _encodeSubmitAppealData({client, txId});
|
|
226
|
-
return _sendTransaction({
|
|
227
|
-
client,
|
|
228
|
-
publicClient,
|
|
229
|
-
encodedData,
|
|
230
|
-
senderAccount,
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const validateAccount = (Account?: Account): Account => {
|
|
237
|
-
if (!Account) {
|
|
238
|
-
throw new Error(
|
|
239
|
-
"No account set. Configure the client with an account or pass an account to this function.",
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
return Account;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const _encodeAddTransactionData = ({
|
|
246
|
-
client,
|
|
247
|
-
senderAccount,
|
|
248
|
-
recipient,
|
|
249
|
-
data,
|
|
250
|
-
consensusMaxRotations = client.chain.defaultConsensusMaxRotations,
|
|
251
|
-
}: {
|
|
252
|
-
client: GenLayerClient<GenLayerChain>;
|
|
253
|
-
senderAccount?: Account;
|
|
254
|
-
recipient?: `0x${string}`;
|
|
255
|
-
data?: `0x${string}`;
|
|
256
|
-
consensusMaxRotations?: number;
|
|
257
|
-
}): `0x${string}` => {
|
|
258
|
-
const validatedSenderAccount = validateAccount(senderAccount);
|
|
259
|
-
return encodeFunctionData({
|
|
260
|
-
abi: client.chain.consensusMainContract?.abi as any,
|
|
261
|
-
functionName: "addTransaction",
|
|
262
|
-
args: [
|
|
263
|
-
validatedSenderAccount.address,
|
|
264
|
-
recipient,
|
|
265
|
-
client.chain.defaultNumberOfInitialValidators,
|
|
266
|
-
consensusMaxRotations,
|
|
267
|
-
data,
|
|
268
|
-
],
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const _encodeSubmitAppealData = ({
|
|
273
|
-
client,
|
|
274
|
-
txId,
|
|
275
|
-
}: {
|
|
276
|
-
client: GenLayerClient<GenLayerChain>;
|
|
277
|
-
txId: `0x${string}`;
|
|
278
|
-
}): `0x${string}` => {
|
|
279
|
-
return encodeFunctionData({
|
|
280
|
-
abi: client.chain.consensusMainContract?.abi as any,
|
|
281
|
-
functionName: "submitAppeal",
|
|
282
|
-
args: [txId],
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const _sendTransaction = async ({
|
|
287
|
-
client,
|
|
288
|
-
publicClient,
|
|
289
|
-
encodedData,
|
|
290
|
-
senderAccount,
|
|
291
|
-
value = 0n,
|
|
292
|
-
}: {
|
|
293
|
-
client: GenLayerClient<GenLayerChain>;
|
|
294
|
-
publicClient: PublicClient;
|
|
295
|
-
encodedData: `0x${string}`;
|
|
296
|
-
senderAccount?: Account;
|
|
297
|
-
value?: bigint;
|
|
298
|
-
}) => {
|
|
299
|
-
if (!client.chain.consensusMainContract?.address) {
|
|
300
|
-
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const validatedSenderAccount = validateAccount(senderAccount);
|
|
304
|
-
const nonce = await client.getCurrentNonce({address: validatedSenderAccount.address});
|
|
305
|
-
|
|
306
|
-
let estimatedGas: bigint;
|
|
307
|
-
try {
|
|
308
|
-
estimatedGas = await client.estimateTransactionGas({
|
|
309
|
-
from: validatedSenderAccount.address,
|
|
310
|
-
to: client.chain.consensusMainContract?.address as Address,
|
|
311
|
-
data: encodedData,
|
|
312
|
-
value: value,
|
|
313
|
-
});
|
|
314
|
-
} catch (err) {
|
|
315
|
-
console.error("Gas estimation failed, using default 200_000:", err);
|
|
316
|
-
estimatedGas = 200_000n;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// For local accounts, build transaction request directly to avoid viem's
|
|
320
|
-
// prepareTransactionRequest which calls eth_fillTransaction (unsupported by GenLayer RPC)
|
|
321
|
-
if (validatedSenderAccount?.type === "local") {
|
|
322
|
-
if (!validatedSenderAccount?.signTransaction) {
|
|
323
|
-
throw new Error("Account does not support signTransaction");
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const gasPriceHex = (await client.request({
|
|
327
|
-
method: "eth_gasPrice",
|
|
328
|
-
})) as string;
|
|
329
|
-
|
|
330
|
-
const transactionRequest = {
|
|
331
|
-
account: validatedSenderAccount,
|
|
332
|
-
to: client.chain.consensusMainContract?.address as Address,
|
|
333
|
-
data: encodedData,
|
|
334
|
-
type: "legacy" as const,
|
|
335
|
-
nonce: Number(nonce),
|
|
336
|
-
value: value,
|
|
337
|
-
gas: estimatedGas,
|
|
338
|
-
gasPrice: BigInt(gasPriceHex),
|
|
339
|
-
chainId: client.chain.id,
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
343
|
-
const txHash = await client.sendRawTransaction({serializedTransaction: serializedTransaction});
|
|
344
|
-
const receipt = await publicClient.waitForTransactionReceipt({hash: txHash});
|
|
345
|
-
|
|
346
|
-
if (receipt.status === "reverted") {
|
|
347
|
-
throw new Error("Transaction reverted");
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const newTxEvents = parseEventLogs({
|
|
351
|
-
abi: client.chain.consensusMainContract?.abi as any,
|
|
352
|
-
eventName: "NewTransaction",
|
|
353
|
-
logs: receipt.logs,
|
|
354
|
-
}) as unknown as {args: {txId: `0x${string}`}}[];
|
|
355
|
-
|
|
356
|
-
if (newTxEvents.length === 0) {
|
|
357
|
-
throw new Error("Transaction not processed by consensus");
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return newTxEvents[0].args["txId"];
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// For external wallets (e.g., MetaMask via AppKit), use prepareTransactionRequest
|
|
364
|
-
// which will route eth_* calls through the provider
|
|
365
|
-
const transactionRequest = await client.prepareTransactionRequest({
|
|
366
|
-
account: validatedSenderAccount,
|
|
367
|
-
to: client.chain.consensusMainContract?.address as Address,
|
|
368
|
-
data: encodedData,
|
|
369
|
-
type: "legacy",
|
|
370
|
-
nonce: Number(nonce),
|
|
371
|
-
value: value,
|
|
372
|
-
gas: estimatedGas,
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
const formattedRequest = {
|
|
376
|
-
from: transactionRequest.from,
|
|
377
|
-
to: transactionRequest.to,
|
|
378
|
-
data: encodedData,
|
|
379
|
-
value: transactionRequest.value ? `0x${transactionRequest.value.toString(16)}` : "0x0",
|
|
380
|
-
gas: transactionRequest.gas ? `0x${transactionRequest.gas.toString(16)}` : "0x5208",
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
return await client.request({
|
|
384
|
-
method: "eth_sendTransaction",
|
|
385
|
-
params: [formattedRequest as any],
|
|
386
|
-
});
|
|
387
|
-
};
|
package/src/global.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
export {createClient} from "./client/client";
|
|
3
|
-
export {createAccount, generatePrivateKey} from "./accounts/account";
|
|
4
|
-
export {
|
|
5
|
-
decodeInputData,
|
|
6
|
-
decodeTransaction,
|
|
7
|
-
simplifyTransactionReceipt,
|
|
8
|
-
decodeLocalnetTransaction
|
|
9
|
-
} from "./transactions/decoders";
|
|
10
|
-
export * as chains from "./chains";
|
|
11
|
-
export * as abi from "./abi";
|
|
12
|
-
export {parseStakingAmount, formatStakingAmount} from "./staking";
|