@reyaxyz/sdk 0.78.2 → 0.79.1

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 CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-12.17%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-9.09%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-12%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-11.52%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-12.1%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-8.97%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-12%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-11.44%25-red.svg?style=flat) |
10
10
 
@@ -62,7 +62,8 @@ var TransactionModule = /** @class */ (function (_super) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var uri;
64
64
  return __generator(this, function (_a) {
65
- uri = "/api/transaction/execute";
65
+ uri = "/api/transaction-gelato/executeGelato";
66
+ // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer
66
67
  return [2 /*return*/, this.post(uri, {}, {
67
68
  txData: txData,
68
69
  contractAddress: contractAddress,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AAgBzB;IAAuC,qCAAU;IAAjD;;IAkBA,CAAC;IAjBO,8CAAkB,GAAxB,UACE,MAAc,EACd,eAAuB,EACvB,QAAsC;;;;gBAGhC,GAAG,GAAG,0BAA0B,CAAC;gBACvC,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EAC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C;IAC9D,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC9D,CAAC,CAAC;AAPW,QAAA,YAAY,gBAOvB;AAEK,IAAM,0BAA0B,GAAG;IACxC,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC;AAEK,IAAM,yBAAyB,GAAG;IACvC,IAAI,CAAC,gBAAgB;QACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC","sourcesContent":["import {\n Address,\n API_CLIENT_CONFIGS,\n RestClient,\n ServiceConfig,\n} from '@reyaxyz/common';\n\nexport type BroadcastTransactionMetadata = {\n accountName?: string;\n};\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\ntype AlphaTermsData = {\n walletAddress: Address;\n link: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: BroadcastTransactionMetadata,\n ) {\n // const uri = `/api/transaction-gelato/executeGelato`;\n const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<{ txHash: string; accountId?: string }>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n }\n}\n\nexport class AlphaTermsModule extends RestClient {\n async registerAlphaSignature(params: AlphaTermsData): Promise<void> {\n // Build formData object.\n const formData = new FormData();\n formData.append('walletAddress', params.walletAddress);\n formData.append('signedLink', params.link);\n\n const uri = '/api/tos/alpha-signatures';\n return this.post(uri, undefined, formData, undefined);\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\n\nlet sdkEnv: ServiceConfig['environment'] = 'test';\n\nexport const getSdkEnvironment = (): ServiceConfig['environment'] => {\n return sdkEnv;\n};\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n const config = API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n sdkEnv = environment;\n transactionModule = new TransactionModule(config.apiEndpoint);\n alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getAlphaTermsModuleClient = (): AlphaTermsModule => {\n if (!alphaTermsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return alphaTermsModule;\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AAgBzB;IAAuC,qCAAU;IAAjD;;IAkBA,CAAC;IAjBO,8CAAkB,GAAxB,UACE,MAAc,EACd,eAAuB,EACvB,QAAsC;;;;gBAEhC,GAAG,GAAG,uCAAuC,CAAC;gBACpD,uFAAuF;gBACvF,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,MAAM,EAAE,MAAM;wBACd,eAAe,iBAAA;wBACf,QAAQ,UAAA;qBACT,CACF,EAAC;;;KACH;IACH,wBAAC;AAAD,CAAC,AAlBD,CAAuC,mBAAU,GAkBhD;AAlBY,8CAAiB;AAoB9B;IAAsC,oCAAU;IAAhD;;IAUA,CAAC;IATO,iDAAsB,GAA5B,UAA6B,MAAsB;;;;gBAE3C,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;gBAChC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,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,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC","sourcesContent":["import {\n Address,\n API_CLIENT_CONFIGS,\n RestClient,\n ServiceConfig,\n} from '@reyaxyz/common';\n\nexport type BroadcastTransactionMetadata = {\n accountName?: string;\n};\n\nexport type TxData = {\n to: string;\n data: string;\n};\n\ntype AlphaTermsData = {\n walletAddress: Address;\n link: string;\n};\n\nexport class TransactionModule extends RestClient {\n async executeTransaction(\n txData: TxData,\n contractAddress: string,\n metadata: BroadcastTransactionMetadata,\n ) {\n const uri = `/api/transaction-gelato/executeGelato`;\n // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<{ txHash: string; accountId?: string }>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n }\n}\n\nexport class AlphaTermsModule extends RestClient {\n async registerAlphaSignature(params: AlphaTermsData): Promise<void> {\n // Build formData object.\n const formData = new FormData();\n formData.append('walletAddress', params.walletAddress);\n formData.append('signedLink', params.link);\n\n const uri = '/api/tos/alpha-signatures';\n return this.post(uri, undefined, formData, undefined);\n }\n}\n\n// Internal state\nlet transactionModule: TransactionModule = new TransactionModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\nlet alphaTermsModule: AlphaTermsModule = new AlphaTermsModule(\n API_CLIENT_CONFIGS['test'].apiEndpoint,\n);\n\nlet sdkEnv: ServiceConfig['environment'] = 'test';\n\nexport const getSdkEnvironment = (): ServiceConfig['environment'] => {\n return sdkEnv;\n};\n// Function to configure the SDK\nexport const configureSDK = (\n environment: ServiceConfig['environment'],\n): void => {\n const config = API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n sdkEnv = environment;\n transactionModule = new TransactionModule(config.apiEndpoint);\n alphaTermsModule = new AlphaTermsModule(config.apiEndpoint);\n};\n\nexport const getTransactionModuleClient = (): TransactionModule => {\n if (!transactionModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return transactionModule;\n};\n\nexport const getAlphaTermsModuleClient = (): AlphaTermsModule => {\n if (!alphaTermsModule)\n throw new Error('SDK is not configured! Call configureSDK()');\n return alphaTermsModule;\n};\n"]}
@@ -127,19 +127,29 @@ function signAndBroadcastTransaction(signer, data, value, chainId, targetContrac
127
127
  contractAddress = Object.values(contractAddresses_1.ContractType).includes(targetContract)
128
128
  ? (0, contractAddresses_1.getAddress)(chainId, targetContract)
129
129
  : targetContract;
130
- _b.label = 1;
130
+ // used to catch error in advance since gelato is slow in failing down
131
+ // on reya chain usually takes around 100ms, should be monitored!
132
+ return [4 /*yield*/, estimateGas(signer, data, value, chainId, targetContract)];
131
133
  case 1:
132
- _b.trys.push([1, 3, , 4]);
134
+ // used to catch error in advance since gelato is slow in failing down
135
+ // on reya chain usually takes around 100ms, should be monitored!
136
+ _b.sent();
137
+ _b.label = 2;
138
+ case 2:
139
+ _b.trys.push([2, 4, , 5]);
133
140
  transactionModuleClient = (0, config_1.getTransactionModuleClient)();
134
141
  return [4 /*yield*/, transactionModuleClient.executeTransaction({ to: contractAddress, data: data }, contractAddress, metadata)];
135
- case 2:
142
+ case 3:
136
143
  _a = _b.sent(), txHash = _a.txHash, accountId = _a.accountId;
144
+ if (!txHash) {
145
+ throw new Error('Error sending transaction');
146
+ }
137
147
  return [2 /*return*/, { hash: txHash, accountId: accountId }];
138
- case 3:
148
+ case 4:
139
149
  error_3 = _b.sent();
140
150
  console.warn(error_3);
141
151
  throw new Error('Transaction Execution Error');
142
- case 4: return [2 /*return*/];
152
+ case 5: return [2 /*return*/];
143
153
  }
144
154
  });
145
155
  });
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAsE;AACtE,gDAAkD;AAClD,oCAGmB;AACnB,0C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K,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AA1BD,kEA0BC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ContractType, getAddress } from '../utils/contractAddresses';\nimport { getGasBuffer } from '../utils/txHelpers';\nimport {\n BroadcastTransactionMetadata,\n getTransactionModuleClient,\n} from '../config';\nimport { ReyaChainId } from '@reyaxyz/common';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n // sentry error & thorw\n console.warn(error);\n throw new Error('Error executing transaction'); // @todo introduce error parsing\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n\nexport async function signAndBroadcastTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n metadata: BroadcastTransactionMetadata,\n): Promise<{ hash: string; accountId?: string }> {\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n try {\n const transactionModuleClient = getTransactionModuleClient();\n const { txHash, accountId } =\n await transactionModuleClient.executeTransaction(\n { to: contractAddress, data: data },\n contractAddress,\n metadata,\n );\n return { hash: txHash, accountId };\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
1
+ {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAsE;AACtE,gDAAkD;AAClD,oCAGmB;AACnB,0CAA8C;AAS9C,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAE1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;oBACb,EAAE,cACN,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,eAAe,EACnB,IAAI,MAAA,IACD,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpD,CAAC;oBAEE,QAAQ,GAAW,MAAM,CAAC,SAAS,CAAC,CAAC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KAAa,EACb,OAAe,EACf,cAAqC,EACrC,QAAsC;;;;;;oBAEhC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;oBAEnB,sEAAsE;oBACtE,iEAAiE;oBACjE,qBAAM,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,EAAA;;oBAF/D,sEAAsE;oBACtE,iEAAiE;oBACjE,SAA+D,CAAC;;;;oBAExD,uBAAuB,GAAG,IAAA,mCAA0B,GAAE,CAAC;oBAE3D,qBAAM,uBAAuB,CAAC,kBAAkB,CAC9C,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,EACnC,eAAe,EACf,QAAQ,CACT,EAAA;;oBALG,KACJ,SAIC,EALK,MAAM,YAAA,EAAE,SAAS,eAAA;oBAOzB,IAAI,CAAC,MAAM,EAAE,CAAC;wBACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;oBAC/C,CAAC;oBACD,sBAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,WAAA,EAAE,EAAC;;;oBAEnC,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAlCD,kEAkCC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ContractType, getAddress } from '../utils/contractAddresses';\nimport { getGasBuffer } from '../utils/txHelpers';\nimport {\n BroadcastTransactionMetadata,\n getTransactionModuleClient,\n} from '../config';\nimport { ReyaChainId } from '@reyaxyz/common';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n // sentry error & thorw\n console.warn(error);\n throw new Error('Error executing transaction'); // @todo introduce error parsing\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n\nexport async function signAndBroadcastTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n metadata: BroadcastTransactionMetadata,\n): Promise<{ hash: string; accountId?: string }> {\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n\n // used to catch error in advance since gelato is slow in failing down\n // on reya chain usually takes around 100ms, should be monitored!\n await estimateGas(signer, data, value, chainId, targetContract);\n try {\n const transactionModuleClient = getTransactionModuleClient();\n const { txHash, accountId } =\n await transactionModuleClient.executeTransaction(\n { to: contractAddress, data: data },\n contractAddress,\n metadata,\n );\n\n if (!txHash) {\n throw new Error('Error sending transaction');\n }\n return { hash: txHash, accountId };\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["services/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAc,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EACL,4BAA4B,EAE7B,MAAM,WAAW,CAAC;AAGnB,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,GACpC,OAAO,CACR,WAAW,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAiCA;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,uDAkBtC;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,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AAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,EACrC,QAAQ,EAAE,4BAA4B,GACrC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA2B/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/sdk",
3
- "version": "0.78.2",
3
+ "version": "0.79.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -29,10 +29,10 @@
29
29
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
30
30
  },
31
31
  "dependencies": {
32
- "@reyaxyz/common": "0.93.1",
32
+ "@reyaxyz/common": "0.94.0",
33
33
  "bignumber.js": "^9.1.2",
34
34
  "ethers": "6.9.0"
35
35
  },
36
36
  "packageManager": "pnpm@8.3.1",
37
- "gitHead": "4cb15327562c48491a5d1313386d207447f76772"
37
+ "gitHead": "e8ab18452b7298d862f6aa4a06552a1eecd6236d"
38
38
  }
@@ -25,8 +25,8 @@ export class TransactionModule extends RestClient {
25
25
  contractAddress: string,
26
26
  metadata: BroadcastTransactionMetadata,
27
27
  ) {
28
- // const uri = `/api/transaction-gelato/executeGelato`;
29
- const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer
28
+ const uri = `/api/transaction-gelato/executeGelato`;
29
+ // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer
30
30
  return this.post<{ txHash: string; accountId?: string }>(
31
31
  uri,
32
32
  {},
@@ -99,6 +99,10 @@ export async function signAndBroadcastTransaction(
99
99
  )
100
100
  ? getAddress(chainId, targetContract as ContractType)
101
101
  : targetContract;
102
+
103
+ // used to catch error in advance since gelato is slow in failing down
104
+ // on reya chain usually takes around 100ms, should be monitored!
105
+ await estimateGas(signer, data, value, chainId, targetContract);
102
106
  try {
103
107
  const transactionModuleClient = getTransactionModuleClient();
104
108
  const { txHash, accountId } =
@@ -107,6 +111,10 @@ export async function signAndBroadcastTransaction(
107
111
  contractAddress,
108
112
  metadata,
109
113
  );
114
+
115
+ if (!txHash) {
116
+ throw new Error('Error sending transaction');
117
+ }
110
118
  return { hash: txHash, accountId };
111
119
  } catch (error) {
112
120
  console.warn(error);