@reyaxyz/common 0.114.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/commands/exposure/command.js +0 -1
- package/dist/commands/exposure/command.js.map +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/commands/exposure/command.d.ts.map +1 -1
- package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/commands/exposure/command.ts +0 -2
- package/src/transactions/abis/Errors.json +3591 -0
- package/src/transactions/executeTransaction.ts +25 -3
|
@@ -2,6 +2,9 @@ import { JsonRpcSigner, Signer } from 'ethers';
|
|
|
2
2
|
import { ReyaChainId } from '../types';
|
|
3
3
|
import { ContractType, getAddress } from './contractAddresses';
|
|
4
4
|
import { getGasBuffer } from './txHelpers';
|
|
5
|
+
import { abi } from './abis/Errors.json';
|
|
6
|
+
import { ErrorDecoder } from 'ethers-decode-error';
|
|
7
|
+
import type { DecodedError } from 'ethers-decode-error';
|
|
5
8
|
|
|
6
9
|
export type Transaction = {
|
|
7
10
|
from: string;
|
|
@@ -9,6 +12,7 @@ export type Transaction = {
|
|
|
9
12
|
data: string;
|
|
10
13
|
value?: string;
|
|
11
14
|
};
|
|
15
|
+
const errorDecoder = ErrorDecoder.create([abi]);
|
|
12
16
|
|
|
13
17
|
export async function estimateGas(
|
|
14
18
|
signer: Signer | JsonRpcSigner,
|
|
@@ -43,11 +47,12 @@ export async function estimateGas(
|
|
|
43
47
|
const gasEstimate = await signer.estimateGas(tx);
|
|
44
48
|
gasLimit = getGasBuffer(gasEstimate);
|
|
45
49
|
} catch (error) {
|
|
46
|
-
|
|
50
|
+
const decodedError = await errorDecoder.decode(error);
|
|
51
|
+
const reason = customReasonMapper(decodedError);
|
|
47
52
|
console.error(
|
|
48
|
-
`Error simulating transaction account address ${accountAddress} ${error}`,
|
|
53
|
+
`Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,
|
|
49
54
|
);
|
|
50
|
-
throw new Error(
|
|
55
|
+
throw new Error(reason);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {
|
|
@@ -83,3 +88,20 @@ export async function executeTransaction(
|
|
|
83
88
|
throw new Error('Transaction Execution Error');
|
|
84
89
|
}
|
|
85
90
|
}
|
|
91
|
+
const customReasonMapper = ({ name, reason }: DecodedError): string => {
|
|
92
|
+
switch (name) {
|
|
93
|
+
case 'SignatureInvalid':
|
|
94
|
+
return `Invalid signature. Please refresh page and try again`;
|
|
95
|
+
case 'StalePriceDetected':
|
|
96
|
+
return `Price not updated, please try again a bit later`;
|
|
97
|
+
case 'SmallOrderSize':
|
|
98
|
+
return `Order size below minimum`;
|
|
99
|
+
case 'DustyOrderSize':
|
|
100
|
+
return `Order amount is not divisible by trade size spacing`;
|
|
101
|
+
case 'AccountBelowIM':
|
|
102
|
+
return `Account below required margin`;
|
|
103
|
+
default:
|
|
104
|
+
// This handles the non-custom errors
|
|
105
|
+
return reason ?? 'Error executing transaction';
|
|
106
|
+
}
|
|
107
|
+
};
|