@reyaxyz/common 0.135.2 → 0.136.0
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 +1 -1
- package/dist/transactions/executeTransaction.js +10 -5
- package/dist/transactions/executeTransaction.js.map +1 -1
- package/dist/types/transactions/executeTransaction.d.ts +2 -2
- package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/transactions/executeTransaction.ts +9 -5
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -46,17 +46,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var _a;
|
|
49
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
51
|
exports.executeTransaction = exports.estimateGas = void 0;
|
|
52
|
+
var ethers_1 = require("ethers");
|
|
51
53
|
var types_1 = require("../types");
|
|
52
54
|
var contractAddresses_1 = require("./contractAddresses");
|
|
53
|
-
var txHelpers_1 = require("./txHelpers");
|
|
54
55
|
var Errors_json_1 = require("./abis/Errors.json");
|
|
55
56
|
var ethers_decode_error_1 = require("ethers-decode-error");
|
|
57
|
+
var reyaChainIdRPCMapper = (_a = {},
|
|
58
|
+
_a[types_1.ReyaChainId.reyaNetwork] = 'https://rpc.reya.network',
|
|
59
|
+
_a[types_1.ReyaChainId.reyaCronos] = 'https://rpc.reya-cronos.gelato.digital',
|
|
60
|
+
_a);
|
|
56
61
|
var errorDecoder = ethers_decode_error_1.ErrorDecoder.create([Errors_json_1.abi]);
|
|
57
62
|
function estimateGas(signer, data, value, chainId, targetContract) {
|
|
58
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
var accountAddress, contractAddress, tx, gasLimit,
|
|
64
|
+
var accountAddress, contractAddress, tx, gasLimit, provider, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
|
|
60
65
|
return __generator(this, function (_a) {
|
|
61
66
|
switch (_a.label) {
|
|
62
67
|
case 0: return [4 /*yield*/, signer.getAddress()];
|
|
@@ -70,10 +75,10 @@ function estimateGas(signer, data, value, chainId, targetContract) {
|
|
|
70
75
|
_a.label = 2;
|
|
71
76
|
case 2:
|
|
72
77
|
_a.trys.push([2, 4, , 6]);
|
|
73
|
-
|
|
78
|
+
provider = ethers_1.ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);
|
|
79
|
+
return [4 /*yield*/, provider.call(tx)];
|
|
74
80
|
case 3:
|
|
75
|
-
|
|
76
|
-
gasLimit = (0, txHelpers_1.getGasBuffer)(gasEstimate);
|
|
81
|
+
_a.sent();
|
|
77
82
|
return [3 /*break*/, 6];
|
|
78
83
|
case 4:
|
|
79
84
|
error_1 = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAuD;AACvD,kCAAuC;AACvC,yDAA+D;AAC/D,kDAAyC;AACzC,2DAAmD;AAGnD,IAAM,oBAAoB;IACxB,GAAC,mBAAW,CAAC,WAAW,IAAG,0BAA0B;IACrD,GAAC,mBAAW,CAAC,UAAU,IAAG,wCAAwC;OACnE,CAAC;AAQF,IAAM,YAAY,GAAG,kCAAY,CAAC,MAAM,CAAC,CAAC,iBAAG,CAAC,CAAC,CAAC;AAEhD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,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yaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\n\nconst reyaChainIdRPCMapper: { [key: number]: string } = {\n [ReyaChainId.reyaNetwork]: 'https://rpc.reya.network',\n [ReyaChainId.reyaCronos]: 'https://rpc.reya-cronos.gelato.digital',\n};\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\nconst errorDecoder = ErrorDecoder.create([abi]);\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 const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const provider = ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);\n await provider.call(tx);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,\n );\n throw new Error(reason);\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}\nconst customReasonMapper = ({ name, reason }: DecodedError): string => {\n switch (name) {\n case 'SignatureInvalid':\n return `Invalid signature. Please refresh page and try again`;\n case 'StalePriceDetected':\n return `Price not updated, please try again a bit later`;\n case 'SmallOrderSize':\n return `Order size below minimum`;\n case 'DustyOrderSize':\n return `Order amount is not divisible by trade size spacing`;\n case 'AccountBelowIM':\n return `Account below required margin`;\n default:\n // This handles the non-custom errors\n return reason ?? 'Error executing transaction';\n }\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
1
|
+
import { ethers, JsonRpcSigner, Signer } from 'ethers';
|
|
2
2
|
import { ContractType } from './contractAddresses';
|
|
3
3
|
export type Transaction = {
|
|
4
4
|
from: string;
|
|
@@ -11,5 +11,5 @@ export declare function estimateGas(signer: Signer | JsonRpcSigner, data: string
|
|
|
11
11
|
maxPriorityFeePerGas?: bigint;
|
|
12
12
|
maxFeePerGas?: bigint;
|
|
13
13
|
}>;
|
|
14
|
-
export declare function executeTransaction(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<
|
|
14
|
+
export declare function executeTransaction(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<ethers.TransactionReceipt | null>;
|
|
15
15
|
//# sourceMappingURL=executeTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAU/D,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;AAGF,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,CAoCA;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,6CAkBtC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.136.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
44
44
|
},
|
|
45
45
|
"packageManager": "pnpm@8.3.1",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "51ccbadf06f7980fbcbaac1a1fc43157d6c90ad5"
|
|
47
47
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
1
|
+
import { ethers, JsonRpcSigner, Signer } from 'ethers';
|
|
2
2
|
import { ReyaChainId } from '../types';
|
|
3
3
|
import { ContractType, getAddress } from './contractAddresses';
|
|
4
|
-
import { getGasBuffer } from './txHelpers';
|
|
5
4
|
import { abi } from './abis/Errors.json';
|
|
6
5
|
import { ErrorDecoder } from 'ethers-decode-error';
|
|
7
6
|
import type { DecodedError } from 'ethers-decode-error';
|
|
8
7
|
|
|
8
|
+
const reyaChainIdRPCMapper: { [key: number]: string } = {
|
|
9
|
+
[ReyaChainId.reyaNetwork]: 'https://rpc.reya.network',
|
|
10
|
+
[ReyaChainId.reyaCronos]: 'https://rpc.reya-cronos.gelato.digital',
|
|
11
|
+
};
|
|
12
|
+
|
|
9
13
|
export type Transaction = {
|
|
10
14
|
from: string;
|
|
11
15
|
to: string;
|
|
@@ -41,11 +45,11 @@ export async function estimateGas(
|
|
|
41
45
|
...(value && value !== '0' ? { value: value } : {}),
|
|
42
46
|
};
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate
|
|
45
49
|
|
|
46
50
|
try {
|
|
47
|
-
const
|
|
48
|
-
|
|
51
|
+
const provider = ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);
|
|
52
|
+
await provider.call(tx);
|
|
49
53
|
} catch (error) {
|
|
50
54
|
const decodedError = await errorDecoder.decode(error);
|
|
51
55
|
const reason = customReasonMapper(decodedError);
|