thirdweb 5.108.2 → 5.108.3
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/exports/x402.js.map +1 -1
- package/dist/cjs/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.js +176 -0
- package/dist/cjs/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/x402/common.js +39 -1
- package/dist/cjs/x402/common.js.map +1 -1
- package/dist/cjs/x402/facilitator.js +1 -0
- package/dist/cjs/x402/facilitator.js.map +1 -1
- package/dist/cjs/x402/fetchWithPayment.js +2 -2
- package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
- package/dist/cjs/x402/sign.js +100 -34
- package/dist/cjs/x402/sign.js.map +1 -1
- package/dist/cjs/x402/types.js.map +1 -1
- package/dist/esm/exports/x402.js.map +1 -1
- package/dist/esm/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.js +169 -0
- package/dist/esm/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/x402/common.js +38 -1
- package/dist/esm/x402/common.js.map +1 -1
- package/dist/esm/x402/facilitator.js +1 -0
- package/dist/esm/x402/facilitator.js.map +1 -1
- package/dist/esm/x402/fetchWithPayment.js +2 -2
- package/dist/esm/x402/fetchWithPayment.js.map +1 -1
- package/dist/esm/x402/sign.js +100 -34
- package/dist/esm/x402/sign.js.map +1 -1
- package/dist/esm/x402/types.js.map +1 -1
- package/dist/scripts/bridge-widget.js +2 -2
- package/dist/types/exports/x402.d.ts +1 -1
- package/dist/types/exports/x402.d.ts.map +1 -1
- package/dist/types/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.d.ts +121 -0
- package/dist/types/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.d.ts.map +1 -0
- package/dist/types/react/web/ui/Bridge/swap-widget/SwapWidget.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/x402/common.d.ts +8 -1
- package/dist/types/x402/common.d.ts.map +1 -1
- package/dist/types/x402/facilitator.d.ts +18 -41
- package/dist/types/x402/facilitator.d.ts.map +1 -1
- package/dist/types/x402/fetchWithPayment.d.ts +1 -1
- package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
- package/dist/types/x402/sign.d.ts +2 -1
- package/dist/types/x402/sign.d.ts.map +1 -1
- package/dist/types/x402/types.d.ts +16 -3
- package/dist/types/x402/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/exports/x402.ts +1 -0
- package/src/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.ts +215 -0
- package/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx +1 -1
- package/src/version.ts +1 -1
- package/src/x402/common.ts +58 -5
- package/src/x402/facilitator.ts +28 -1
- package/src/x402/fetchWithPayment.ts +3 -2
- package/src/x402/sign.ts +140 -49
- package/src/x402/types.ts +18 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { decodePayment, encodePayment } from "../x402/encode.js";
|
|
2
|
-
export { facilitator, type ThirdwebX402FacilitatorConfig, } from "../x402/facilitator.js";
|
|
2
|
+
export { facilitator, type ThirdwebX402Facilitator, type ThirdwebX402FacilitatorConfig, } from "../x402/facilitator.js";
|
|
3
3
|
export { wrapFetchWithPayment } from "../x402/fetchWithPayment.js";
|
|
4
4
|
export { settlePayment } from "../x402/settle-payment.js";
|
|
5
5
|
export type { PaymentArgs, SettlePaymentResult, VerifyPaymentResult, } from "../x402/types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../../src/exports/x402.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,WAAW,EACX,KAAK,6BAA6B,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../../src/exports/x402.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,WAAW,EACX,KAAK,uBAAuB,EAC5B,KAAK,6BAA6B,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
|
2
|
+
import type { BaseTransactionOptions, WithOverrides } from "../../../../../transaction/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents the parameters for the "transferWithAuthorization" function.
|
|
5
|
+
*/
|
|
6
|
+
export type TransferWithAuthorizationParams = WithOverrides<{
|
|
7
|
+
from: AbiParameterToPrimitiveType<{
|
|
8
|
+
type: "address";
|
|
9
|
+
name: "from";
|
|
10
|
+
}>;
|
|
11
|
+
to: AbiParameterToPrimitiveType<{
|
|
12
|
+
type: "address";
|
|
13
|
+
name: "to";
|
|
14
|
+
}>;
|
|
15
|
+
value: AbiParameterToPrimitiveType<{
|
|
16
|
+
type: "uint256";
|
|
17
|
+
name: "value";
|
|
18
|
+
}>;
|
|
19
|
+
validAfter: AbiParameterToPrimitiveType<{
|
|
20
|
+
type: "uint256";
|
|
21
|
+
name: "validAfter";
|
|
22
|
+
}>;
|
|
23
|
+
validBefore: AbiParameterToPrimitiveType<{
|
|
24
|
+
type: "uint256";
|
|
25
|
+
name: "validBefore";
|
|
26
|
+
}>;
|
|
27
|
+
nonce: AbiParameterToPrimitiveType<{
|
|
28
|
+
type: "bytes32";
|
|
29
|
+
name: "nonce";
|
|
30
|
+
}>;
|
|
31
|
+
signature: AbiParameterToPrimitiveType<{
|
|
32
|
+
type: "bytes";
|
|
33
|
+
name: "signature";
|
|
34
|
+
}>;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const FN_SELECTOR: "0xcf092995";
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the `transferWithAuthorization` method is supported by the given contract.
|
|
39
|
+
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
|
|
40
|
+
* @returns A boolean indicating if the `transferWithAuthorization` method is supported.
|
|
41
|
+
* @extension ERC20
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { isTransferWithAuthorizationSupported } from "thirdweb/extensions/erc20";
|
|
45
|
+
*
|
|
46
|
+
* const supported = isTransferWithAuthorizationSupported(["0x..."]);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function isTransferWithAuthorizationSupported(availableSelectors: string[]): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Encodes the parameters for the "transferWithAuthorization" function.
|
|
52
|
+
* @param options - The options for the transferWithAuthorization function.
|
|
53
|
+
* @returns The encoded ABI parameters.
|
|
54
|
+
* @extension ERC20
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { encodeTransferWithAuthorizationParams } from "thirdweb/extensions/erc20";
|
|
58
|
+
* const result = encodeTransferWithAuthorizationParams({
|
|
59
|
+
* from: ...,
|
|
60
|
+
* to: ...,
|
|
61
|
+
* value: ...,
|
|
62
|
+
* validAfter: ...,
|
|
63
|
+
* validBefore: ...,
|
|
64
|
+
* nonce: ...,
|
|
65
|
+
* signature: ...,
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function encodeTransferWithAuthorizationParams(options: TransferWithAuthorizationParams): `0x${string}`;
|
|
70
|
+
/**
|
|
71
|
+
* Encodes the "transferWithAuthorization" function into a Hex string with its parameters.
|
|
72
|
+
* @param options - The options for the transferWithAuthorization function.
|
|
73
|
+
* @returns The encoded hexadecimal string.
|
|
74
|
+
* @extension ERC20
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { encodeTransferWithAuthorization } from "thirdweb/extensions/erc20";
|
|
78
|
+
* const result = encodeTransferWithAuthorization({
|
|
79
|
+
* from: ...,
|
|
80
|
+
* to: ...,
|
|
81
|
+
* value: ...,
|
|
82
|
+
* validAfter: ...,
|
|
83
|
+
* validBefore: ...,
|
|
84
|
+
* nonce: ...,
|
|
85
|
+
* signature: ...,
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function encodeTransferWithAuthorization(options: TransferWithAuthorizationParams): `${typeof FN_SELECTOR}${string}`;
|
|
90
|
+
/**
|
|
91
|
+
* Prepares a transaction to call the "transferWithAuthorization" function on the contract.
|
|
92
|
+
* @param options - The options for the "transferWithAuthorization" function.
|
|
93
|
+
* @returns A prepared transaction object.
|
|
94
|
+
* @extension ERC20
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { sendTransaction } from "thirdweb";
|
|
98
|
+
* import { transferWithAuthorization } from "thirdweb/extensions/erc20";
|
|
99
|
+
*
|
|
100
|
+
* const transaction = transferWithAuthorization({
|
|
101
|
+
* contract,
|
|
102
|
+
* from: ...,
|
|
103
|
+
* to: ...,
|
|
104
|
+
* value: ...,
|
|
105
|
+
* validAfter: ...,
|
|
106
|
+
* validBefore: ...,
|
|
107
|
+
* nonce: ...,
|
|
108
|
+
* signature: ...,
|
|
109
|
+
* overrides: {
|
|
110
|
+
* ...
|
|
111
|
+
* }
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* // Send the transaction
|
|
115
|
+
* await sendTransaction({ transaction, account });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function transferWithAuthorization(options: BaseTransactionOptions<TransferWithAuthorizationParams | {
|
|
119
|
+
asyncParams: () => Promise<TransferWithAuthorizationParams>;
|
|
120
|
+
}>): import("../../../../../transaction/prepare-transaction.js").PreparedTransaction<any, import("abitype").AbiFunction, import("../../../../../transaction/prepare-transaction.js").PrepareTransactionOptions>;
|
|
121
|
+
//# sourceMappingURL=transferWithAuthorization.d.ts.map
|
package/dist/types/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferWithAuthorization.d.ts","sourceRoot":"","sources":["../../../../../../../src/extensions/erc20/__generated__/USDC/write/transferWithAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,qCAAqC,CAAC;AAK7C;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,aAAa,CAAC;IAC1D,IAAI,EAAE,2BAA2B,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,EAAE,EAAE,2BAA2B,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;IACjE,KAAK,EAAE,2BAA2B,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACvE,UAAU,EAAE,2BAA2B,CAAC;QACtC,IAAI,EAAE,SAAS,CAAC;QAChB,IAAI,EAAE,YAAY,CAAC;KACpB,CAAC,CAAC;IACH,WAAW,EAAE,2BAA2B,CAAC;QACvC,IAAI,EAAE,SAAS,CAAC;QAChB,IAAI,EAAE,aAAa,CAAC;KACrB,CAAC,CAAC;IACH,KAAK,EAAE,2BAA2B,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACvE,SAAS,EAAE,2BAA2B,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;CAC9E,CAAC,CAAC;AAEH,eAAO,MAAM,WAAW,EAAG,YAAqB,CAAC;AAiCjD;;;;;;;;;;;GAWG;AACH,wBAAgB,oCAAoC,CAClD,kBAAkB,EAAE,MAAM,EAAE,WAM7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,+BAA+B,iBAWzC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,+BAA+B,GAOhC,GAAG,OAAO,WAAW,GAAG,MAAM,EAAE,CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,sBAAsB,CAC3B,+BAA+B,GAC/B;IACE,WAAW,EAAE,MAAM,OAAO,CAAC,+BAA+B,CAAC,CAAC;CAC7D,CACJ,8MAkCF"}
|
|
@@ -20,7 +20,7 @@ export type SwapWidgetProps = {
|
|
|
20
20
|
*/
|
|
21
21
|
client: ThirdwebClient;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Prefill Buy and/or Sell tokens for the swap widget. If `tokenAddress` is not provided, the native token will be used
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
*
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.108.
|
|
1
|
+
export declare const version = "5.108.3";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
1
2
|
import { type RequestedPaymentPayload, type RequestedPaymentRequirements } from "./schemas.js";
|
|
2
|
-
import { type PaymentArgs, type PaymentRequiredResult } from "./types.js";
|
|
3
|
+
import { type ERC20TokenAmount, type PaymentArgs, type PaymentRequiredResult, type SupportedSignatureType } from "./types.js";
|
|
3
4
|
type GetPaymentRequirementsResult = {
|
|
4
5
|
status: 200;
|
|
5
6
|
paymentRequirements: RequestedPaymentRequirements[];
|
|
@@ -12,5 +13,11 @@ type GetPaymentRequirementsResult = {
|
|
|
12
13
|
* @returns The payment requirements, selected payment requirements, and decoded payment
|
|
13
14
|
*/
|
|
14
15
|
export declare function decodePaymentRequest(args: PaymentArgs): Promise<GetPaymentRequirementsResult | PaymentRequiredResult>;
|
|
16
|
+
export declare function getSupportedSignatureType(args: {
|
|
17
|
+
client: ThirdwebClient;
|
|
18
|
+
asset: string;
|
|
19
|
+
chainId: number;
|
|
20
|
+
eip712Extras: ERC20TokenAmount["asset"]["eip712"] | undefined;
|
|
21
|
+
}): Promise<SupportedSignatureType | undefined>;
|
|
15
22
|
export {};
|
|
16
23
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/x402/common.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/x402/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAE5B,MAAM,YAAY,CAAC;AAEpB,KAAK,4BAA4B,GAAG;IAClC,MAAM,EAAE,GAAG,CAAC;IACZ,mBAAmB,EAAE,4BAA4B,EAAE,CAAC;IACpD,2BAA2B,EAAE,4BAA4B,CAAC;IAC1D,cAAc,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,4BAA4B,GAAG,qBAAqB,CAAC,CAoJ/D;AA+DD,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACpD,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;CAC/D,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAiC9C"}
|
|
@@ -7,6 +7,23 @@ export type ThirdwebX402FacilitatorConfig = {
|
|
|
7
7
|
vaultAccessToken?: string;
|
|
8
8
|
baseUrl?: string;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* facilitator for the x402 payment protocol.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type ThirdwebX402Facilitator = {
|
|
15
|
+
url: `${string}://${string}`;
|
|
16
|
+
address: string;
|
|
17
|
+
createAuthHeaders: () => Promise<{
|
|
18
|
+
verify: Record<string, string>;
|
|
19
|
+
settle: Record<string, string>;
|
|
20
|
+
supported: Record<string, string>;
|
|
21
|
+
list: Record<string, string>;
|
|
22
|
+
}>;
|
|
23
|
+
verify: (payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements) => Promise<VerifyResponse>;
|
|
24
|
+
settle: (payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements) => Promise<FacilitatorSettleResponse>;
|
|
25
|
+
supported: () => Promise<SupportedPaymentKindsResponse>;
|
|
26
|
+
};
|
|
10
27
|
/**
|
|
11
28
|
* Creates a facilitator for the x402 payment protocol.
|
|
12
29
|
* You can use this with `settlePayment` or with any x402 middleware to enable settling transactions with your thirdweb server wallet.
|
|
@@ -46,45 +63,5 @@ export type ThirdwebX402FacilitatorConfig = {
|
|
|
46
63
|
*
|
|
47
64
|
* @bridge x402
|
|
48
65
|
*/
|
|
49
|
-
export declare function facilitator(config: ThirdwebX402FacilitatorConfig):
|
|
50
|
-
url: `${string}://${string}`;
|
|
51
|
-
createAuthHeaders: () => Promise<{
|
|
52
|
-
verify: {
|
|
53
|
-
"x-secret-key": string;
|
|
54
|
-
};
|
|
55
|
-
settle: {
|
|
56
|
-
"x-vault-access-token"?: string | undefined;
|
|
57
|
-
"x-secret-key": string;
|
|
58
|
-
"x-settlement-wallet-address": string;
|
|
59
|
-
};
|
|
60
|
-
supported: {
|
|
61
|
-
"x-secret-key": string;
|
|
62
|
-
};
|
|
63
|
-
list: {
|
|
64
|
-
"x-secret-key": string;
|
|
65
|
-
};
|
|
66
|
-
}>;
|
|
67
|
-
/**
|
|
68
|
-
* Verifies a payment payload with the facilitator service
|
|
69
|
-
*
|
|
70
|
-
* @param payload - The payment payload to verify
|
|
71
|
-
* @param paymentRequirements - The payment requirements to verify against
|
|
72
|
-
* @returns A promise that resolves to the verification response
|
|
73
|
-
*/
|
|
74
|
-
verify(payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements): Promise<VerifyResponse>;
|
|
75
|
-
/**
|
|
76
|
-
* Settles a payment with the facilitator service
|
|
77
|
-
*
|
|
78
|
-
* @param payload - The payment payload to settle
|
|
79
|
-
* @param paymentRequirements - The payment requirements for the settlement
|
|
80
|
-
* @returns A promise that resolves to the settlement response
|
|
81
|
-
*/
|
|
82
|
-
settle(payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements): Promise<FacilitatorSettleResponse>;
|
|
83
|
-
/**
|
|
84
|
-
* Gets the supported payment kinds from the facilitator service.
|
|
85
|
-
*
|
|
86
|
-
* @returns A promise that resolves to the supported payment kinds
|
|
87
|
-
*/
|
|
88
|
-
supported(): Promise<SupportedPaymentKindsResponse>;
|
|
89
|
-
};
|
|
66
|
+
export declare function facilitator(config: ThirdwebX402FacilitatorConfig): ThirdwebX402Facilitator;
|
|
90
67
|
//# sourceMappingURL=facilitator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,cAAc,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,cAAc,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,GAAG,MAAM,MAAM,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,OAAO,CAAC;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC9B,CAAC,CAAC;IACH,MAAM,EAAE,CACN,OAAO,EAAE,uBAAuB,EAChC,mBAAmB,EAAE,4BAA4B,KAC9C,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7B,MAAM,EAAE,CACN,OAAO,EAAE,uBAAuB,EAChC,mBAAmB,EAAE,4BAA4B,KAC9C,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACxC,SAAS,EAAE,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC;CACzD,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,6BAA6B,GACpC,uBAAuB,CA0IzB"}
|
|
@@ -39,5 +39,5 @@ import type { Wallet } from "../wallets/interfaces/wallet.js";
|
|
|
39
39
|
*
|
|
40
40
|
* @bridge x402
|
|
41
41
|
*/
|
|
42
|
-
export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch,
|
|
42
|
+
export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, maxValue?: bigint): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
43
43
|
//# sourceMappingURL=fetchWithPayment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAQ9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,
|
|
1
|
+
{"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAQ9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAA4B,IAExB,OAAO,WAAW,EAAE,OAAO,WAAW,uBA0ErD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
1
2
|
import type { Account } from "../wallets/interfaces/wallet.js";
|
|
2
3
|
import { type RequestedPaymentRequirements } from "./schemas.js";
|
|
3
4
|
/**
|
|
@@ -8,5 +9,5 @@ import { type RequestedPaymentRequirements } from "./schemas.js";
|
|
|
8
9
|
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
9
10
|
* @returns A promise that resolves to the encoded payment header string
|
|
10
11
|
*/
|
|
11
|
-
export declare function createPaymentHeader(account: Account,
|
|
12
|
+
export declare function createPaymentHeader(client: ThirdwebClient, account: Account, paymentRequirements: RequestedPaymentRequirements, x402Version: number): Promise<string>;
|
|
12
13
|
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/x402/sign.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/x402/sign.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG/D,OAAO,EAGL,KAAK,4BAA4B,EAElC,MAAM,cAAc,CAAC;AA6HtB;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,EAChB,mBAAmB,EAAE,4BAA4B,EACjD,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Money, PaymentMiddlewareConfig } from "x402/types";
|
|
2
2
|
import type { Chain } from "../chains/types.js";
|
|
3
3
|
import type { Address } from "../utils/address.js";
|
|
4
4
|
import type { Prettify } from "../utils/type-utils.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ThirdwebX402Facilitator } from "./facilitator.js";
|
|
6
6
|
import type { FacilitatorNetwork, FacilitatorSettleResponse, RequestedPaymentPayload, RequestedPaymentRequirements } from "./schemas.js";
|
|
7
7
|
export declare const x402Version = 1;
|
|
8
8
|
/**
|
|
@@ -24,7 +24,7 @@ export type PaymentArgs = {
|
|
|
24
24
|
/** The price for accessing the resource - either a USD amount (e.g., "$0.10") or a specific token amount */
|
|
25
25
|
price: Money | ERC20TokenAmount;
|
|
26
26
|
/** The payment facilitator instance used to verify and settle payments */
|
|
27
|
-
facilitator:
|
|
27
|
+
facilitator: ThirdwebX402Facilitator;
|
|
28
28
|
/** Optional configuration for the payment middleware route */
|
|
29
29
|
routeConfig?: PaymentMiddlewareConfig;
|
|
30
30
|
};
|
|
@@ -69,4 +69,17 @@ export type VerifyPaymentResult = Prettify<{
|
|
|
69
69
|
decodedPayment: RequestedPaymentPayload;
|
|
70
70
|
selectedPaymentRequirements: RequestedPaymentRequirements;
|
|
71
71
|
} | PaymentRequiredResult>;
|
|
72
|
+
export type SupportedSignatureType = "TransferWithAuthorization" | "Permit";
|
|
73
|
+
export type ERC20TokenAmount = {
|
|
74
|
+
amount: string;
|
|
75
|
+
asset: {
|
|
76
|
+
address: `0x${string}`;
|
|
77
|
+
decimals: number;
|
|
78
|
+
eip712: {
|
|
79
|
+
name: string;
|
|
80
|
+
version: string;
|
|
81
|
+
primaryType: SupportedSignatureType;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
72
85
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/x402/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/x402/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACvC,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,mEAAmE;IACnE,OAAO,EAAE,kBAAkB,GAAG,KAAK,CAAC;IACpC,4GAA4G;IAC5G,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC;IAChC,0EAA0E;IAC1E,WAAW,EAAE,uBAAuB,CAAC;IACrC,8DAA8D;IAC9D,WAAW,CAAC,EAAE,uBAAuB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,wFAAwF;IACxF,MAAM,EAAE,GAAG,CAAC;IACZ,8DAA8D;IAC9D,YAAY,EAAE;QACZ,gCAAgC;QAChC,WAAW,EAAE,MAAM,CAAC;QACpB,mCAAmC;QACnC,KAAK,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,OAAO,EAAE,4BAA4B,EAAE,CAAC;QACxC,iEAAiE;QACjE,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,8CAA8C;IAC9C,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACtC;IACE,oDAAoD;IACpD,MAAM,EAAE,GAAG,CAAC;IACZ,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,uDAAuD;IACvD,cAAc,EAAE,yBAAyB,CAAC;CAC3C,GACD,qBAAqB,CACxB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACtC;IACE,mDAAmD;IACnD,MAAM,EAAE,GAAG,CAAC;IACZ,cAAc,EAAE,uBAAuB,CAAC;IACxC,2BAA2B,EAAE,4BAA4B,CAAC;CAC3D,GACD,qBAAqB,CACxB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,GAAG,QAAQ,CAAC;AAE5E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE;QACL,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,sBAAsB,CAAC;SACrC,CAAC;KACH,CAAC;CACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"viem": "2.33.2",
|
|
41
41
|
"x402": "0.6.1",
|
|
42
42
|
"zod": "3.25.75",
|
|
43
|
-
"@thirdweb-dev/
|
|
44
|
-
"@thirdweb-dev/
|
|
43
|
+
"@thirdweb-dev/engine": "3.2.1",
|
|
44
|
+
"@thirdweb-dev/insight": "1.1.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@aws-sdk/client-kms": "3.592.0",
|
|
@@ -399,7 +399,7 @@
|
|
|
399
399
|
}
|
|
400
400
|
},
|
|
401
401
|
"typings": "./dist/types/exports/thirdweb.d.ts",
|
|
402
|
-
"version": "5.108.
|
|
402
|
+
"version": "5.108.3",
|
|
403
403
|
"scripts": {
|
|
404
404
|
"bench": "vitest -c ./test/vitest.config.ts bench",
|
|
405
405
|
"bench:compare": "bun run ./benchmarks/run.ts",
|
package/src/exports/x402.ts
CHANGED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { AbiParameterToPrimitiveType } from "abitype";
|
|
2
|
+
import { prepareContractCall } from "../../../../../transaction/prepare-contract-call.js";
|
|
3
|
+
import type {
|
|
4
|
+
BaseTransactionOptions,
|
|
5
|
+
WithOverrides,
|
|
6
|
+
} from "../../../../../transaction/types.js";
|
|
7
|
+
import { encodeAbiParameters } from "../../../../../utils/abi/encodeAbiParameters.js";
|
|
8
|
+
import { detectMethod } from "../../../../../utils/bytecode/detectExtension.js";
|
|
9
|
+
import { once } from "../../../../../utils/promise/once.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents the parameters for the "transferWithAuthorization" function.
|
|
13
|
+
*/
|
|
14
|
+
export type TransferWithAuthorizationParams = WithOverrides<{
|
|
15
|
+
from: AbiParameterToPrimitiveType<{ type: "address"; name: "from" }>;
|
|
16
|
+
to: AbiParameterToPrimitiveType<{ type: "address"; name: "to" }>;
|
|
17
|
+
value: AbiParameterToPrimitiveType<{ type: "uint256"; name: "value" }>;
|
|
18
|
+
validAfter: AbiParameterToPrimitiveType<{
|
|
19
|
+
type: "uint256";
|
|
20
|
+
name: "validAfter";
|
|
21
|
+
}>;
|
|
22
|
+
validBefore: AbiParameterToPrimitiveType<{
|
|
23
|
+
type: "uint256";
|
|
24
|
+
name: "validBefore";
|
|
25
|
+
}>;
|
|
26
|
+
nonce: AbiParameterToPrimitiveType<{ type: "bytes32"; name: "nonce" }>;
|
|
27
|
+
signature: AbiParameterToPrimitiveType<{ type: "bytes"; name: "signature" }>;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
export const FN_SELECTOR = "0xcf092995" as const;
|
|
31
|
+
const FN_INPUTS = [
|
|
32
|
+
{
|
|
33
|
+
type: "address",
|
|
34
|
+
name: "from",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: "address",
|
|
38
|
+
name: "to",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: "uint256",
|
|
42
|
+
name: "value",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "uint256",
|
|
46
|
+
name: "validAfter",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "uint256",
|
|
50
|
+
name: "validBefore",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "bytes32",
|
|
54
|
+
name: "nonce",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "bytes",
|
|
58
|
+
name: "signature",
|
|
59
|
+
},
|
|
60
|
+
] as const;
|
|
61
|
+
const FN_OUTPUTS = [] as const;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the `transferWithAuthorization` method is supported by the given contract.
|
|
65
|
+
* @param availableSelectors An array of 4byte function selectors of the contract. You can get this in various ways, such as using "whatsabi" or if you have the ABI of the contract available you can use it to generate the selectors.
|
|
66
|
+
* @returns A boolean indicating if the `transferWithAuthorization` method is supported.
|
|
67
|
+
* @extension ERC20
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { isTransferWithAuthorizationSupported } from "thirdweb/extensions/erc20";
|
|
71
|
+
*
|
|
72
|
+
* const supported = isTransferWithAuthorizationSupported(["0x..."]);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function isTransferWithAuthorizationSupported(
|
|
76
|
+
availableSelectors: string[],
|
|
77
|
+
) {
|
|
78
|
+
return detectMethod({
|
|
79
|
+
availableSelectors,
|
|
80
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Encodes the parameters for the "transferWithAuthorization" function.
|
|
86
|
+
* @param options - The options for the transferWithAuthorization function.
|
|
87
|
+
* @returns The encoded ABI parameters.
|
|
88
|
+
* @extension ERC20
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { encodeTransferWithAuthorizationParams } from "thirdweb/extensions/erc20";
|
|
92
|
+
* const result = encodeTransferWithAuthorizationParams({
|
|
93
|
+
* from: ...,
|
|
94
|
+
* to: ...,
|
|
95
|
+
* value: ...,
|
|
96
|
+
* validAfter: ...,
|
|
97
|
+
* validBefore: ...,
|
|
98
|
+
* nonce: ...,
|
|
99
|
+
* signature: ...,
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function encodeTransferWithAuthorizationParams(
|
|
104
|
+
options: TransferWithAuthorizationParams,
|
|
105
|
+
) {
|
|
106
|
+
return encodeAbiParameters(FN_INPUTS, [
|
|
107
|
+
options.from,
|
|
108
|
+
options.to,
|
|
109
|
+
options.value,
|
|
110
|
+
options.validAfter,
|
|
111
|
+
options.validBefore,
|
|
112
|
+
options.nonce,
|
|
113
|
+
options.signature,
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Encodes the "transferWithAuthorization" function into a Hex string with its parameters.
|
|
119
|
+
* @param options - The options for the transferWithAuthorization function.
|
|
120
|
+
* @returns The encoded hexadecimal string.
|
|
121
|
+
* @extension ERC20
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { encodeTransferWithAuthorization } from "thirdweb/extensions/erc20";
|
|
125
|
+
* const result = encodeTransferWithAuthorization({
|
|
126
|
+
* from: ...,
|
|
127
|
+
* to: ...,
|
|
128
|
+
* value: ...,
|
|
129
|
+
* validAfter: ...,
|
|
130
|
+
* validBefore: ...,
|
|
131
|
+
* nonce: ...,
|
|
132
|
+
* signature: ...,
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function encodeTransferWithAuthorization(
|
|
137
|
+
options: TransferWithAuthorizationParams,
|
|
138
|
+
) {
|
|
139
|
+
// we do a "manual" concat here to avoid the overhead of the "concatHex" function
|
|
140
|
+
// we can do this because we know the specific formats of the values
|
|
141
|
+
return (FN_SELECTOR +
|
|
142
|
+
encodeTransferWithAuthorizationParams(options).slice(
|
|
143
|
+
2,
|
|
144
|
+
)) as `${typeof FN_SELECTOR}${string}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Prepares a transaction to call the "transferWithAuthorization" function on the contract.
|
|
149
|
+
* @param options - The options for the "transferWithAuthorization" function.
|
|
150
|
+
* @returns A prepared transaction object.
|
|
151
|
+
* @extension ERC20
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { sendTransaction } from "thirdweb";
|
|
155
|
+
* import { transferWithAuthorization } from "thirdweb/extensions/erc20";
|
|
156
|
+
*
|
|
157
|
+
* const transaction = transferWithAuthorization({
|
|
158
|
+
* contract,
|
|
159
|
+
* from: ...,
|
|
160
|
+
* to: ...,
|
|
161
|
+
* value: ...,
|
|
162
|
+
* validAfter: ...,
|
|
163
|
+
* validBefore: ...,
|
|
164
|
+
* nonce: ...,
|
|
165
|
+
* signature: ...,
|
|
166
|
+
* overrides: {
|
|
167
|
+
* ...
|
|
168
|
+
* }
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* // Send the transaction
|
|
172
|
+
* await sendTransaction({ transaction, account });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function transferWithAuthorization(
|
|
176
|
+
options: BaseTransactionOptions<
|
|
177
|
+
| TransferWithAuthorizationParams
|
|
178
|
+
| {
|
|
179
|
+
asyncParams: () => Promise<TransferWithAuthorizationParams>;
|
|
180
|
+
}
|
|
181
|
+
>,
|
|
182
|
+
) {
|
|
183
|
+
const asyncOptions = once(async () => {
|
|
184
|
+
return "asyncParams" in options ? await options.asyncParams() : options;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return prepareContractCall({
|
|
188
|
+
contract: options.contract,
|
|
189
|
+
method: [FN_SELECTOR, FN_INPUTS, FN_OUTPUTS] as const,
|
|
190
|
+
params: async () => {
|
|
191
|
+
const resolvedOptions = await asyncOptions();
|
|
192
|
+
return [
|
|
193
|
+
resolvedOptions.from,
|
|
194
|
+
resolvedOptions.to,
|
|
195
|
+
resolvedOptions.value,
|
|
196
|
+
resolvedOptions.validAfter,
|
|
197
|
+
resolvedOptions.validBefore,
|
|
198
|
+
resolvedOptions.nonce,
|
|
199
|
+
resolvedOptions.signature,
|
|
200
|
+
] as const;
|
|
201
|
+
},
|
|
202
|
+
value: async () => (await asyncOptions()).overrides?.value,
|
|
203
|
+
accessList: async () => (await asyncOptions()).overrides?.accessList,
|
|
204
|
+
gas: async () => (await asyncOptions()).overrides?.gas,
|
|
205
|
+
gasPrice: async () => (await asyncOptions()).overrides?.gasPrice,
|
|
206
|
+
maxFeePerGas: async () => (await asyncOptions()).overrides?.maxFeePerGas,
|
|
207
|
+
maxPriorityFeePerGas: async () =>
|
|
208
|
+
(await asyncOptions()).overrides?.maxPriorityFeePerGas,
|
|
209
|
+
nonce: async () => (await asyncOptions()).overrides?.nonce,
|
|
210
|
+
extraGas: async () => (await asyncOptions()).overrides?.extraGas,
|
|
211
|
+
erc20Value: async () => (await asyncOptions()).overrides?.erc20Value,
|
|
212
|
+
authorizationList: async () =>
|
|
213
|
+
(await asyncOptions()).overrides?.authorizationList,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
@@ -48,7 +48,7 @@ export type SwapWidgetProps = {
|
|
|
48
48
|
*/
|
|
49
49
|
client: ThirdwebClient;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Prefill Buy and/or Sell tokens for the swap widget. If `tokenAddress` is not provided, the native token will be used
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
*
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.108.
|
|
1
|
+
export const version = "5.108.3";
|