@reyaxyz/common 0.115.0 → 0.116.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/abis/Errors.json +3591 -0
- package/dist/transactions/executeTransaction.js +30 -6
- package/dist/transactions/executeTransaction.js.map +1 -1
- package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/transactions/abis/Errors.json +3591 -0
- package/src/transactions/executeTransaction.ts +25 -3
|
@@ -51,9 +51,12 @@ exports.executeTransaction = exports.estimateGas = void 0;
|
|
|
51
51
|
var types_1 = require("../types");
|
|
52
52
|
var contractAddresses_1 = require("./contractAddresses");
|
|
53
53
|
var txHelpers_1 = require("./txHelpers");
|
|
54
|
+
var Errors_json_1 = require("./abis/Errors.json");
|
|
55
|
+
var ethers_decode_error_1 = require("ethers-decode-error");
|
|
56
|
+
var errorDecoder = ethers_decode_error_1.ErrorDecoder.create([Errors_json_1.abi]);
|
|
54
57
|
function estimateGas(signer, data, value, chainId, targetContract) {
|
|
55
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_1, maxPriorityFeePerGas, maxFeePerGas;
|
|
59
|
+
var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
|
|
57
60
|
return __generator(this, function (_a) {
|
|
58
61
|
switch (_a.label) {
|
|
59
62
|
case 0: return [4 /*yield*/, signer.getAddress()];
|
|
@@ -66,18 +69,21 @@ function estimateGas(signer, data, value, chainId, targetContract) {
|
|
|
66
69
|
gasLimit = BigInt('5000000');
|
|
67
70
|
_a.label = 2;
|
|
68
71
|
case 2:
|
|
69
|
-
_a.trys.push([2, 4, ,
|
|
72
|
+
_a.trys.push([2, 4, , 6]);
|
|
70
73
|
return [4 /*yield*/, signer.estimateGas(tx)];
|
|
71
74
|
case 3:
|
|
72
75
|
gasEstimate = _a.sent();
|
|
73
76
|
gasLimit = (0, txHelpers_1.getGasBuffer)(gasEstimate);
|
|
74
|
-
return [3 /*break*/,
|
|
77
|
+
return [3 /*break*/, 6];
|
|
75
78
|
case 4:
|
|
76
79
|
error_1 = _a.sent();
|
|
77
|
-
|
|
78
|
-
console.error("Error simulating transaction account address ".concat(accountAddress, " ").concat(error_1));
|
|
79
|
-
throw new Error('Error executing transaction'); // @todo introduce error parsing
|
|
80
|
+
return [4 /*yield*/, errorDecoder.decode(error_1)];
|
|
80
81
|
case 5:
|
|
82
|
+
decodedError = _a.sent();
|
|
83
|
+
reason = customReasonMapper(decodedError);
|
|
84
|
+
console.error("Error simulating transaction account address ".concat(accountAddress, " reason ").concat(decodedError === null || decodedError === void 0 ? void 0 : decodedError.name, " ").concat(decodedError, " ").concat(error_1));
|
|
85
|
+
throw new Error(reason);
|
|
86
|
+
case 6:
|
|
81
87
|
if (Object.values(types_1.ReyaChainId).includes(chainId)) {
|
|
82
88
|
maxPriorityFeePerGas = BigInt('0');
|
|
83
89
|
maxFeePerGas = BigInt('100000000');
|
|
@@ -117,4 +123,22 @@ function executeTransaction(signer, data, value, chainId, targetContract) {
|
|
|
117
123
|
});
|
|
118
124
|
}
|
|
119
125
|
exports.executeTransaction = executeTransaction;
|
|
126
|
+
var customReasonMapper = function (_a) {
|
|
127
|
+
var name = _a.name, reason = _a.reason;
|
|
128
|
+
switch (name) {
|
|
129
|
+
case 'SignatureInvalid':
|
|
130
|
+
return "Invalid signature. Please refresh page and try again";
|
|
131
|
+
case 'StalePriceDetected':
|
|
132
|
+
return "Price not updated, please try again a bit later";
|
|
133
|
+
case 'SmallOrderSize':
|
|
134
|
+
return "Order size below minimum";
|
|
135
|
+
case 'DustyOrderSize':
|
|
136
|
+
return "Order amount is not divisible by trade size spacing";
|
|
137
|
+
case 'AccountBelowIM':
|
|
138
|
+
return "Account below required margin";
|
|
139
|
+
default:
|
|
140
|
+
// This handles the non-custom errors
|
|
141
|
+
return reason !== null && reason !== void 0 ? reason : 'Error executing transaction';
|
|
142
|
+
}
|
|
143
|
+
};
|
|
120
144
|
//# sourceMappingURL=executeTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAuC;AACvC,yDAA+D;AAC/D,yCAA2C;
|
|
1
|
+
{"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAuC;AACvC,yDAA+D;AAC/D,yCAA2C;AAC3C,kDAAyC;AACzC,2DAAmD;AASnD,IAAM,YAAY,GAAG,kCAAY,CAAC,MAAM,CAAC,CAAC,iBAAG,CAAC,CAAC,CAAC;AAEhD,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;;;;oBAGnB,qBA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EjB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAvBD,gDAuBC;AACD,IAAM,kBAAkB,GAAG,UAAC,EAA8B;QAA5B,IAAI,UAAA,EAAE,MAAM,YAAA;IACxC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAkB;YACrB,OAAO,sDAAsD,CAAC;QAChE,KAAK,oBAAoB;YACvB,OAAO,iDAAiD,CAAC;QAC3D,KAAK,gBAAgB;YACnB,OAAO,0BAA0B,CAAC;QACpC,KAAK,gBAAgB;YACnB,OAAO,qDAAqD,CAAC;QAC/D,KAAK,gBAAgB;YACnB,OAAO,+BAA+B,CAAC;QACzC;YACE,qCAAqC;YACrC,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,6BAA6B,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ReyaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { getGasBuffer } from './txHelpers';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\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 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 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 +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;AAE/C,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAM/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,uDAkBtC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"axios": "^1.6.2",
|
|
25
25
|
"bignumber.js": "^9.1.2",
|
|
26
26
|
"ethers": "6.9.0",
|
|
27
|
+
"ethers-decode-error": "^2.1.3",
|
|
27
28
|
"lodash.clonedeep": "4.5.0"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
@@ -42,5 +43,5 @@
|
|
|
42
43
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
43
44
|
},
|
|
44
45
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "451f5ad174f0ba7adb3404c5e5660e6c1bdbf6cd"
|
|
46
47
|
}
|