@reyaxyz/sdk 0.90.1 → 0.90.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/config/index.js.map +1 -1
- package/dist/services/signAndBroadcastTransaction.js +10 -10
- package/dist/services/signAndBroadcastTransaction.js.map +1 -1
- package/dist/types/config/index.d.ts +2 -5
- package/dist/types/config/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/config/index.ts +2 -1
- package/src/services/signAndBroadcastTransaction.ts +3 -3
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAOyB;AAYzB;IAAuC,qCAAU;IAAjD;;IAwCA,CAAC;IAvCO,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;IAEK,kDAAsB,GAA5B,UACE,eAAuB,EACvB,eAAuB,EACvB,aAAqB,EACrB,MAAc,EACd,OAAe,EACf,IAAY;;;;gBAEN,GAAG,GAAG,wBAAiB,eAAe,8BAA2B,CAAC;gBACxE,sBAAO,IAAI,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF;wBACE,OAAO,EAAE,eAAe;wBACxB,eAAe,EAAE,aAAa;wBAC9B,MAAM,QA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AAgB,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 TransactionExecutionMetadata,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\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: TransactionExecutionMetadata,\n ) {\n const uri = `/api/transaction-gelato/executeGelato`;\n // const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer\n return this.post<TransactionExecutionOutput>(\n uri,\n {},\n {\n txData: txData,\n contractAddress,\n metadata,\n },\n );\n }\n\n async pushPendingTransaction(\n marginAccountId: number,\n transactionHash: string,\n sourceChainId: number,\n amount: number,\n assetId: string,\n type: string,\n ) {\n const uri = `/api/accounts/${marginAccountId}/push-pending-transaction`;\n return this.post<{ successful: boolean }>(\n uri,\n {},\n {\n tx_hash: transactionHash,\n source_chain_id: sourceChainId,\n amount,\n asset_id: assetId,\n type: type,\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"]}
|
|
@@ -41,9 +41,9 @@ var common_1 = require("@reyaxyz/common");
|
|
|
41
41
|
var config_1 = require("../config");
|
|
42
42
|
function signAndBroadcastTransaction(signer, data, value, chainId, targetContract, metadata) {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var contractAddress, transactionModuleClient,
|
|
45
|
-
return __generator(this, function (
|
|
46
|
-
switch (
|
|
44
|
+
var contractAddress, transactionModuleClient, transactionExecutionOutput, error_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
47
|
case 0:
|
|
48
48
|
contractAddress = Object.values(common_1.ContractType).includes(targetContract)
|
|
49
49
|
? (0, common_1.getAddress)(chainId, targetContract)
|
|
@@ -54,20 +54,20 @@ function signAndBroadcastTransaction(signer, data, value, chainId, targetContrac
|
|
|
54
54
|
case 1:
|
|
55
55
|
// used to catch error in advance since gelato is slow in failing down
|
|
56
56
|
// on reya chain usually takes around 100ms, should be monitored!
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
_a.sent();
|
|
58
|
+
_a.label = 2;
|
|
59
59
|
case 2:
|
|
60
|
-
|
|
60
|
+
_a.trys.push([2, 4, , 5]);
|
|
61
61
|
transactionModuleClient = (0, config_1.getTransactionModuleClient)();
|
|
62
62
|
return [4 /*yield*/, transactionModuleClient.executeTransaction({ to: contractAddress, data: data }, contractAddress, metadata)];
|
|
63
63
|
case 3:
|
|
64
|
-
|
|
65
|
-
if (!txHash) {
|
|
64
|
+
transactionExecutionOutput = _a.sent();
|
|
65
|
+
if (!transactionExecutionOutput.txHash) {
|
|
66
66
|
throw new Error('Error sending transaction');
|
|
67
67
|
}
|
|
68
|
-
return [2 /*return*/,
|
|
68
|
+
return [2 /*return*/, transactionExecutionOutput];
|
|
69
69
|
case 4:
|
|
70
|
-
error_1 =
|
|
70
|
+
error_1 = _a.sent();
|
|
71
71
|
console.warn(error_1);
|
|
72
72
|
throw new Error('Transaction Execution Error');
|
|
73
73
|
case 5: return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signAndBroadcastTransaction.js","sourceRoot":"/","sources":["services/signAndBroadcastTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAMyB;AACzB,oCAAuD;AAEvD,SAAsB,2BAA2B,CAC/C,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC,EACrC,QAAsC;;;;;;oBAEhC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,mBAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;o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9B,SAIC;oBAEH,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,CAAC;wBACvC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;oBAC/C,CAAC;oBACD,sBAAO,0BAA0B,EAAC;;;oBAElC,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 {\n ContractType,\n getAddress,\n estimateGas,\n TransactionExecutionMetadata,\n TransactionExecutionOutput,\n} from '@reyaxyz/common';\nimport { getTransactionModuleClient } from '../config';\n\nexport async function signAndBroadcastTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n metadata: TransactionExecutionMetadata,\n): Promise<TransactionExecutionOutput> {\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 transactionExecutionOutput =\n await transactionModuleClient.executeTransaction(\n { to: contractAddress, data: data },\n contractAddress,\n metadata,\n );\n\n if (!transactionExecutionOutput.txHash) {\n throw new Error('Error sending transaction');\n }\n return transactionExecutionOutput;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata } from '@reyaxyz/common';
|
|
1
|
+
import { Address, RestClient, ServiceConfig, TransactionExecutionMetadata, TransactionExecutionOutput } from '@reyaxyz/common';
|
|
2
2
|
export type TxData = {
|
|
3
3
|
to: string;
|
|
4
4
|
data: string;
|
|
@@ -8,10 +8,7 @@ type AlphaTermsData = {
|
|
|
8
8
|
link: string;
|
|
9
9
|
};
|
|
10
10
|
export declare class TransactionModule extends RestClient {
|
|
11
|
-
executeTransaction(txData: TxData, contractAddress: string, metadata: TransactionExecutionMetadata): Promise<
|
|
12
|
-
txHash: string;
|
|
13
|
-
accountId?: string | undefined;
|
|
14
|
-
}>;
|
|
11
|
+
executeTransaction(txData: TxData, contractAddress: string, metadata: TransactionExecutionMetadata): Promise<TransactionExecutionOutput>;
|
|
15
12
|
pushPendingTransaction(marginAccountId: number, transactionHash: string, sourceChainId: number, amount: number, assetId: string, type: string): Promise<{
|
|
16
13
|
successful: boolean;
|
|
17
14
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,aAAa,EACb,4BAA4B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACV,aAAa,EACb,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,UAAU;IACzC,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,4BAA4B;IAelC,sBAAsB,CAC1B,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM;oBAGmB,OAAO;;CAYzC;AAED,qBAAa,gBAAiB,SAAQ,UAAU;IACxC,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASpE;AAYD,eAAO,MAAM,iBAAiB,QAAO,aAAa,CAAC,aAAa,CAE/D,CAAC;AAEF,eAAO,MAAM,YAAY,gBACV,aAAa,CAAC,aAAa,CAAC,KACxC,IAKF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAAO,iBAI7C,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,gBAI5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.3",
|
|
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.105.
|
|
32
|
+
"@reyaxyz/common": "0.105.1",
|
|
33
33
|
"bignumber.js": "^9.1.2",
|
|
34
34
|
"ethers": "6.9.0"
|
|
35
35
|
},
|
|
36
36
|
"packageManager": "pnpm@8.3.1",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9343c5063fa541031bc107dfcc4aecaab4be04c3"
|
|
38
38
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
RestClient,
|
|
5
5
|
ServiceConfig,
|
|
6
6
|
TransactionExecutionMetadata,
|
|
7
|
+
TransactionExecutionOutput,
|
|
7
8
|
} from '@reyaxyz/common';
|
|
8
9
|
|
|
9
10
|
export type TxData = {
|
|
@@ -24,7 +25,7 @@ export class TransactionModule extends RestClient {
|
|
|
24
25
|
) {
|
|
25
26
|
const uri = `/api/transaction-gelato/executeGelato`;
|
|
26
27
|
// const uri = `/api/transaction/execute`; //switch between Gelato and internal relayer
|
|
27
|
-
return this.post<
|
|
28
|
+
return this.post<TransactionExecutionOutput>(
|
|
28
29
|
uri,
|
|
29
30
|
{},
|
|
30
31
|
{
|
|
@@ -27,17 +27,17 @@ export async function signAndBroadcastTransaction(
|
|
|
27
27
|
await estimateGas(signer, data, value, chainId, targetContract);
|
|
28
28
|
try {
|
|
29
29
|
const transactionModuleClient = getTransactionModuleClient();
|
|
30
|
-
const
|
|
30
|
+
const transactionExecutionOutput =
|
|
31
31
|
await transactionModuleClient.executeTransaction(
|
|
32
32
|
{ to: contractAddress, data: data },
|
|
33
33
|
contractAddress,
|
|
34
34
|
metadata,
|
|
35
35
|
);
|
|
36
36
|
|
|
37
|
-
if (!txHash) {
|
|
37
|
+
if (!transactionExecutionOutput.txHash) {
|
|
38
38
|
throw new Error('Error sending transaction');
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return transactionExecutionOutput;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
console.warn(error);
|
|
43
43
|
throw new Error('Transaction Execution Error');
|