@bosonprotocol/core-sdk 1.48.0-alpha.1 → 1.48.0-alpha.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.
Files changed (37) hide show
  1. package/dist/cjs/meta-tx/handler.d.ts +27 -1
  2. package/dist/cjs/meta-tx/handler.d.ts.map +1 -1
  3. package/dist/cjs/meta-tx/handler.js +62 -21
  4. package/dist/cjs/meta-tx/handler.js.map +1 -1
  5. package/dist/cjs/meta-tx/mixin.d.ts +22 -0
  6. package/dist/cjs/meta-tx/mixin.d.ts.map +1 -1
  7. package/dist/cjs/meta-tx/mixin.js +42 -0
  8. package/dist/cjs/meta-tx/mixin.js.map +1 -1
  9. package/dist/cjs/native-meta-tx/handler.d.ts +16 -1
  10. package/dist/cjs/native-meta-tx/handler.d.ts.map +1 -1
  11. package/dist/cjs/native-meta-tx/handler.js +9 -0
  12. package/dist/cjs/native-meta-tx/handler.js.map +1 -1
  13. package/dist/cjs/native-meta-tx/mixin.d.ts +17 -0
  14. package/dist/cjs/native-meta-tx/mixin.d.ts.map +1 -1
  15. package/dist/cjs/native-meta-tx/mixin.js +23 -0
  16. package/dist/cjs/native-meta-tx/mixin.js.map +1 -1
  17. package/dist/esm/meta-tx/handler.d.ts +27 -1
  18. package/dist/esm/meta-tx/handler.d.ts.map +1 -1
  19. package/dist/esm/meta-tx/handler.js +35 -0
  20. package/dist/esm/meta-tx/handler.js.map +1 -1
  21. package/dist/esm/meta-tx/mixin.d.ts +22 -0
  22. package/dist/esm/meta-tx/mixin.d.ts.map +1 -1
  23. package/dist/esm/meta-tx/mixin.js +39 -0
  24. package/dist/esm/meta-tx/mixin.js.map +1 -1
  25. package/dist/esm/native-meta-tx/handler.d.ts +16 -1
  26. package/dist/esm/native-meta-tx/handler.d.ts.map +1 -1
  27. package/dist/esm/native-meta-tx/handler.js +6 -0
  28. package/dist/esm/native-meta-tx/handler.js.map +1 -1
  29. package/dist/esm/native-meta-tx/mixin.d.ts +17 -0
  30. package/dist/esm/native-meta-tx/mixin.d.ts.map +1 -1
  31. package/dist/esm/native-meta-tx/mixin.js +21 -0
  32. package/dist/esm/native-meta-tx/mixin.js.map +1 -1
  33. package/package.json +4 -3
  34. package/src/meta-tx/handler.ts +80 -1
  35. package/src/meta-tx/mixin.ts +57 -0
  36. package/src/native-meta-tx/handler.ts +31 -0
  37. package/src/native-meta-tx/mixin.ts +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bosonprotocol/core-sdk",
3
- "version": "1.48.0-alpha.1",
3
+ "version": "1.48.0-alpha.3",
4
4
  "description": "Facilitates interaction with the contracts and subgraphs of the Boson Protocol",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -35,12 +35,13 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@bosonprotocol/common": "^1.33.0-alpha.2",
38
+ "@bosonprotocol/common": "^1.33.0-alpha.4",
39
39
  "@ethersproject/abi": "^5.5.0",
40
40
  "@ethersproject/address": "^5.5.0",
41
41
  "@ethersproject/bignumber": "^5.5.0",
42
42
  "@ethersproject/bytes": "^5.6.1",
43
43
  "@ethersproject/constants": "^5.5.0",
44
+ "@ethersproject/random": "^5.8.0",
44
45
  "@ethersproject/units": "^5.5.0",
45
46
  "cross-fetch": "^3.1.5",
46
47
  "graphql": "^16.5.0",
@@ -61,5 +62,5 @@
61
62
  "overrides": {
62
63
  "typescript": "^5.1.6"
63
64
  },
64
- "gitHead": "11914b38d48b28bd1bdb27848e4b251201c12060"
65
+ "gitHead": "d707d8613eebf1f21243c2b405ab60f94ebd5103"
65
66
  }
@@ -3,6 +3,7 @@ import {
3
3
  CreateSellerArgs,
4
4
  MetaTxConfig,
5
5
  Web3LibAdapter,
6
+ TransactionRequest,
6
7
  TransactionResponse,
7
8
  utils,
8
9
  MetadataStorage,
@@ -17,7 +18,7 @@ import {
17
18
  } from "@bosonprotocol/common";
18
19
  import { storeMetadataOnTheGraph } from "../offers/storage";
19
20
  import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
20
- import { BytesLike } from "@ethersproject/bytes";
21
+ import { BytesLike, hexlify } from "@ethersproject/bytes";
21
22
 
22
23
  import {
23
24
  encodeCreateSeller,
@@ -46,6 +47,7 @@ import {
46
47
  ForwarderDomainData,
47
48
  GetRetriedHashesData
48
49
  } from "./biconomy";
50
+ import { metaTransactionsHandlerIface } from "./interface";
49
51
  import { isAddress } from "@ethersproject/address";
50
52
  import { AddressZero } from "@ethersproject/constants";
51
53
  import { encodeDepositFunds, encodeWithdrawFunds } from "../funds/interface";
@@ -2213,6 +2215,83 @@ export async function relayMetaTransaction(args: {
2213
2215
  };
2214
2216
  }
2215
2217
 
2218
+ export type ExecuteMetaTxBaseArgs = {
2219
+ contractAddress: string;
2220
+ web3Lib: Web3LibAdapter;
2221
+ userAddress: string;
2222
+ functionName: string;
2223
+ functionSignature: BytesLike;
2224
+ nonce: BigNumberish;
2225
+ sigR: BytesLike;
2226
+ sigS: BytesLike;
2227
+ sigV: BigNumberish;
2228
+ };
2229
+
2230
+ // Overload: returnTxInfo is true -> returns TransactionRequest
2231
+ export async function executeMetaTransaction(
2232
+ args: ExecuteMetaTxBaseArgs & { returnTxInfo: true }
2233
+ ): Promise<TransactionRequest>;
2234
+ // Overload: returnTxInfo is false or undefined -> returns TransactionResponse
2235
+ export async function executeMetaTransaction(
2236
+ args: ExecuteMetaTxBaseArgs & { returnTxInfo?: false | undefined }
2237
+ ): Promise<TransactionResponse>;
2238
+ // Implementation
2239
+ export async function executeMetaTransaction(
2240
+ args: ExecuteMetaTxBaseArgs & { returnTxInfo?: boolean }
2241
+ ): Promise<TransactionRequest | TransactionResponse> {
2242
+ const data = metaTransactionsHandlerIface.encodeFunctionData(
2243
+ "executeMetaTransaction",
2244
+ [
2245
+ args.userAddress,
2246
+ args.functionName,
2247
+ args.functionSignature,
2248
+ args.nonce,
2249
+ rebuildSignature({
2250
+ r: hexlify(args.sigR),
2251
+ s: hexlify(args.sigS),
2252
+ v: Number(args.sigV)
2253
+ })
2254
+ ]
2255
+ );
2256
+ const tx: TransactionRequest = { to: args.contractAddress, data };
2257
+ return args.returnTxInfo ? tx : args.web3Lib.sendTransaction(tx);
2258
+ }
2259
+
2260
+ export type ExecuteMetaTxWithAuthArgs = ExecuteMetaTxBaseArgs & {
2261
+ transferAuthorizations: TransferAuthorization[];
2262
+ };
2263
+
2264
+ // Overload: returnTxInfo is true -> returns TransactionRequest
2265
+ export async function executeMetaTransactionWithTokenTransferAuthorization(
2266
+ args: ExecuteMetaTxWithAuthArgs & { returnTxInfo: true }
2267
+ ): Promise<TransactionRequest>;
2268
+ // Overload: returnTxInfo is false or undefined -> returns TransactionResponse
2269
+ export async function executeMetaTransactionWithTokenTransferAuthorization(
2270
+ args: ExecuteMetaTxWithAuthArgs & { returnTxInfo?: false | undefined }
2271
+ ): Promise<TransactionResponse>;
2272
+ // Implementation
2273
+ export async function executeMetaTransactionWithTokenTransferAuthorization(
2274
+ args: ExecuteMetaTxWithAuthArgs & { returnTxInfo?: boolean }
2275
+ ): Promise<TransactionRequest | TransactionResponse> {
2276
+ const data = metaTransactionsHandlerIface.encodeFunctionData(
2277
+ "executeMetaTransactionWithTokenTransferAuthorization",
2278
+ [
2279
+ args.userAddress,
2280
+ args.functionName,
2281
+ args.functionSignature,
2282
+ args.nonce,
2283
+ rebuildSignature({
2284
+ r: hexlify(args.sigR),
2285
+ s: hexlify(args.sigS),
2286
+ v: Number(args.sigV)
2287
+ }),
2288
+ encodeTransferAuthorizationQueue(args.transferAuthorizations)
2289
+ ]
2290
+ );
2291
+ const tx: TransactionRequest = { to: args.contractAddress, data };
2292
+ return args.returnTxInfo ? tx : args.web3Lib.sendTransaction(tx);
2293
+ }
2294
+
2216
2295
  export async function getResubmitted(args: {
2217
2296
  chainId: number;
2218
2297
  metaTx: {
@@ -1855,6 +1855,63 @@ export class MetaTxMixin<T extends Web3LibAdapter> extends BaseCoreSDK<T> {
1855
1855
  });
1856
1856
  }
1857
1857
 
1858
+ /**
1859
+ * Execute a signed meta transaction directly on-chain (no Biconomy relayer).
1860
+ * Routes to `executeMetaTransaction` or `executeMetaTransactionWithTokenTransferAuthorization`
1861
+ * depending on whether `transferAuthorizations` is provided and non-empty.
1862
+ * The wallet backing the SDK pays the gas; pass `overrides.userAddress` when
1863
+ * the meta-tx signer differs from that wallet.
1864
+ * @param metaTxParams - Required params for meta transaction.
1865
+ * @param overrides - Optional overrides.
1866
+ * @returns Transaction response.
1867
+ */
1868
+ public async executeMetaTransaction(
1869
+ metaTxParams: {
1870
+ functionName: string;
1871
+ functionSignature: BytesLike;
1872
+ nonce: BigNumberish;
1873
+ sigR: BytesLike;
1874
+ sigS: BytesLike;
1875
+ sigV: BigNumberish;
1876
+ transferAuthorizations?: TransferAuthorization[];
1877
+ },
1878
+ overrides: Partial<{
1879
+ userAddress: string;
1880
+ contractAddress: string;
1881
+ }> = {}
1882
+ ): Promise<TransactionResponse> {
1883
+ const userAddress =
1884
+ overrides.userAddress || (await this._web3Lib.getSignerAddress());
1885
+ const contractAddress = overrides.contractAddress || this._protocolDiamond;
1886
+
1887
+ if (metaTxParams.transferAuthorizations?.length) {
1888
+ return handler.executeMetaTransactionWithTokenTransferAuthorization({
1889
+ web3Lib: this._web3Lib,
1890
+ contractAddress,
1891
+ userAddress,
1892
+ functionName: metaTxParams.functionName,
1893
+ functionSignature: metaTxParams.functionSignature,
1894
+ nonce: metaTxParams.nonce,
1895
+ sigR: metaTxParams.sigR,
1896
+ sigS: metaTxParams.sigS,
1897
+ sigV: metaTxParams.sigV,
1898
+ transferAuthorizations: metaTxParams.transferAuthorizations
1899
+ });
1900
+ }
1901
+
1902
+ return handler.executeMetaTransaction({
1903
+ web3Lib: this._web3Lib,
1904
+ contractAddress,
1905
+ userAddress,
1906
+ functionName: metaTxParams.functionName,
1907
+ functionSignature: metaTxParams.functionSignature,
1908
+ nonce: metaTxParams.nonce,
1909
+ sigR: metaTxParams.sigR,
1910
+ sigS: metaTxParams.sigS,
1911
+ sigV: metaTxParams.sigV
1912
+ });
1913
+ }
1914
+
1858
1915
  /**
1859
1916
  * Returns information of submitted meta transaction.
1860
1917
  * See https://docs.biconomy.io/api/native-meta-tx/get-retried-hashes.
@@ -2,6 +2,7 @@ import { tokenSpecifics } from "./tokenSpecifics";
2
2
  import {
3
3
  MetaTxConfig,
4
4
  Web3LibAdapter,
5
+ TransactionRequest,
5
6
  TransactionResponse
6
7
  } from "@bosonprotocol/common";
7
8
  import { BigNumberish, BigNumber } from "@ethersproject/bignumber";
@@ -242,3 +243,33 @@ export async function relayNativeMetaTransaction(args: {
242
243
  hash: relayTxResponse.txHash
243
244
  };
244
245
  }
246
+
247
+ export type ExecuteNativeMetaTxBaseArgs = {
248
+ contractAddress: string;
249
+ web3Lib: Web3LibAdapter;
250
+ userAddress: string;
251
+ functionSignature: BytesLike;
252
+ sigR: BytesLike;
253
+ sigS: BytesLike;
254
+ sigV: BigNumberish;
255
+ };
256
+
257
+ // Overload: returnTxInfo is true -> returns TransactionRequest
258
+ export async function executeNativeMetaTransaction(
259
+ args: ExecuteNativeMetaTxBaseArgs & { returnTxInfo: true }
260
+ ): Promise<TransactionRequest>;
261
+ // Overload: returnTxInfo is false or undefined -> returns TransactionResponse
262
+ export async function executeNativeMetaTransaction(
263
+ args: ExecuteNativeMetaTxBaseArgs & { returnTxInfo?: false | undefined }
264
+ ): Promise<TransactionResponse>;
265
+ // Implementation
266
+ export async function executeNativeMetaTransaction(
267
+ args: ExecuteNativeMetaTxBaseArgs & { returnTxInfo?: boolean }
268
+ ): Promise<TransactionRequest | TransactionResponse> {
269
+ const data = nativeMetaTransactionsIface.encodeFunctionData(
270
+ "executeMetaTransaction",
271
+ [args.userAddress, args.functionSignature, args.sigR, args.sigS, args.sigV]
272
+ );
273
+ const tx: TransactionRequest = { to: args.contractAddress, data };
274
+ return args.returnTxInfo ? tx : args.web3Lib.sendTransaction(tx);
275
+ }
@@ -108,4 +108,39 @@ export class NativeMetaTxMixin<
108
108
  }
109
109
  });
110
110
  }
111
+
112
+ /**
113
+ * Execute a signed native meta transaction directly on-chain (no Biconomy relayer).
114
+ * The wallet backing the SDK pays the gas; pass `overrides.userAddress` when the
115
+ * meta-tx signer differs from that wallet.
116
+ * @param contractAddress - The token contract address.
117
+ * @param metaTxParams - Required params for the native meta transaction.
118
+ * @param overrides - Optional overrides.
119
+ * @returns Transaction response.
120
+ */
121
+ public async executeNativeMetaTransaction(
122
+ contractAddress: string,
123
+ metaTxParams: {
124
+ functionSignature: BytesLike;
125
+ sigR: BytesLike;
126
+ sigS: BytesLike;
127
+ sigV: BigNumberish;
128
+ },
129
+ overrides: Partial<{
130
+ userAddress: string;
131
+ }> = {}
132
+ ): Promise<TransactionResponse> {
133
+ const userAddress =
134
+ overrides.userAddress || (await this._web3Lib.getSignerAddress());
135
+
136
+ return handler.executeNativeMetaTransaction({
137
+ web3Lib: this._web3Lib,
138
+ contractAddress,
139
+ userAddress,
140
+ functionSignature: metaTxParams.functionSignature,
141
+ sigR: metaTxParams.sigR,
142
+ sigS: metaTxParams.sigS,
143
+ sigV: metaTxParams.sigV
144
+ });
145
+ }
111
146
  }