@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.
- package/README.md +1 -0
- package/dist/constants/compact.d.ts +1 -0
- package/dist/constants/compact.js +5 -0
- package/dist/constants/contractAddresses.d.ts +57 -0
- package/dist/constants/contractAddresses.js +181 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +18 -0
- package/dist/data/epochgraphmainnet.json +410 -0
- package/dist/data/epochgraphtestnet.json +532 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/data/index.js +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/types/index.d.ts +322 -0
- package/dist/types/index.js +37 -0
- package/dist/utils/compact.d.ts +4 -0
- package/dist/utils/compact.js +58 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/web3.d.ts +9 -0
- package/dist/utils/web3.js +115 -0
- package/dist/web3/abis/COMPACT_ABI.json +1529 -0
- package/dist/web3/abis/epochModuleAbi.d.ts +2 -0
- package/dist/web3/abis/epochModuleAbi.js +233 -0
- package/dist/web3/abis/erc20Abi.d.ts +2 -0
- package/dist/web3/abis/erc20Abi.js +224 -0
- package/dist/web3/abis/intentRegistryAbi.d.ts +2 -0
- package/dist/web3/abis/intentRegistryAbi.js +925 -0
- package/dist/web3/abis/safe7702ProxyFactoryAbi.d.ts +2 -0
- package/dist/web3/abis/safe7702ProxyFactoryAbi.js +107 -0
- package/dist/web3/abis/safeProxyFactoryAbi.d.ts +2 -0
- package/dist/web3/abis/safeProxyFactoryAbi.js +3 -0
- package/dist/web3/abis/solverRegistryAbi.d.ts +2 -0
- package/dist/web3/abis/solverRegistryAbi.js +236 -0
- package/dist/web3/index.d.ts +3 -0
- package/dist/web3/index.js +23 -0
- package/dist/web3/intents.d.ts +5 -0
- package/dist/web3/intents.js +32 -0
- package/dist/web3/registry.d.ts +5 -0
- package/dist/web3/registry.js +29 -0
- package/dist/web3/wallet.d.ts +26 -0
- package/dist/web3/wallet.js +390 -0
- package/package.json +41 -0
|
@@ -0,0 +1,390 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.validationEpochModuleSafeSignature = exports.getProxyAddressFromReceipt = exports.set7702DelegatorFromAuthorizationListManually = exports.set7702DelegatorManually = exports.set7702DelegatorFromAuthorizationList = exports.set7702Delegator = exports.getCreateWalletData = exports.getMetamaskDelegatorInstance = exports.calculateProxyAddress = exports.getSafeProxyFactoryInstance = void 0;
|
|
40
|
+
const ethers_1 = require("ethers");
|
|
41
|
+
const viem_1 = require("viem");
|
|
42
|
+
const accounts_1 = require("viem/accounts");
|
|
43
|
+
const chains = __importStar(require("viem/chains"));
|
|
44
|
+
const constants_1 = require("../constants");
|
|
45
|
+
const web3_1 = require("../utils/web3");
|
|
46
|
+
const types_1 = require("../types");
|
|
47
|
+
const web3_2 = require("../web3");
|
|
48
|
+
const safe7702ProxyFactoryAbi_1 = __importDefault(require("./abis/safe7702ProxyFactoryAbi"));
|
|
49
|
+
const safeProxyFactoryAbi_1 = __importDefault(require("./abis/safeProxyFactoryAbi"));
|
|
50
|
+
const delegation_toolkit_1 = require("@metamask/delegation-toolkit");
|
|
51
|
+
const epochModuleAbi_1 = __importDefault(require("./abis/epochModuleAbi"));
|
|
52
|
+
const getSafeProxyFactoryInstance = (chainId, is7702) => {
|
|
53
|
+
const provider = new ethers_1.ethers.JsonRpcProvider(constants_1.RPC_ENDPOINTS[chainId]);
|
|
54
|
+
return new ethers_1.ethers.Contract(is7702
|
|
55
|
+
? constants_1.EIP7702_SAFE_PROXY_ADDRESS[chainId]
|
|
56
|
+
: constants_1.SAFE_PROXY_FACTORY_ADDRESS[chainId], is7702 ? safe7702ProxyFactoryAbi_1.default : safeProxyFactoryAbi_1.default, provider);
|
|
57
|
+
};
|
|
58
|
+
exports.getSafeProxyFactoryInstance = getSafeProxyFactoryInstance;
|
|
59
|
+
const calculateProxyAddress = async (walletType, options) => {
|
|
60
|
+
if (walletType === types_1.WalletType.metamask) {
|
|
61
|
+
if (!options?.metamaskOptions) {
|
|
62
|
+
throw new Error("Metamask options are required");
|
|
63
|
+
}
|
|
64
|
+
const delegatorSmartAccount = await (0, exports.getMetamaskDelegatorInstance)(options?.metamaskOptions?.userAddress, options?.metamaskOptions?.userSigner);
|
|
65
|
+
return delegatorSmartAccount.address;
|
|
66
|
+
}
|
|
67
|
+
else if (walletType === types_1.WalletType.safe) {
|
|
68
|
+
if (!options?.safeOptions) {
|
|
69
|
+
throw new Error("Safe options are required");
|
|
70
|
+
}
|
|
71
|
+
const salt = ethers_1.ethers.solidityPackedKeccak256(["bytes32", "uint256"], [
|
|
72
|
+
ethers_1.ethers.solidityPackedKeccak256(["bytes"], [options.safeOptions.inititalizer]),
|
|
73
|
+
options.safeOptions.nonce,
|
|
74
|
+
]);
|
|
75
|
+
const factoryAddress = typeof options.safeOptions.factory.target === "string"
|
|
76
|
+
? options.safeOptions.factory.target
|
|
77
|
+
: await options.safeOptions.factory.target;
|
|
78
|
+
const proxyCreationCode = await options.safeOptions.factory.proxyCreationCode();
|
|
79
|
+
const deploymentCode = ethers_1.ethers.solidityPacked(["bytes", "uint256"], [proxyCreationCode, options.safeOptions.singleton]);
|
|
80
|
+
return ethers_1.ethers.getCreate2Address(factoryAddress, salt, ethers_1.ethers.keccak256(deploymentCode));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error("Invalid wallet type");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
exports.calculateProxyAddress = calculateProxyAddress;
|
|
87
|
+
const getMetamaskDelegatorInstance = async (userAddress, userSigner, is7702, isPasskey, passkey) => {
|
|
88
|
+
const walletClientwithPublic = userSigner.extend(viem_1.publicActions);
|
|
89
|
+
const deployParams = [userAddress, [], [], []];
|
|
90
|
+
if (is7702) {
|
|
91
|
+
return await (0, delegation_toolkit_1.toMetaMaskSmartAccount)({
|
|
92
|
+
client: walletClientwithPublic,
|
|
93
|
+
implementation: delegation_toolkit_1.Implementation.Stateless7702,
|
|
94
|
+
address: userAddress,
|
|
95
|
+
signatory: { walletClient: walletClientwithPublic },
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (isPasskey) {
|
|
99
|
+
return await (0, delegation_toolkit_1.toMetaMaskSmartAccount)({
|
|
100
|
+
client: walletClientwithPublic,
|
|
101
|
+
implementation: delegation_toolkit_1.Implementation.Hybrid,
|
|
102
|
+
deployParams: [
|
|
103
|
+
userAddress,
|
|
104
|
+
[passkey.credential.id],
|
|
105
|
+
[passkey.publicKey.x],
|
|
106
|
+
[passkey.publicKey.y],
|
|
107
|
+
],
|
|
108
|
+
deploySalt: "0x",
|
|
109
|
+
signatory: {
|
|
110
|
+
webAuthnAccount: passkey.webAuthnAccount,
|
|
111
|
+
keyId: (0, viem_1.toHex)(passkey.credential.id),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return await (0, delegation_toolkit_1.toMetaMaskSmartAccount)({
|
|
116
|
+
client: walletClientwithPublic,
|
|
117
|
+
implementation: delegation_toolkit_1.Implementation.Hybrid,
|
|
118
|
+
deployParams: deployParams,
|
|
119
|
+
deploySalt: "0x",
|
|
120
|
+
signatory: { walletClient: walletClientwithPublic },
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
exports.getMetamaskDelegatorInstance = getMetamaskDelegatorInstance;
|
|
124
|
+
const getCreateWalletData = async (userAddress, chainId, walletType, options) => {
|
|
125
|
+
console.log("walletType: ", walletType);
|
|
126
|
+
if (walletType === types_1.WalletType.metamask) {
|
|
127
|
+
console.log("WalletType.metamask: ", types_1.WalletType.metamask);
|
|
128
|
+
if (!options?.userSigner) {
|
|
129
|
+
throw new Error("only viem Client supported for Metamask");
|
|
130
|
+
}
|
|
131
|
+
const delegatorSmartAccount = await (0, exports.getMetamaskDelegatorInstance)(userAddress, options?.userSigner, options.is7702);
|
|
132
|
+
console.log("delegatorSmartAccount: ", delegatorSmartAccount);
|
|
133
|
+
const deployParams = [userAddress, [], [], []];
|
|
134
|
+
console.log("deployParams: ", deployParams);
|
|
135
|
+
return {
|
|
136
|
+
txnData: {
|
|
137
|
+
target: delegatorSmartAccount.address,
|
|
138
|
+
data: "0x",
|
|
139
|
+
value: "0",
|
|
140
|
+
},
|
|
141
|
+
proxyAddress: delegatorSmartAccount.address,
|
|
142
|
+
initializerData: (0, viem_1.encodeFunctionData)({
|
|
143
|
+
abi: delegatorSmartAccount.abi,
|
|
144
|
+
functionName: "initialize",
|
|
145
|
+
args: deployParams,
|
|
146
|
+
}),
|
|
147
|
+
isAlreadyDeployed: await delegatorSmartAccount.isDeployed(),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else if (walletType === types_1.WalletType.safe) {
|
|
151
|
+
const { is7702 } = { ...options };
|
|
152
|
+
const abiCoder = new ethers_1.ethers.AbiCoder();
|
|
153
|
+
let safeOwners = [userAddress];
|
|
154
|
+
const salt = 123665432;
|
|
155
|
+
const safeInitSetupABI = [
|
|
156
|
+
"function forwardSetup(address safeInitSetup, bool triggerFaucet, bytes extraData)",
|
|
157
|
+
];
|
|
158
|
+
const safeInitSetupInterface = new ethers_1.ethers.Interface(safeInitSetupABI);
|
|
159
|
+
let extraData = "0x";
|
|
160
|
+
if (options?.passkey) {
|
|
161
|
+
safeOwners = [constants_1.SAFE_WEBAUTHN_SHARED_SIGNER[chainId]];
|
|
162
|
+
const signer = {
|
|
163
|
+
x: options?.passkey?.publicKey.x,
|
|
164
|
+
y: options?.passkey?.publicKey.y,
|
|
165
|
+
verifiers: constants_1.FCLP256Verifier[chainId],
|
|
166
|
+
};
|
|
167
|
+
const signerData = abiCoder.encode(["tuple(bytes32 x, bytes32 y, uint176 verifiers)"], [
|
|
168
|
+
{
|
|
169
|
+
x: signer.x,
|
|
170
|
+
y: signer.y,
|
|
171
|
+
verifiers: signer.verifiers,
|
|
172
|
+
},
|
|
173
|
+
]);
|
|
174
|
+
extraData = signerData;
|
|
175
|
+
}
|
|
176
|
+
const safeInitSetupData = safeInitSetupInterface.encodeFunctionData("forwardSetup", [constants_1.EPOCH_SAFE_INIT_SETUP[chainId], true, extraData]);
|
|
177
|
+
const safeSetupABI = [
|
|
178
|
+
"function setup(address[] calldata _owners, uint256 _threshold, address to, bytes calldata data, address fallbackHandler, address paymentToken, uint256 payment, address payable paymentReceiver)",
|
|
179
|
+
];
|
|
180
|
+
const safeSetupInterface = new ethers_1.ethers.Interface(safeSetupABI);
|
|
181
|
+
const initializerData = safeSetupInterface.encodeFunctionData("setup", [
|
|
182
|
+
safeOwners,
|
|
183
|
+
1,
|
|
184
|
+
constants_1.SAFE_INIT_SETUP_FORWARDER[chainId],
|
|
185
|
+
safeInitSetupData,
|
|
186
|
+
ethers_1.ethers.ZeroAddress,
|
|
187
|
+
ethers_1.ethers.ZeroAddress,
|
|
188
|
+
0,
|
|
189
|
+
ethers_1.ethers.ZeroAddress,
|
|
190
|
+
]);
|
|
191
|
+
const safeEIP7702ProxyFactory = (0, exports.getSafeProxyFactoryInstance)(chainId, true);
|
|
192
|
+
const proxyFactory = (0, exports.getSafeProxyFactoryInstance)(chainId);
|
|
193
|
+
const proxyAddress = await (0, exports.calculateProxyAddress)(walletType, {
|
|
194
|
+
safeOptions: {
|
|
195
|
+
factory: is7702 ? safeEIP7702ProxyFactory : proxyFactory,
|
|
196
|
+
singleton: is7702
|
|
197
|
+
? constants_1.SAFE_7702_SINGLETON_ADDRESS[chainId]
|
|
198
|
+
: constants_1.SAFE_SINGLETON_ADDRESS[chainId],
|
|
199
|
+
inititalizer: initializerData,
|
|
200
|
+
nonce: salt,
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
if (!proxyAddress) {
|
|
204
|
+
throw new Error("Failed to calculate proxy address");
|
|
205
|
+
}
|
|
206
|
+
const provider = (0, web3_2.getProvider)(chainId);
|
|
207
|
+
const isContract = await provider.getCode(proxyAddress);
|
|
208
|
+
if (isContract !== "0x") {
|
|
209
|
+
return {
|
|
210
|
+
txnData: {
|
|
211
|
+
target: "",
|
|
212
|
+
data: "",
|
|
213
|
+
value: "0",
|
|
214
|
+
},
|
|
215
|
+
proxyAddress,
|
|
216
|
+
initializerData,
|
|
217
|
+
isAlreadyDeployed: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (is7702) {
|
|
221
|
+
const proxyData = await safeEIP7702ProxyFactory.createProxyWithNonce.populateTransaction(constants_1.SAFE_7702_SINGLETON_ADDRESS[chainId], initializerData, salt);
|
|
222
|
+
if (!proxyData.data) {
|
|
223
|
+
throw new Error("Failed to create proxy data");
|
|
224
|
+
}
|
|
225
|
+
const factoryTarget = typeof safeEIP7702ProxyFactory.target === "string"
|
|
226
|
+
? safeEIP7702ProxyFactory.target
|
|
227
|
+
: await safeEIP7702ProxyFactory.target;
|
|
228
|
+
return {
|
|
229
|
+
txnData: {
|
|
230
|
+
target: factoryTarget,
|
|
231
|
+
data: proxyData.data,
|
|
232
|
+
value: "0",
|
|
233
|
+
},
|
|
234
|
+
proxyAddress,
|
|
235
|
+
initializerData,
|
|
236
|
+
isAlreadyDeployed: false,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const proxyData = await proxyFactory.createProxyWithNonce.populateTransaction(constants_1.SAFE_SINGLETON_ADDRESS[chainId], initializerData, salt);
|
|
241
|
+
if (!proxyData.data) {
|
|
242
|
+
throw new Error("Failed to create proxy data");
|
|
243
|
+
}
|
|
244
|
+
const factoryTarget = typeof proxyFactory.target === "string"
|
|
245
|
+
? proxyFactory.target
|
|
246
|
+
: await proxyFactory.target;
|
|
247
|
+
return {
|
|
248
|
+
txnData: {
|
|
249
|
+
target: factoryTarget,
|
|
250
|
+
data: proxyData.data,
|
|
251
|
+
value: "0",
|
|
252
|
+
},
|
|
253
|
+
proxyAddress,
|
|
254
|
+
initializerData,
|
|
255
|
+
isAlreadyDeployed: false,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
throw new Error("Invalid wallet type");
|
|
260
|
+
};
|
|
261
|
+
exports.getCreateWalletData = getCreateWalletData;
|
|
262
|
+
const set7702Delegator = async (chainId, userAddress, userSafeAddress, initializerData, userWalletClient, relayer) => {
|
|
263
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
264
|
+
transport: (0, viem_1.http)(constants_1.RPC_ENDPOINTS[chainId]),
|
|
265
|
+
});
|
|
266
|
+
const account = userWalletClient.account;
|
|
267
|
+
if (!account) {
|
|
268
|
+
throw new Error("Account not found");
|
|
269
|
+
}
|
|
270
|
+
const transactionCount = await publicClient.getTransactionCount({
|
|
271
|
+
address: account.address,
|
|
272
|
+
});
|
|
273
|
+
const relayerAddress = ethers_1.ethers.computeAddress(relayer.publicKey);
|
|
274
|
+
let authorizationList;
|
|
275
|
+
if (account.address === relayerAddress) {
|
|
276
|
+
authorizationList = await userWalletClient.signAuthorization({
|
|
277
|
+
account: account,
|
|
278
|
+
contractAddress: userSafeAddress,
|
|
279
|
+
chainId: chainId,
|
|
280
|
+
executor: "self",
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
authorizationList = await userWalletClient.signAuthorization({
|
|
285
|
+
account: account,
|
|
286
|
+
contractAddress: userSafeAddress,
|
|
287
|
+
nonce: transactionCount,
|
|
288
|
+
chainId: chainId,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (!authorizationList) {
|
|
292
|
+
throw new Error("Failed to sign authorization for 7702 delegator");
|
|
293
|
+
}
|
|
294
|
+
await (0, exports.set7702DelegatorFromAuthorizationList)(chainId, userAddress, authorizationList, initializerData, relayer);
|
|
295
|
+
};
|
|
296
|
+
exports.set7702Delegator = set7702Delegator;
|
|
297
|
+
const set7702DelegatorFromAuthorizationList = async (chainId, userAddress, authorizationList, initializerData, relayer) => {
|
|
298
|
+
const chain = (0, viem_1.extractChain)({
|
|
299
|
+
chains: Object.values(chains),
|
|
300
|
+
id: chainId,
|
|
301
|
+
});
|
|
302
|
+
const account = (0, accounts_1.privateKeyToAccount)(relayer.privateKey);
|
|
303
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
304
|
+
transport: (0, viem_1.http)(constants_1.RPC_ENDPOINTS[chainId]),
|
|
305
|
+
chain,
|
|
306
|
+
});
|
|
307
|
+
const relayerWalletClient = (0, viem_1.createWalletClient)({
|
|
308
|
+
account,
|
|
309
|
+
transport: (0, viem_1.http)(constants_1.RPC_ENDPOINTS[chainId]),
|
|
310
|
+
chain,
|
|
311
|
+
});
|
|
312
|
+
const hash = await relayerWalletClient.sendTransaction({
|
|
313
|
+
account,
|
|
314
|
+
chain: chain,
|
|
315
|
+
to: userAddress,
|
|
316
|
+
data: initializerData,
|
|
317
|
+
value: BigInt(0),
|
|
318
|
+
authorizationList: [authorizationList],
|
|
319
|
+
});
|
|
320
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
321
|
+
hash: hash,
|
|
322
|
+
});
|
|
323
|
+
if (receipt.status !== "success") {
|
|
324
|
+
throw new Error("Failed to set 7702 delegator");
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
exports.set7702DelegatorFromAuthorizationList = set7702DelegatorFromAuthorizationList;
|
|
328
|
+
const set7702DelegatorManually = async (chainId, userAddress, userSafeAddress, userSigner, relayer, initializerData) => {
|
|
329
|
+
const provider = (0, web3_2.getProvider)(chainId);
|
|
330
|
+
const authNonce = await provider.getTransactionCount(userAddress, "pending");
|
|
331
|
+
const authAddress = userSafeAddress;
|
|
332
|
+
const authorizationList = await (0, web3_1.getAuthorizationList)(chainId, BigInt(authNonce), authAddress, userSigner);
|
|
333
|
+
await (0, exports.set7702DelegatorFromAuthorizationListManually)(chainId, userAddress, userSafeAddress, authorizationList, initializerData, relayer);
|
|
334
|
+
return true;
|
|
335
|
+
};
|
|
336
|
+
exports.set7702DelegatorManually = set7702DelegatorManually;
|
|
337
|
+
const set7702DelegatorFromAuthorizationListManually = async (chainId, userAddress, userSafeAddress, authorizationList, initializerData, relayer) => {
|
|
338
|
+
try {
|
|
339
|
+
const provider = (0, web3_2.getProvider)(chainId);
|
|
340
|
+
const encodedSignedTx = await (0, web3_1.getSignedTransaction)(provider, relayer, authorizationList);
|
|
341
|
+
const authAddress = userSafeAddress;
|
|
342
|
+
const isAlreadyDelegated = await (0, web3_1.isAccountDelegatedToAddress)(provider, userAddress, authAddress);
|
|
343
|
+
if (isAlreadyDelegated &&
|
|
344
|
+
(await provider.getStorage(userAddress, 4)) ==
|
|
345
|
+
ethers_1.ethers.zeroPadValue("0x01", 32)) {
|
|
346
|
+
throw new Error("Account already delegated to Safe Proxy and storage is setup. Returning");
|
|
347
|
+
}
|
|
348
|
+
const response = await provider.send("eth_sendRawTransaction", [
|
|
349
|
+
encodedSignedTx,
|
|
350
|
+
]);
|
|
351
|
+
await (await provider.getTransaction(response))?.wait();
|
|
352
|
+
const relayerWallet = new ethers_1.ethers.Wallet(relayer.privateKey, provider);
|
|
353
|
+
const setupTxResponse = await relayerWallet.sendTransaction({
|
|
354
|
+
to: userAddress,
|
|
355
|
+
data: initializerData,
|
|
356
|
+
});
|
|
357
|
+
await setupTxResponse.wait();
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
exports.set7702DelegatorFromAuthorizationListManually = set7702DelegatorFromAuthorizationListManually;
|
|
364
|
+
const getProxyAddressFromReceipt = (txnReceipt) => {
|
|
365
|
+
const proxyCreationEvent = `event ProxyCreation(address indexed proxy, address singleton)`;
|
|
366
|
+
const proxyCreationEventAbi = new ethers_1.ethers.Interface([proxyCreationEvent]);
|
|
367
|
+
let proxyAddress;
|
|
368
|
+
for (const log of txnReceipt.logs) {
|
|
369
|
+
try {
|
|
370
|
+
const parsedLog = proxyCreationEventAbi.parseLog(log);
|
|
371
|
+
if (parsedLog && parsedLog.name === "ProxyCreation") {
|
|
372
|
+
proxyAddress = parsedLog.args.proxy;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch (e) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return proxyAddress;
|
|
381
|
+
};
|
|
382
|
+
exports.getProxyAddressFromReceipt = getProxyAddressFromReceipt;
|
|
383
|
+
const validationEpochModuleSafeSignature = async (sender, data, signature) => {
|
|
384
|
+
const epochModule = constants_1.EPOCH_MODULE_SAFE_ADDRESS[constants_1.DEFAULT_CHAIN_ID];
|
|
385
|
+
const provider = (0, web3_2.getProvider)(constants_1.DEFAULT_CHAIN_ID);
|
|
386
|
+
const epochModuleInstance = new ethers_1.ethers.Contract(epochModule, epochModuleAbi_1.default, provider);
|
|
387
|
+
const isValid = await epochModuleInstance.verifySignature(sender, data, signature);
|
|
388
|
+
return isValid;
|
|
389
|
+
};
|
|
390
|
+
exports.validationEpochModuleSafeSignature = validationEpochModuleSafeSignature;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@epoch-protocol/epoch-commons-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK for interacting with Epoch Commons Protocol",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"lint": "eslint . --ext .ts",
|
|
11
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
12
|
+
"prepare": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"blockchain",
|
|
16
|
+
"ethereum",
|
|
17
|
+
"viem",
|
|
18
|
+
"sdk"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ethers": "^6.0.0",
|
|
24
|
+
"viem": "2.42.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^29.5.14",
|
|
28
|
+
"@types/node": "^20.11.19",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
30
|
+
"@typescript-eslint/parser": "^7.0.1",
|
|
31
|
+
"eslint": "^8.56.0",
|
|
32
|
+
"jest": "^29.7.0",
|
|
33
|
+
"prettier": "^3.2.5",
|
|
34
|
+
"ts-jest": "^29.1.2",
|
|
35
|
+
"typescript": "^5.3.3"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md"
|
|
40
|
+
]
|
|
41
|
+
}
|