@epoch-protocol/epoch-commons-sdk 0.1.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.
Files changed (43) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/compact.d.ts +1 -0
  3. package/dist/constants/compact.js +5 -0
  4. package/dist/constants/contractAddresses.d.ts +57 -0
  5. package/dist/constants/contractAddresses.js +181 -0
  6. package/dist/constants/index.d.ts +2 -0
  7. package/dist/constants/index.js +18 -0
  8. package/dist/data/epochgraphmainnet.json +410 -0
  9. package/dist/data/epochgraphtestnet.json +532 -0
  10. package/dist/data/index.d.ts +3 -0
  11. package/dist/data/index.js +10 -0
  12. package/dist/index.d.ts +5 -0
  13. package/dist/index.js +22 -0
  14. package/dist/types/index.d.ts +322 -0
  15. package/dist/types/index.js +37 -0
  16. package/dist/utils/compact.d.ts +4 -0
  17. package/dist/utils/compact.js +58 -0
  18. package/dist/utils/index.d.ts +1 -0
  19. package/dist/utils/index.js +17 -0
  20. package/dist/utils/web3.d.ts +9 -0
  21. package/dist/utils/web3.js +115 -0
  22. package/dist/web3/abis/COMPACT_ABI.json +1529 -0
  23. package/dist/web3/abis/epochModuleAbi.d.ts +2 -0
  24. package/dist/web3/abis/epochModuleAbi.js +233 -0
  25. package/dist/web3/abis/erc20Abi.d.ts +2 -0
  26. package/dist/web3/abis/erc20Abi.js +224 -0
  27. package/dist/web3/abis/intentRegistryAbi.d.ts +2 -0
  28. package/dist/web3/abis/intentRegistryAbi.js +925 -0
  29. package/dist/web3/abis/safe7702ProxyFactoryAbi.d.ts +2 -0
  30. package/dist/web3/abis/safe7702ProxyFactoryAbi.js +107 -0
  31. package/dist/web3/abis/safeProxyFactoryAbi.d.ts +2 -0
  32. package/dist/web3/abis/safeProxyFactoryAbi.js +3 -0
  33. package/dist/web3/abis/solverRegistryAbi.d.ts +2 -0
  34. package/dist/web3/abis/solverRegistryAbi.js +236 -0
  35. package/dist/web3/index.d.ts +3 -0
  36. package/dist/web3/index.js +23 -0
  37. package/dist/web3/intents.d.ts +5 -0
  38. package/dist/web3/intents.js +32 -0
  39. package/dist/web3/registry.d.ts +5 -0
  40. package/dist/web3/registry.js +29 -0
  41. package/dist/web3/wallet.d.ts +26 -0
  42. package/dist/web3/wallet.js +390 -0
  43. package/package.json +41 -0
@@ -0,0 +1,322 @@
1
+ import { ethers } from "ethers";
2
+ import { Address, WalletClient } from "viem";
3
+ export type ApiResponse<T> = {
4
+ data: T;
5
+ status: number;
6
+ message?: string;
7
+ };
8
+ export type BlockchainData = {
9
+ balance: string;
10
+ };
11
+ export type ContractInteraction = {
12
+ address: string;
13
+ functionName: string;
14
+ args: any[];
15
+ };
16
+ export type Config = {
17
+ apiUrl: string;
18
+ };
19
+ export type ChainEntity<T extends Chain | Protocol | Token = Chain | Protocol | Token> = {
20
+ name: string;
21
+ data: T;
22
+ };
23
+ export type Task = {
24
+ action?: ProtocolType;
25
+ tokens?: string[][];
26
+ chainIds?: number[][];
27
+ protocol?: string;
28
+ recipient?: string;
29
+ extraData?: string;
30
+ };
31
+ export type NonceResponse = {
32
+ nonce: string;
33
+ };
34
+ export type SolveIntentResponse = {
35
+ success: boolean;
36
+ path: Path[];
37
+ };
38
+ export type ErrorResponse = {
39
+ error: string;
40
+ };
41
+ export type Transaction = {
42
+ target: string;
43
+ data: string;
44
+ value: string;
45
+ };
46
+ export declare enum WalletType {
47
+ safe = "safe",
48
+ metamask = "metamask"
49
+ }
50
+ export type CreateWalletOptions = {
51
+ is7702?: boolean;
52
+ userSigner?: ethers.Wallet | ethers.VoidSigner | WalletClient;
53
+ passkey?: any;
54
+ };
55
+ export type AuthorizationListEntryAny = {
56
+ chainId: number;
57
+ address: string;
58
+ nonce: bigint;
59
+ yParity: any;
60
+ r: any;
61
+ s: any;
62
+ };
63
+ export type AuthEntry7702RLPType = [
64
+ Uint8Array,
65
+ string,
66
+ Uint8Array,
67
+ Uint8Array,
68
+ Uint8Array,
69
+ Uint8Array
70
+ ];
71
+ export type Auth7702RLPType = Array<AuthEntry7702RLPType>;
72
+ export type CreateWalletData = {
73
+ txnData: Transaction;
74
+ proxyAddress: string;
75
+ initializerData: string;
76
+ isAlreadyDeployed: boolean;
77
+ };
78
+ export declare enum ProtocolType {
79
+ lending = "lending:deposit",
80
+ bridge = "bridge",
81
+ swap = "swap",
82
+ restaking = "restaking",
83
+ yield = "yield",
84
+ swapandbridge = "swapandbridge",
85
+ protocolInteraction = "protocol-interaction"
86
+ }
87
+ export interface IntentTaskData {
88
+ action?: ProtocolType;
89
+ tokens?: string[][];
90
+ chainIds?: string[][];
91
+ protocol?: string;
92
+ extraData?: any;
93
+ }
94
+ export type Protocol = {
95
+ contractAddress: {
96
+ [chainName: string]: string;
97
+ };
98
+ type: ProtocolType[];
99
+ };
100
+ export type Token = {
101
+ contractAddress: {
102
+ [chainName: string]: string;
103
+ };
104
+ decimals: number;
105
+ };
106
+ export type Chain = {
107
+ chainId: number;
108
+ explorer: string;
109
+ };
110
+ export type Relationships = {
111
+ protocolTokensByChain: {
112
+ [protocolName: string]: {
113
+ [chainName: string]: {
114
+ tokensIn?: string[];
115
+ tokensOut?: string[];
116
+ tokensInAndOut?: string[];
117
+ };
118
+ };
119
+ };
120
+ };
121
+ export type Graph = {
122
+ protocols: {
123
+ [protocolName: string]: Protocol;
124
+ };
125
+ tokens: {
126
+ [tokenName: string]: Token;
127
+ };
128
+ chains: {
129
+ [chainName: string]: Chain;
130
+ };
131
+ relationships: Relationships;
132
+ };
133
+ export type Solver = {
134
+ solverAddress: string;
135
+ url: string;
136
+ modules: string[];
137
+ status: number;
138
+ };
139
+ export type Approval = {
140
+ tokenAddress: string;
141
+ spenderAddress: string;
142
+ amount: string;
143
+ chainId: number;
144
+ };
145
+ export type Constraint = {
146
+ constraintData: string;
147
+ constraintResponse: string;
148
+ constraints: string;
149
+ optimizationFactor: number;
150
+ deadline: number;
151
+ triggers: string;
152
+ preferredSolvers: string[];
153
+ };
154
+ export type Calldata = {
155
+ data: string;
156
+ target: string;
157
+ value: string;
158
+ };
159
+ export type Intent = {
160
+ sender: string;
161
+ approvals: Approval[];
162
+ task: string;
163
+ constraint: Constraint;
164
+ nonce: string;
165
+ proposedFeeRewards: number;
166
+ chainIds: number[];
167
+ calldatas: Calldata[];
168
+ recurring: boolean;
169
+ signature?: string;
170
+ executor?: string;
171
+ completed?: boolean;
172
+ };
173
+ export type PathItem = {
174
+ name: string;
175
+ chain?: Chain;
176
+ protocol?: Protocol;
177
+ token?: Token & {
178
+ amount: string;
179
+ };
180
+ calldata?: CalldataReturnInterface;
181
+ fillerData?: FillerTokenData;
182
+ };
183
+ export type Path = PathItem[][][];
184
+ export interface QuoteReturnInterface {
185
+ asset: string;
186
+ tokenIn: string;
187
+ tokenOut: string;
188
+ optionalData: any;
189
+ quoteId: string;
190
+ quoteData: string;
191
+ callData: CalldataReturnInterface;
192
+ fillerData?: FillerTokenData;
193
+ }
194
+ export interface ExecutionResult {
195
+ success: boolean;
196
+ transactionHash?: string;
197
+ error?: string;
198
+ }
199
+ export type ExecutionTransaction = {
200
+ target: string;
201
+ value: string;
202
+ callData: string;
203
+ };
204
+ export type IntermediaryApprovals = {
205
+ tokenAddress: string;
206
+ spenderAddress: string;
207
+ amount: string;
208
+ chainId: string;
209
+ };
210
+ export interface IntentEvent {
211
+ user: string;
212
+ intentIndex: number;
213
+ }
214
+ export interface EventData {
215
+ abi: string[];
216
+ data: string[];
217
+ contractAddress: string;
218
+ chainId: string;
219
+ }
220
+ export interface ExecutionTransactionWithEventData {
221
+ userSCWalletAddress: string;
222
+ nonce: string;
223
+ transaction: ExecutionTransaction[];
224
+ eventData: EventData;
225
+ approvals: IntermediaryApprovals[];
226
+ fillerTokenDatas: FillerTokenData[];
227
+ }
228
+ export interface CalldataReturnInterface {
229
+ executionTransactions: ExecutionTransaction[];
230
+ eventData: EventData;
231
+ }
232
+ export interface MultisendTransaction {
233
+ to: string;
234
+ value: string;
235
+ data: string;
236
+ }
237
+ export interface IntentQuoteInterface {
238
+ originSettler: string;
239
+ user: string;
240
+ nonce: string;
241
+ originChainId: string;
242
+ openDeadline: number;
243
+ fillDeadline: number;
244
+ orderDataType: string;
245
+ orderData: string;
246
+ }
247
+ export type FillerTokenData = {
248
+ filler: string;
249
+ user: string;
250
+ token: string;
251
+ amount: string;
252
+ nonce: string;
253
+ fillChainId: string;
254
+ redeemChainId: string;
255
+ };
256
+ export declare enum TransactionStatus {
257
+ PENDING = "pending",
258
+ SUCCESS = "success",
259
+ FAILED = "failed"
260
+ }
261
+ export type QueuedTransactionForIntent = {
262
+ nonce: string;
263
+ transactions: ExecutionTransaction[];
264
+ chainId: number;
265
+ userSCWalletAddress: string;
266
+ intentNonce: string;
267
+ approvals: IntermediaryApprovals[];
268
+ fillerTokenDatas: FillerTokenData[];
269
+ executionType: QueueExecutionType;
270
+ status: TransactionStatus;
271
+ dependenciesTransactions: string[];
272
+ transactionHash: string | null;
273
+ };
274
+ export type CompactDataForQueue = {
275
+ intentNonce: string;
276
+ fillerTokenDatas: FillerTokenData[];
277
+ claimHash: string;
278
+ chainId: string;
279
+ };
280
+ export declare enum QueueExecutionType {
281
+ ADD_AND_EXECUTE = "addAndExecute",
282
+ ADD_INTENT = "addIntent",
283
+ SIMPLE_EXECUTION = "simpleExecution"
284
+ }
285
+ export declare enum TaskType {
286
+ GetTokenOut = "gettokenout",
287
+ Deposit = "deposit",
288
+ ProtocolInteraction = "protocol-interaction"
289
+ }
290
+ export type Mandate = {
291
+ tokenIn: string;
292
+ tokenInAmount: string;
293
+ tokenOut: string;
294
+ minTokenOut: string;
295
+ destinationChainId: string;
296
+ taskType: string;
297
+ recipient: string;
298
+ protocolHashIdentifier?: string;
299
+ [key: string]: any;
300
+ };
301
+ export type SerializedCompactData = {
302
+ arbiter: string;
303
+ sponsor: string;
304
+ nonce: string;
305
+ expires: string;
306
+ id: string;
307
+ lockTag: string;
308
+ token: string;
309
+ amount: string;
310
+ mandate?: Mandate;
311
+ };
312
+ export type CompactData = {
313
+ arbiter: Address;
314
+ sponsor: Address;
315
+ nonce: bigint | string;
316
+ expires: bigint | string;
317
+ id: bigint | string;
318
+ lockTag: bigint | string;
319
+ token: Address | bigint | string;
320
+ amount: bigint | string;
321
+ mandate?: Mandate;
322
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskType = exports.QueueExecutionType = exports.TransactionStatus = exports.ProtocolType = exports.WalletType = void 0;
4
+ var WalletType;
5
+ (function (WalletType) {
6
+ WalletType["safe"] = "safe";
7
+ WalletType["metamask"] = "metamask";
8
+ })(WalletType || (exports.WalletType = WalletType = {}));
9
+ // Define types for various entities
10
+ var ProtocolType;
11
+ (function (ProtocolType) {
12
+ ProtocolType["lending"] = "lending:deposit";
13
+ ProtocolType["bridge"] = "bridge";
14
+ ProtocolType["swap"] = "swap";
15
+ ProtocolType["restaking"] = "restaking";
16
+ ProtocolType["yield"] = "yield";
17
+ ProtocolType["swapandbridge"] = "swapandbridge";
18
+ ProtocolType["protocolInteraction"] = "protocol-interaction";
19
+ })(ProtocolType || (exports.ProtocolType = ProtocolType = {}));
20
+ var TransactionStatus;
21
+ (function (TransactionStatus) {
22
+ TransactionStatus["PENDING"] = "pending";
23
+ TransactionStatus["SUCCESS"] = "success";
24
+ TransactionStatus["FAILED"] = "failed";
25
+ })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
26
+ var QueueExecutionType;
27
+ (function (QueueExecutionType) {
28
+ QueueExecutionType["ADD_AND_EXECUTE"] = "addAndExecute";
29
+ QueueExecutionType["ADD_INTENT"] = "addIntent";
30
+ QueueExecutionType["SIMPLE_EXECUTION"] = "simpleExecution";
31
+ })(QueueExecutionType || (exports.QueueExecutionType = QueueExecutionType = {}));
32
+ var TaskType;
33
+ (function (TaskType) {
34
+ TaskType["GetTokenOut"] = "gettokenout";
35
+ TaskType["Deposit"] = "deposit";
36
+ TaskType["ProtocolInteraction"] = "protocol-interaction";
37
+ })(TaskType || (exports.TaskType = TaskType = {}));
@@ -0,0 +1,4 @@
1
+ import { type Hex } from 'viem';
2
+ import { CompactData } from '../types';
3
+ export declare function getCompactTypehash(witnessTypeString?: string): Hex;
4
+ export declare function getClaimHash(message: CompactData, witnessTypeString: string): `0x${string}`;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompactTypehash = getCompactTypehash;
4
+ exports.getClaimHash = getClaimHash;
5
+ const viem_1 = require("viem");
6
+ const utils_1 = require("viem/utils");
7
+ function getCompactTypehash(witnessTypeString) {
8
+ if (witnessTypeString) {
9
+ const typestring = `Compact(address arbiter,address sponsor,uint256 nonce,uint256 expires,bytes12 lockTag,address token,uint256 amount,Mandate mandate)Mandate(${witnessTypeString})`;
10
+ console.log('typestring: ', typestring);
11
+ return (0, viem_1.keccak256)((0, viem_1.toBytes)(typestring));
12
+ }
13
+ const typestring = 'Compact(address arbiter,address sponsor,uint256 nonce,uint256 expires,bytes12 lockTag,address token,uint256 amount)';
14
+ console.log('typestring: ', typestring);
15
+ return (0, viem_1.keccak256)((0, viem_1.toBytes)(typestring));
16
+ }
17
+ function getClaimHash(message, witnessTypeString) {
18
+ // Convert lockTag bigint to bytes12 hex string and token bigint to address
19
+ const messageWithFormattedData = {
20
+ ...message,
21
+ lockTag: `0x${message.lockTag.toString(16).padStart(24, '0')}`,
22
+ token: typeof message.token === 'bigint'
23
+ ? `0x${message.token.toString(16).padStart(40, '0')}`
24
+ : message.token,
25
+ };
26
+ console.log('messageWithFormattedData: ', messageWithFormattedData);
27
+ console.log('Hererererere');
28
+ console.log('getTypes(message): ', getTypes(message, witnessTypeString));
29
+ console.log('herererere: ');
30
+ return (0, utils_1.hashStruct)({
31
+ types: getTypes(messageWithFormattedData, witnessTypeString),
32
+ primaryType: 'Compact',
33
+ data: messageWithFormattedData,
34
+ });
35
+ }
36
+ function getTypes(message, witnessTypeString) {
37
+ console.log('message: ', message);
38
+ return {
39
+ Compact: [
40
+ { name: 'arbiter', type: 'address' },
41
+ { name: 'sponsor', type: 'address' },
42
+ { name: 'nonce', type: 'uint256' },
43
+ { name: 'expires', type: 'uint256' },
44
+ { name: 'lockTag', type: 'bytes12' },
45
+ { name: 'token', type: 'address' },
46
+ { name: 'amount', type: 'uint256' },
47
+ ...(message.mandate ? [{ name: 'mandate', type: 'Mandate' }] : []),
48
+ ],
49
+ ...(message.mandate
50
+ ? {
51
+ Mandate: witnessTypeString.split(',').map((field) => {
52
+ const [type, name] = field.trim().split(/\s+/);
53
+ return { name, type };
54
+ }),
55
+ }
56
+ : {}),
57
+ };
58
+ }
@@ -0,0 +1 @@
1
+ export * from "./compact";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./compact"), exports);
@@ -0,0 +1,9 @@
1
+ import { ethers } from "ethers";
2
+ import { SignAuthorizationReturnType } from "viem/_types/accounts/utils/signAuthorization";
3
+ import { AuthorizationListEntryAny } from "../types";
4
+ export declare const encodeRLPAuthorizationEntryUnsigned: (chainId: number, address: any, nonce: bigint) => string;
5
+ export declare const getAuthorizationList: (chainId: number, nonce: bigint, authorizer: string, signer: ethers.Wallet | ethers.VoidSigner) => Promise<AuthorizationListEntryAny[]>;
6
+ export declare const getSignedTransaction: (provider: ethers.Provider, relayer: ethers.SigningKey, authorizationList: SignAuthorizationReturnType | AuthorizationListEntryAny[], to?: string, value?: bigint | number, data?: string, nonce?: number) => Promise<string>;
7
+ export declare const serializeEip7702: (tx: any, _sig: null | ethers.Signature) => string;
8
+ export declare const ACCOUNT_CODE_PREFIX = "0xef0100";
9
+ export declare const isAccountDelegatedToAddress: (provider: ethers.Provider, account: string, authority: string) => Promise<boolean>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAccountDelegatedToAddress = exports.ACCOUNT_CODE_PREFIX = exports.serializeEip7702 = exports.getSignedTransaction = exports.getAuthorizationList = exports.encodeRLPAuthorizationEntryUnsigned = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const formatNumber = (_value) => {
6
+ const value = typeof _value === "bigint" ? _value : BigInt(_value);
7
+ // Convert bigint to hex string, then to bytes for RLP encoding
8
+ const hexValue = ethers_1.ethers.toBeHex(value);
9
+ return ethers_1.ethers.getBytes(hexValue);
10
+ };
11
+ const encodeRLPAuthorizationEntryUnsigned = (chainId, address, nonce) => {
12
+ // MAGIC = "0x05" defined in ERC-7702
13
+ return ethers_1.ethers.concat([
14
+ "0x05",
15
+ ethers_1.ethers.encodeRlp([formatNumber(chainId), address, formatNumber(nonce)]),
16
+ ]);
17
+ };
18
+ exports.encodeRLPAuthorizationEntryUnsigned = encodeRLPAuthorizationEntryUnsigned;
19
+ const getAuthorizationList = async (chainId, nonce, authorizer, signer) => {
20
+ const dataToSign = (0, exports.encodeRLPAuthorizationEntryUnsigned)(chainId, authorizer, nonce);
21
+ const authHash = ethers_1.ethers.keccak256(dataToSign);
22
+ // TODO: should be signDigest
23
+ const sig = await signer.signMessage(authHash);
24
+ // In ethers v6, splitSignature is removed, we need to parse manually
25
+ const sigBytes = ethers_1.ethers.getBytes(sig);
26
+ const r = ethers_1.ethers.hexlify(sigBytes.slice(0, 32));
27
+ const s = ethers_1.ethers.hexlify(sigBytes.slice(32, 64));
28
+ const v = sigBytes[64];
29
+ const yParity = v - 27;
30
+ return [
31
+ {
32
+ chainId: chainId,
33
+ address: authorizer,
34
+ nonce: nonce,
35
+ yParity: yParity,
36
+ r: r,
37
+ s: s,
38
+ },
39
+ ];
40
+ };
41
+ exports.getAuthorizationList = getAuthorizationList;
42
+ const getSignedTransaction = async (provider, relayer, authorizationList, to = ethers_1.ethers.ZeroAddress, value = 0, data = "0x", nonce) => {
43
+ const relayerAddress = ethers_1.ethers.computeAddress(relayer.publicKey);
44
+ const relayerNonce = nonce || (await provider.getTransactionCount(relayerAddress));
45
+ const valueBigInt = typeof value === "bigint" ? value : BigInt(value);
46
+ const tx = {
47
+ from: relayerAddress,
48
+ nonce: relayerNonce,
49
+ gasLimit: 21000000,
50
+ gasPrice: 3100,
51
+ data: data,
52
+ to: to,
53
+ value: valueBigInt,
54
+ chainId: (await provider.getNetwork()).chainId,
55
+ type: 4,
56
+ maxFeePerGas: 30000,
57
+ maxPriorityFeePerGas: 30000,
58
+ accessList: [],
59
+ authorizationList: authorizationList,
60
+ };
61
+ const encodedTx = (0, exports.serializeEip7702)(tx, null);
62
+ const txHashToSign = ethers_1.ethers.keccak256(encodedTx);
63
+ const signature = relayer.sign(txHashToSign);
64
+ return (0, exports.serializeEip7702)(tx, signature);
65
+ };
66
+ exports.getSignedTransaction = getSignedTransaction;
67
+ const serializeEip7702 = (tx, _sig) => {
68
+ const fields = [
69
+ formatNumber(tx.chainId),
70
+ formatNumber(tx.nonce),
71
+ formatNumber(tx.maxPriorityFeePerGas || 0),
72
+ formatNumber(tx.maxFeePerGas || 0),
73
+ formatNumber(tx.gasLimit),
74
+ tx.to,
75
+ formatNumber(tx.value),
76
+ tx.data,
77
+ formatAccessList(tx.accessList || []),
78
+ formatAuthorizationList(tx.authorizationList || []),
79
+ ];
80
+ if (_sig) {
81
+ // In ethers v6, Signature object has r, s, v properties
82
+ const yParity = _sig.v - 27;
83
+ fields.push(formatNumber(yParity));
84
+ fields.push(ethers_1.ethers.getBytes(_sig.r));
85
+ fields.push(ethers_1.ethers.getBytes(_sig.s));
86
+ }
87
+ return ethers_1.ethers.concat(["0x04", ethers_1.ethers.encodeRlp(fields)]);
88
+ };
89
+ exports.serializeEip7702 = serializeEip7702;
90
+ const formatAccessList = (value) => {
91
+ return ethers_1.ethers
92
+ .accessListify(value)
93
+ .map((set) => [set.address, set.storageKeys]);
94
+ };
95
+ const formatAuthorizationList = (value) => {
96
+ return value.map((set) => formatAuthorizationEntry(set));
97
+ };
98
+ const formatAuthorizationEntry = (set) => {
99
+ return [
100
+ formatNumber(set.chainId),
101
+ set.address,
102
+ formatNumber(set.nonce),
103
+ formatNumber(set.yParity),
104
+ ethers_1.ethers.getBytes(set.r),
105
+ ethers_1.ethers.getBytes(set.s),
106
+ ];
107
+ };
108
+ exports.ACCOUNT_CODE_PREFIX = "0xef0100";
109
+ const isAccountDelegatedToAddress = async (provider, account, authority) => {
110
+ const codeAtEOA = await provider.getCode(account);
111
+ return (codeAtEOA.length === 48 &&
112
+ codeAtEOA.startsWith(exports.ACCOUNT_CODE_PREFIX) &&
113
+ ethers_1.ethers.getAddress("0x" + codeAtEOA.slice(8)) === authority);
114
+ };
115
+ exports.isAccountDelegatedToAddress = isAccountDelegatedToAddress;