refactor SafeMath rich errors and use them in staking libs
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import { BigNumber } from './configured_bignumber';
|
||||
import { RevertError } from './revert_error';
|
||||
|
||||
export enum SafeMathErrorCodes {
|
||||
Uint256AdditionOverflow,
|
||||
Uint256MultiplicationOverflow,
|
||||
Uint256SubtractionUnderflow,
|
||||
Uint256DivisionByZero,
|
||||
// tslint:disable:max-classes-per-file
|
||||
|
||||
export enum BinopErrorCodes {
|
||||
AdditionOverflow,
|
||||
MultiplicationOverflow,
|
||||
SubtractionUnderflow,
|
||||
DivisionByZero,
|
||||
}
|
||||
|
||||
export class SafeMathError extends RevertError {
|
||||
constructor(error?: SafeMathErrorCodes, a?: BigNumber, b?: BigNumber) {
|
||||
super('SafeMathError', 'SafeMathError(uint8 error, uint256 a, uint256 b)', {
|
||||
export enum DowncastErrorCodes {
|
||||
ValueTooLargeToDowncastToUint64,
|
||||
ValueTooLargeToDowncastToUint96,
|
||||
}
|
||||
|
||||
export class Uint256BinopError extends RevertError {
|
||||
constructor(error?: BinopErrorCodes, a?: BigNumber, b?: BigNumber) {
|
||||
super('Uint256BinopError', 'Uint256BinopError(uint8 error, uint256 a, uint256 b)', {
|
||||
error,
|
||||
a,
|
||||
b,
|
||||
@@ -18,4 +25,38 @@ export class SafeMathError extends RevertError {
|
||||
}
|
||||
}
|
||||
|
||||
RevertError.registerType(SafeMathError);
|
||||
export class Uint96BinopError extends RevertError {
|
||||
constructor(error?: BinopErrorCodes, a?: BigNumber, b?: BigNumber) {
|
||||
super('Uint96BinopError', 'Uint96BinopError(uint8 error, uint96 a, uint96 b)', {
|
||||
error,
|
||||
a,
|
||||
b,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class Uint64BinopError extends RevertError {
|
||||
constructor(error?: BinopErrorCodes, a?: BigNumber, b?: BigNumber) {
|
||||
super('Uint64BinopError', 'Uint64BinopError(uint8 error, uint64 a, uint64 b)', {
|
||||
error,
|
||||
a,
|
||||
b,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class Uint256DowncastError extends RevertError {
|
||||
constructor(error?: DowncastErrorCodes, a?: BigNumber) {
|
||||
super('Uint256DowncastError', 'Uint256DowncastError(uint8 error, uint256 a)', {
|
||||
error,
|
||||
a,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const types = [Uint256BinopError, Uint96BinopError, Uint64BinopError, Uint256DowncastError];
|
||||
|
||||
// Register the types we've defined.
|
||||
for (const type of types) {
|
||||
RevertError.registerType(type);
|
||||
}
|
||||
|
Reference in New Issue
Block a user