@bosonprotocol/core-sdk 1.48.0-alpha.3 → 1.48.0-alpha.5
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/cjs/erc20/handler.d.ts +21 -1
- package/dist/cjs/erc20/handler.d.ts.map +1 -1
- package/dist/cjs/erc20/handler.js +59 -5
- package/dist/cjs/erc20/handler.js.map +1 -1
- package/dist/cjs/erc20/mixin.d.ts +21 -0
- package/dist/cjs/erc20/mixin.d.ts.map +1 -1
- package/dist/cjs/erc20/mixin.js +20 -0
- package/dist/cjs/erc20/mixin.js.map +1 -1
- package/dist/cjs/meta-tx/handler.d.ts.map +1 -1
- package/dist/cjs/meta-tx/handler.js +2 -2
- package/dist/cjs/meta-tx/handler.js.map +1 -1
- package/dist/esm/erc20/handler.d.ts +21 -1
- package/dist/esm/erc20/handler.d.ts.map +1 -1
- package/dist/esm/erc20/handler.js +66 -5
- package/dist/esm/erc20/handler.js.map +1 -1
- package/dist/esm/erc20/mixin.d.ts +21 -0
- package/dist/esm/erc20/mixin.d.ts.map +1 -1
- package/dist/esm/erc20/mixin.js +25 -1
- package/dist/esm/erc20/mixin.js.map +1 -1
- package/dist/esm/meta-tx/handler.d.ts.map +1 -1
- package/dist/esm/meta-tx/handler.js +3 -3
- package/dist/esm/meta-tx/handler.js.map +1 -1
- package/package.json +3 -3
- package/src/erc20/handler.ts +105 -11
- package/src/erc20/mixin.ts +59 -0
- package/src/meta-tx/handler.ts +5 -3
package/src/erc20/handler.ts
CHANGED
|
@@ -31,6 +31,10 @@ export type UnsignedTransferAuthorization =
|
|
|
31
31
|
| {
|
|
32
32
|
strategy: "Permit2";
|
|
33
33
|
data: { nonce: BigNumberish; deadline: BigNumberish };
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
strategy: "DAIPermit";
|
|
37
|
+
data: { nonce: BigNumberish; expiry: BigNumberish };
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
export type TransferAuthorization = UnsignedTransferAuthorization & {
|
|
@@ -43,10 +47,13 @@ export type TransferAuthorization = UnsignedTransferAuthorization & {
|
|
|
43
47
|
const TRANSFER_STRATEGY_ID = {
|
|
44
48
|
ERC3009: 1,
|
|
45
49
|
EIP2612: 2,
|
|
46
|
-
Permit2: 3
|
|
50
|
+
Permit2: 3,
|
|
51
|
+
DAIPermit: 4
|
|
47
52
|
} as const;
|
|
48
53
|
|
|
49
|
-
function encodeTransferAuthorizationEntry(
|
|
54
|
+
export function encodeTransferAuthorizationEntry(
|
|
55
|
+
auth: TransferAuthorization
|
|
56
|
+
): string {
|
|
50
57
|
let innerData: string;
|
|
51
58
|
switch (auth.strategy) {
|
|
52
59
|
case "ERC3009":
|
|
@@ -74,6 +81,12 @@ function encodeTransferAuthorizationEntry(auth: TransferAuthorization): string {
|
|
|
74
81
|
[auth.data.nonce, auth.data.deadline, auth.signature]
|
|
75
82
|
);
|
|
76
83
|
break;
|
|
84
|
+
case "DAIPermit":
|
|
85
|
+
innerData = defaultAbiCoder.encode(
|
|
86
|
+
["uint256", "uint256", "uint8", "bytes32", "bytes32"],
|
|
87
|
+
[auth.data.nonce, auth.data.expiry, auth.v, auth.r, auth.s]
|
|
88
|
+
);
|
|
89
|
+
break;
|
|
77
90
|
}
|
|
78
91
|
return defaultAbiCoder.encode(
|
|
79
92
|
["uint8", "bytes"],
|
|
@@ -81,15 +94,6 @@ function encodeTransferAuthorizationEntry(auth: TransferAuthorization): string {
|
|
|
81
94
|
);
|
|
82
95
|
}
|
|
83
96
|
|
|
84
|
-
export function encodeTransferAuthorizationQueue(
|
|
85
|
-
auths: TransferAuthorization[]
|
|
86
|
-
): string {
|
|
87
|
-
return defaultAbiCoder.encode(
|
|
88
|
-
["bytes[]"],
|
|
89
|
-
[auths.map(encodeTransferAuthorizationEntry)]
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
97
|
// Overload: returnTxInfo is true -> returns TransactionRequest
|
|
94
98
|
export async function approve(args: {
|
|
95
99
|
contractAddress: string;
|
|
@@ -484,3 +488,93 @@ export async function signReceiveWithPermit2(
|
|
|
484
488
|
data: { nonce: permit2Nonce, deadline: args.deadline }
|
|
485
489
|
};
|
|
486
490
|
}
|
|
491
|
+
|
|
492
|
+
type SignReceiveWithDaiPermitArgs = ApproveExchangeTokenBaseArgs & {
|
|
493
|
+
tokenDomain: { name: string };
|
|
494
|
+
expiry: BigNumberish;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// Overload: returnTypedDataToSign is true → returns StructuredData
|
|
498
|
+
export async function signReceiveWithDaiPermit(
|
|
499
|
+
args: SignReceiveWithDaiPermitArgs & { returnTypedDataToSign: true }
|
|
500
|
+
): Promise<StructuredData>;
|
|
501
|
+
// Overload: returnTypedDataToSign is false or undefined → returns TransferAuthorization (DAIPermit)
|
|
502
|
+
export async function signReceiveWithDaiPermit(
|
|
503
|
+
args: SignReceiveWithDaiPermitArgs & {
|
|
504
|
+
returnTypedDataToSign?: false | undefined;
|
|
505
|
+
}
|
|
506
|
+
): Promise<TransferAuthorization & { strategy: "DAIPermit" }>;
|
|
507
|
+
// Implementation
|
|
508
|
+
export async function signReceiveWithDaiPermit(
|
|
509
|
+
args: SignReceiveWithDaiPermitArgs & { returnTypedDataToSign?: boolean }
|
|
510
|
+
): Promise<
|
|
511
|
+
(TransferAuthorization & { strategy: "DAIPermit" }) | StructuredData
|
|
512
|
+
> {
|
|
513
|
+
const nonceResult = await args.web3Lib.call({
|
|
514
|
+
to: args.exchangeToken,
|
|
515
|
+
data: alternativeNonceIface.encodeFunctionData("nonces", [args.user])
|
|
516
|
+
});
|
|
517
|
+
const [nonce] = alternativeNonceIface.decodeFunctionResult(
|
|
518
|
+
"nonces",
|
|
519
|
+
nonceResult
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
const customSignatureType = {
|
|
523
|
+
EIP712Domain: [
|
|
524
|
+
{ name: "name", type: "string" },
|
|
525
|
+
{ name: "version", type: "string" },
|
|
526
|
+
{ name: "chainId", type: "uint256" },
|
|
527
|
+
{ name: "verifyingContract", type: "address" }
|
|
528
|
+
],
|
|
529
|
+
Permit: [
|
|
530
|
+
{ name: "holder", type: "address" },
|
|
531
|
+
{ name: "spender", type: "address" },
|
|
532
|
+
{ name: "nonce", type: "uint256" },
|
|
533
|
+
{ name: "expiry", type: "uint256" },
|
|
534
|
+
{ name: "allowed", type: "bool" }
|
|
535
|
+
]
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
const customDomainData = {
|
|
539
|
+
name: args.tokenDomain.name,
|
|
540
|
+
version: "1",
|
|
541
|
+
chainId: args.chainId,
|
|
542
|
+
salt: undefined
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
const message = {
|
|
546
|
+
holder: args.user,
|
|
547
|
+
spender: args.spender,
|
|
548
|
+
nonce: nonce.toString(),
|
|
549
|
+
expiry: args.expiry.toString(),
|
|
550
|
+
allowed: true
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
const baseParams = {
|
|
554
|
+
web3Lib: args.web3Lib,
|
|
555
|
+
chainId: args.chainId,
|
|
556
|
+
verifyingContractAddress: args.exchangeToken,
|
|
557
|
+
customSignatureType,
|
|
558
|
+
customDomainData,
|
|
559
|
+
primaryType: "Permit",
|
|
560
|
+
message
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
if (args.returnTypedDataToSign) {
|
|
564
|
+
return prepareDataSignatureParameters({
|
|
565
|
+
...baseParams,
|
|
566
|
+
returnTypedDataToSign: true
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const sig = await prepareDataSignatureParameters({
|
|
571
|
+
...baseParams,
|
|
572
|
+
returnTypedDataToSign: false
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
return {
|
|
576
|
+
...sig,
|
|
577
|
+
strategy: "DAIPermit",
|
|
578
|
+
data: { nonce: nonce.toString(), expiry: args.expiry }
|
|
579
|
+
};
|
|
580
|
+
}
|
package/src/erc20/mixin.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
signReceiveWithErc3009Authorization,
|
|
17
17
|
signReceiveWithErc2612Permit,
|
|
18
18
|
signReceiveWithPermit2,
|
|
19
|
+
signReceiveWithDaiPermit,
|
|
19
20
|
TransferAuthorization
|
|
20
21
|
} from "./handler";
|
|
21
22
|
import { StructuredData } from "../utils/signature";
|
|
@@ -326,4 +327,62 @@ export class ERC20Mixin<T extends Web3LibAdapter> extends BaseCoreSDK<T> {
|
|
|
326
327
|
returnTypedDataToSign: false
|
|
327
328
|
});
|
|
328
329
|
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Signs a DAI-style `Permit` payload authorizing the spender (default:
|
|
333
|
+
* protocol diamond) to pull `exchangeToken` from the signer up to `expiry`.
|
|
334
|
+
* Returns a `TransferAuthorization` tagged with strategy `"DAIPermit"`,
|
|
335
|
+
* ready to feed into `relayMetaTransaction` via `transferAuthorizations`.
|
|
336
|
+
*/
|
|
337
|
+
// Overload: returnTypedDataToSign is true → returns StructuredData
|
|
338
|
+
public async signReceiveWithDaiPermit(
|
|
339
|
+
exchangeToken: string,
|
|
340
|
+
tokenDomain: { name: string },
|
|
341
|
+
value: BigNumberish,
|
|
342
|
+
expiry: BigNumberish,
|
|
343
|
+
overrides: Partial<{ spender: string }> & { returnTypedDataToSign: true }
|
|
344
|
+
): Promise<StructuredData>;
|
|
345
|
+
// Overload: returnTypedDataToSign is false or undefined → returns TransferAuthorization (DAIPermit)
|
|
346
|
+
public async signReceiveWithDaiPermit(
|
|
347
|
+
exchangeToken: string,
|
|
348
|
+
tokenDomain: { name: string },
|
|
349
|
+
value: BigNumberish,
|
|
350
|
+
expiry: BigNumberish,
|
|
351
|
+
overrides?: Partial<{ spender: string; returnTypedDataToSign?: false }>
|
|
352
|
+
): Promise<TransferAuthorization & { strategy: "DAIPermit" }>;
|
|
353
|
+
// Implementation
|
|
354
|
+
public async signReceiveWithDaiPermit(
|
|
355
|
+
exchangeToken: string,
|
|
356
|
+
tokenDomain: { name: string },
|
|
357
|
+
value: BigNumberish,
|
|
358
|
+
expiry: BigNumberish,
|
|
359
|
+
overrides: Partial<{
|
|
360
|
+
spender: string;
|
|
361
|
+
returnTypedDataToSign: boolean;
|
|
362
|
+
}> = {}
|
|
363
|
+
): Promise<
|
|
364
|
+
(TransferAuthorization & { strategy: "DAIPermit" }) | StructuredData
|
|
365
|
+
> {
|
|
366
|
+
const user = await this._web3Lib.getSignerAddress();
|
|
367
|
+
const baseArgs = {
|
|
368
|
+
web3Lib: this._web3Lib,
|
|
369
|
+
chainId: this._chainId,
|
|
370
|
+
user,
|
|
371
|
+
exchangeToken,
|
|
372
|
+
spender: overrides.spender || this._protocolDiamond,
|
|
373
|
+
value,
|
|
374
|
+
tokenDomain,
|
|
375
|
+
expiry
|
|
376
|
+
};
|
|
377
|
+
if (overrides.returnTypedDataToSign) {
|
|
378
|
+
return signReceiveWithDaiPermit({
|
|
379
|
+
...baseArgs,
|
|
380
|
+
returnTypedDataToSign: true
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return signReceiveWithDaiPermit({
|
|
384
|
+
...baseArgs,
|
|
385
|
+
returnTypedDataToSign: false
|
|
386
|
+
});
|
|
387
|
+
}
|
|
329
388
|
}
|
package/src/meta-tx/handler.ts
CHANGED
|
@@ -70,7 +70,7 @@ import { id } from "@ethersproject/hash";
|
|
|
70
70
|
import { defaultAbiCoder } from "@ethersproject/abi";
|
|
71
71
|
import {
|
|
72
72
|
TransferAuthorization,
|
|
73
|
-
|
|
73
|
+
encodeTransferAuthorizationEntry
|
|
74
74
|
} from "../erc20/handler";
|
|
75
75
|
import { ERC20ForwardRequest } from "../forwarder/biconomy-interface";
|
|
76
76
|
import { getNonce, verifyEIP712 } from "../forwarder/handler";
|
|
@@ -2182,7 +2182,9 @@ export async function relayMetaTransaction(args: {
|
|
|
2182
2182
|
const params = metaTx.params.transferAuthorizations?.length
|
|
2183
2183
|
? [
|
|
2184
2184
|
...baseParams,
|
|
2185
|
-
|
|
2185
|
+
metaTx.params.transferAuthorizations.map(
|
|
2186
|
+
encodeTransferAuthorizationEntry
|
|
2187
|
+
)
|
|
2186
2188
|
]
|
|
2187
2189
|
: baseParams;
|
|
2188
2190
|
|
|
@@ -2285,7 +2287,7 @@ export async function executeMetaTransactionWithTokenTransferAuthorization(
|
|
|
2285
2287
|
s: hexlify(args.sigS),
|
|
2286
2288
|
v: Number(args.sigV)
|
|
2287
2289
|
}),
|
|
2288
|
-
|
|
2290
|
+
args.transferAuthorizations.map(encodeTransferAuthorizationEntry)
|
|
2289
2291
|
]
|
|
2290
2292
|
);
|
|
2291
2293
|
const tx: TransactionRequest = { to: args.contractAddress, data };
|