@cowprotocol/sdk-cow-shed 0.1.10 → 0.2.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/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -2
- package/dist/index.mjs +22 -3
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -63,6 +63,8 @@ declare class CowShedHooks {
|
|
|
63
63
|
private chainId;
|
|
64
64
|
private customOptions?;
|
|
65
65
|
readonly version: CoWShedVersion;
|
|
66
|
+
private eip1271SignatureCache;
|
|
67
|
+
private accountCodeCache;
|
|
66
68
|
constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
|
|
67
69
|
proxyOf(user: string): string;
|
|
68
70
|
encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ declare class CowShedHooks {
|
|
|
63
63
|
private chainId;
|
|
64
64
|
private customOptions?;
|
|
65
65
|
readonly version: CoWShedVersion;
|
|
66
|
+
private eip1271SignatureCache;
|
|
67
|
+
private accountCodeCache;
|
|
66
68
|
constructor(chainId: SupportedChainId, customOptions?: ICoWShedOptions | undefined, version?: CoWShedVersion, adapter?: AbstractProviderAdapter);
|
|
67
69
|
proxyOf(user: string): string;
|
|
68
70
|
encodeExecuteHooksForFactory(calls: ICoWShedCall[], nonce: string, deadline: bigint, ownerAddress: string, signature: string): string;
|
package/dist/index.js
CHANGED
|
@@ -234,6 +234,7 @@ var COW_SHED_712_TYPES = {
|
|
|
234
234
|
{ type: "bool", name: "isDelegateCall" }
|
|
235
235
|
]
|
|
236
236
|
};
|
|
237
|
+
var FIVE_MINUTES = 5 * 60 * 1e3;
|
|
237
238
|
var CowShedHooks = class {
|
|
238
239
|
constructor(chainId, customOptions, version = COW_SHED_LATEST_VERSION, adapter) {
|
|
239
240
|
this.chainId = chainId;
|
|
@@ -242,7 +243,11 @@ var CowShedHooks = class {
|
|
|
242
243
|
if (adapter) {
|
|
243
244
|
(0, import_sdk_common.setGlobalAdapter)(adapter);
|
|
244
245
|
}
|
|
246
|
+
this.eip1271SignatureCache = new import_sdk_common.TTLCache("cowshed-eip1271-signature", true, FIVE_MINUTES);
|
|
247
|
+
this.accountCodeCache = new import_sdk_common.TTLCache("cowshed-account-code", true, FIVE_MINUTES);
|
|
245
248
|
}
|
|
249
|
+
eip1271SignatureCache;
|
|
250
|
+
accountCodeCache;
|
|
246
251
|
proxyOf(user) {
|
|
247
252
|
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
248
253
|
const salt = adapter.utils.encodeAbi(["address"], [user]);
|
|
@@ -294,6 +299,11 @@ var CowShedHooks = class {
|
|
|
294
299
|
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
295
300
|
const { domain, types, message } = typedDataContext;
|
|
296
301
|
const hash = adapter.utils.hashTypedData(domain, types, message);
|
|
302
|
+
const cacheKey = `${account}:${signature}:${hash}`;
|
|
303
|
+
const cachedResult = this.eip1271SignatureCache.get(cacheKey);
|
|
304
|
+
if (cachedResult !== void 0) {
|
|
305
|
+
return cachedResult;
|
|
306
|
+
}
|
|
297
307
|
try {
|
|
298
308
|
const result = await adapter.readContract({
|
|
299
309
|
address: account,
|
|
@@ -301,7 +311,9 @@ var CowShedHooks = class {
|
|
|
301
311
|
functionName: "isValidSignature",
|
|
302
312
|
args: [hash, signature]
|
|
303
313
|
});
|
|
304
|
-
|
|
314
|
+
const isValid = result === import_sdk_contracts_ts.EIP1271_MAGICVALUE;
|
|
315
|
+
this.eip1271SignatureCache.set(cacheKey, isValid);
|
|
316
|
+
return isValid;
|
|
305
317
|
} catch (error) {
|
|
306
318
|
console.error("CoWShedHooks.verifyEip1271Signature", error);
|
|
307
319
|
return false;
|
|
@@ -333,9 +345,15 @@ var CowShedHooks = class {
|
|
|
333
345
|
return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
|
|
334
346
|
}
|
|
335
347
|
async doesAccountHaveCode(account) {
|
|
348
|
+
const cachedResult = this.accountCodeCache.get(account);
|
|
349
|
+
if (cachedResult !== void 0) {
|
|
350
|
+
return cachedResult;
|
|
351
|
+
}
|
|
336
352
|
const adapter = (0, import_sdk_common.getGlobalAdapter)();
|
|
337
353
|
const userAccountCode = await adapter.getCode(account);
|
|
338
|
-
|
|
354
|
+
const hasCode = !!userAccountCode && userAccountCode !== "0x";
|
|
355
|
+
this.accountCodeCache.set(account, hasCode);
|
|
356
|
+
return hasCode;
|
|
339
357
|
}
|
|
340
358
|
};
|
|
341
359
|
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
} from "@cowprotocol/sdk-contracts-ts";
|
|
7
7
|
import {
|
|
8
8
|
getGlobalAdapter,
|
|
9
|
-
setGlobalAdapter
|
|
9
|
+
setGlobalAdapter,
|
|
10
|
+
TTLCache
|
|
10
11
|
} from "@cowprotocol/sdk-common";
|
|
11
12
|
|
|
12
13
|
// src/abi/CowShedFactoryAbi.ts
|
|
@@ -205,6 +206,7 @@ var COW_SHED_712_TYPES = {
|
|
|
205
206
|
{ type: "bool", name: "isDelegateCall" }
|
|
206
207
|
]
|
|
207
208
|
};
|
|
209
|
+
var FIVE_MINUTES = 5 * 60 * 1e3;
|
|
208
210
|
var CowShedHooks = class {
|
|
209
211
|
constructor(chainId, customOptions, version = COW_SHED_LATEST_VERSION, adapter) {
|
|
210
212
|
this.chainId = chainId;
|
|
@@ -213,7 +215,11 @@ var CowShedHooks = class {
|
|
|
213
215
|
if (adapter) {
|
|
214
216
|
setGlobalAdapter(adapter);
|
|
215
217
|
}
|
|
218
|
+
this.eip1271SignatureCache = new TTLCache("cowshed-eip1271-signature", true, FIVE_MINUTES);
|
|
219
|
+
this.accountCodeCache = new TTLCache("cowshed-account-code", true, FIVE_MINUTES);
|
|
216
220
|
}
|
|
221
|
+
eip1271SignatureCache;
|
|
222
|
+
accountCodeCache;
|
|
217
223
|
proxyOf(user) {
|
|
218
224
|
const adapter = getGlobalAdapter();
|
|
219
225
|
const salt = adapter.utils.encodeAbi(["address"], [user]);
|
|
@@ -265,6 +271,11 @@ var CowShedHooks = class {
|
|
|
265
271
|
const adapter = getGlobalAdapter();
|
|
266
272
|
const { domain, types, message } = typedDataContext;
|
|
267
273
|
const hash = adapter.utils.hashTypedData(domain, types, message);
|
|
274
|
+
const cacheKey = `${account}:${signature}:${hash}`;
|
|
275
|
+
const cachedResult = this.eip1271SignatureCache.get(cacheKey);
|
|
276
|
+
if (cachedResult !== void 0) {
|
|
277
|
+
return cachedResult;
|
|
278
|
+
}
|
|
268
279
|
try {
|
|
269
280
|
const result = await adapter.readContract({
|
|
270
281
|
address: account,
|
|
@@ -272,7 +283,9 @@ var CowShedHooks = class {
|
|
|
272
283
|
functionName: "isValidSignature",
|
|
273
284
|
args: [hash, signature]
|
|
274
285
|
});
|
|
275
|
-
|
|
286
|
+
const isValid = result === EIP1271_MAGICVALUE;
|
|
287
|
+
this.eip1271SignatureCache.set(cacheKey, isValid);
|
|
288
|
+
return isValid;
|
|
276
289
|
} catch (error) {
|
|
277
290
|
console.error("CoWShedHooks.verifyEip1271Signature", error);
|
|
278
291
|
return false;
|
|
@@ -304,9 +317,15 @@ var CowShedHooks = class {
|
|
|
304
317
|
return this.customOptions?.implementationAddress ?? COW_SHED_IMPLEMENTATION[this.version];
|
|
305
318
|
}
|
|
306
319
|
async doesAccountHaveCode(account) {
|
|
320
|
+
const cachedResult = this.accountCodeCache.get(account);
|
|
321
|
+
if (cachedResult !== void 0) {
|
|
322
|
+
return cachedResult;
|
|
323
|
+
}
|
|
307
324
|
const adapter = getGlobalAdapter();
|
|
308
325
|
const userAccountCode = await adapter.getCode(account);
|
|
309
|
-
|
|
326
|
+
const hasCode = !!userAccountCode && userAccountCode !== "0x";
|
|
327
|
+
this.accountCodeCache.set(account, hasCode);
|
|
328
|
+
return hasCode;
|
|
310
329
|
}
|
|
311
330
|
};
|
|
312
331
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-cow-shed",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CowProtocol Cow Shed package",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@cowprotocol/sdk-config": "0.3.0",
|
|
18
17
|
"@cowprotocol/sdk-common": "0.3.0",
|
|
19
|
-
"@cowprotocol/sdk-
|
|
18
|
+
"@cowprotocol/sdk-config": "0.3.0",
|
|
19
|
+
"@cowprotocol/sdk-contracts-ts": "0.5.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/jest": "^29.4.0",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"tsup": "^7.2.0",
|
|
34
34
|
"tsx": "^4.19.4",
|
|
35
35
|
"typescript": "^5.2.2",
|
|
36
|
-
"@
|
|
36
|
+
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
37
37
|
"@cowprotocol/sdk-ethers-v6-adapter": "0.2.0",
|
|
38
38
|
"@cowprotocol/sdk-viem-adapter": "0.2.0",
|
|
39
|
-
"@
|
|
39
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|