Skip to content

Commit 498acdb

Browse files
committed
fix: add exceptions for better error decoding
1 parent 31a20e3 commit 498acdb

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

src/sdk/abi/errors.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
export const iRouterV3ErrorsAbi = [
2+
{
3+
type: "error",
4+
inputs: [
5+
{ name: "tokenIn", internalType: "address", type: "address" },
6+
{ name: "tokenOut", internalType: "address", type: "address" },
7+
],
8+
name: "PathNotFoundException",
9+
},
10+
{
11+
type: "error",
12+
inputs: [
13+
{ name: "ttIn", internalType: "uint8", type: "uint8" },
14+
{ name: "tokenOut", internalType: "address", type: "address" },
15+
],
16+
name: "PathNotFoundExceptionTyped",
17+
},
18+
{
19+
type: "error",
20+
inputs: [{ name: "tokenOut", internalType: "address", type: "address" }],
21+
name: "PathToTargetNotFound",
22+
},
23+
{ type: "error", inputs: [], name: "UnsupportedAdapterType" },
24+
{
25+
type: "error",
26+
inputs: [{ name: "", internalType: "address", type: "address" }],
27+
name: "UnsupportedRouterComponent",
28+
},
29+
] as const;
30+
31+
export const iExceptionsAbi = [
32+
{ type: "error", inputs: [], name: "ActiveCreditAccountNotSetException" },
33+
{ type: "error", inputs: [], name: "ActiveCreditAccountOverridenException" },
34+
{ type: "error", inputs: [], name: "AdapterIsNotRegisteredException" },
35+
{
36+
type: "error",
37+
inputs: [{ name: "", internalType: "address", type: "address" }],
38+
name: "AddressIsNotContractException",
39+
},
40+
{ type: "error", inputs: [], name: "AddressNotFoundException" },
41+
{ type: "error", inputs: [], name: "AllowanceFailedException" },
42+
{ type: "error", inputs: [], name: "AmountCantBeZeroException" },
43+
{ type: "error", inputs: [], name: "BalanceLessThanExpectedException" },
44+
{ type: "error", inputs: [], name: "BorrowAmountOutOfLimitsException" },
45+
{ type: "error", inputs: [], name: "BorrowedBlockLimitException" },
46+
{ type: "error", inputs: [], name: "BorrowingMoreThanU2ForbiddenException" },
47+
{ type: "error", inputs: [], name: "CallerNotAccountFactoryException" },
48+
{ type: "error", inputs: [], name: "CallerNotAdapterException" },
49+
{ type: "error", inputs: [], name: "CallerNotConfiguratorException" },
50+
{ type: "error", inputs: [], name: "CallerNotControllerException" },
51+
{ type: "error", inputs: [], name: "CallerNotCreditAccountOwnerException" },
52+
{ type: "error", inputs: [], name: "CallerNotCreditFacadeException" },
53+
{ type: "error", inputs: [], name: "CallerNotCreditManagerException" },
54+
{ type: "error", inputs: [], name: "CallerNotExecutorException" },
55+
{ type: "error", inputs: [], name: "CallerNotGaugeException" },
56+
{ type: "error", inputs: [], name: "CallerNotMigratorException" },
57+
{ type: "error", inputs: [], name: "CallerNotPausableAdminException" },
58+
{ type: "error", inputs: [], name: "CallerNotPoolQuotaKeeperException" },
59+
{ type: "error", inputs: [], name: "CallerNotUnpausableAdminException" },
60+
{ type: "error", inputs: [], name: "CallerNotVetoAdminException" },
61+
{ type: "error", inputs: [], name: "CallerNotVoterException" },
62+
{ type: "error", inputs: [], name: "CloseAccountWithEnabledTokensException" },
63+
{ type: "error", inputs: [], name: "CloseAccountWithNonZeroDebtException" },
64+
{ type: "error", inputs: [], name: "CreditAccountDoesNotExistException" },
65+
{ type: "error", inputs: [], name: "CreditAccountIsInUseException" },
66+
{ type: "error", inputs: [], name: "CreditAccountNotLiquidatableException" },
67+
{ type: "error", inputs: [], name: "CreditManagerCantBorrowException" },
68+
{ type: "error", inputs: [], name: "CustomHealthFactorTooLowException" },
69+
{ type: "error", inputs: [], name: "DebtToZeroWithActiveQuotasException" },
70+
{ type: "error", inputs: [], name: "DebtUpdatedTwiceInOneBlockException" },
71+
{ type: "error", inputs: [], name: "ExpectedBalancesAlreadySetException" },
72+
{ type: "error", inputs: [], name: "ExpectedBalancesNotSetException" },
73+
{ type: "error", inputs: [], name: "ForbiddenInWhitelistedModeException" },
74+
{
75+
type: "error",
76+
inputs: [],
77+
name: "ForbiddenTokenBalanceIncreasedException",
78+
},
79+
{ type: "error", inputs: [], name: "ForbiddenTokenEnabledException" },
80+
{ type: "error", inputs: [], name: "ForbiddenTokensException" },
81+
{ type: "error", inputs: [], name: "IncompatibleContractException" },
82+
{ type: "error", inputs: [], name: "IncompatibleCreditManagerException" },
83+
{ type: "error", inputs: [], name: "IncompatiblePoolQuotaKeeperException" },
84+
{ type: "error", inputs: [], name: "IncompatibleSuccessorException" },
85+
{ type: "error", inputs: [], name: "IncorrectExpirationDateException" },
86+
{ type: "error", inputs: [], name: "IncorrectLimitsException" },
87+
{ type: "error", inputs: [], name: "IncorrectLiquidationThresholdException" },
88+
{ type: "error", inputs: [], name: "IncorrectParameterException" },
89+
{ type: "error", inputs: [], name: "IncorrectPriceException" },
90+
{ type: "error", inputs: [], name: "IncorrectPriceFeedException" },
91+
{ type: "error", inputs: [], name: "IncorrectTokenContractException" },
92+
{ type: "error", inputs: [], name: "InsufficientBalanceException" },
93+
{ type: "error", inputs: [], name: "InsufficientRemainingFundsException" },
94+
{ type: "error", inputs: [], name: "InsufficientVotesException" },
95+
{ type: "error", inputs: [], name: "InvalidBotException" },
96+
{ type: "error", inputs: [], name: "InvalidCollateralHintException" },
97+
{
98+
type: "error",
99+
inputs: [],
100+
name: "MasterCreditAccountAlreadyDeployedException",
101+
},
102+
{
103+
type: "error",
104+
inputs: [{ name: "permission", internalType: "uint256", type: "uint256" }],
105+
name: "NoPermissionException",
106+
},
107+
{ type: "error", inputs: [], name: "NotAllowedAfterExpirationException" },
108+
{ type: "error", inputs: [], name: "NotAllowedWhenNotExpirableException" },
109+
{ type: "error", inputs: [], name: "NotApprovedBotException" },
110+
{ type: "error", inputs: [], name: "NotEnoughCollateralException" },
111+
{ type: "error", inputs: [], name: "NotImplementedException" },
112+
{ type: "error", inputs: [], name: "ParameterChangedAfterQueuedTxException" },
113+
{ type: "error", inputs: [], name: "ParameterChecksFailedException" },
114+
{ type: "error", inputs: [], name: "PriceFeedDoesNotExistException" },
115+
{ type: "error", inputs: [], name: "QuotaIsOutOfBoundsException" },
116+
{ type: "error", inputs: [], name: "ReceiveIsNotAllowedException" },
117+
{ type: "error", inputs: [], name: "RegisteredCreditManagerOnlyException" },
118+
{ type: "error", inputs: [], name: "RegisteredPoolOnlyException" },
119+
{
120+
type: "error",
121+
inputs: [],
122+
name: "RemainingTokenBalanceIncreasedException",
123+
},
124+
{ type: "error", inputs: [], name: "StalePriceException" },
125+
{ type: "error", inputs: [], name: "TargetContractNotAllowedException" },
126+
{ type: "error", inputs: [], name: "TokenAlreadyAddedException" },
127+
{ type: "error", inputs: [], name: "TokenIsNotQuotedException" },
128+
{ type: "error", inputs: [], name: "TokenNotAllowedException" },
129+
{ type: "error", inputs: [], name: "TooManyEnabledTokensException" },
130+
{ type: "error", inputs: [], name: "TooManyTokensException" },
131+
{ type: "error", inputs: [], name: "TxExecutedOutsideTimeWindowException" },
132+
{ type: "error", inputs: [], name: "TxExecutionRevertedException" },
133+
{ type: "error", inputs: [], name: "TxNotQueuedException" },
134+
{ type: "error", inputs: [], name: "UnexpectedPermissionsException" },
135+
{ type: "error", inputs: [], name: "UnknownMethodException" },
136+
{ type: "error", inputs: [], name: "UpdateQuotaOnZeroDebtAccountException" },
137+
{ type: "error", inputs: [], name: "ValueOutOfRangeException" },
138+
{ type: "error", inputs: [], name: "VotingContractNotAllowedException" },
139+
{ type: "error", inputs: [], name: "ZeroAddressException" },
140+
] as const;

src/sdk/abi/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./compressors";
2+
export * from "./errors";
23
export * from "./generated";
34
export * from "./misc";
45
export * from "./oracles";

src/sdk/base/BaseContract.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from "viem";
1313
import { decodeFunctionData, getContract, isHex } from "viem";
1414

15-
import { iVersionAbi } from "../abi";
15+
import { iExceptionsAbi, iRouterV3ErrorsAbi, iVersionAbi } from "../abi";
1616
import { ADDRESS_0X0 } from "../constants";
1717
import type { GearboxSDK } from "../GearboxSDK";
1818
import type { BaseContractState } from "../state";
@@ -57,11 +57,12 @@ export abstract class BaseContract<
5757

5858
this.contract = getContract({
5959
address: this.address,
60-
abi: this.abi,
60+
// add exceptions for better error decoding
61+
abi: [this.abi, ...iExceptionsAbi, ...iRouterV3ErrorsAbi],
6162
client: {
6263
public: sdk.provider.publicClient,
6364
},
64-
});
65+
}) as any;
6566
this.version = Number(args.version || 0);
6667
this.contractType = args.contractType ?? "";
6768
if (isHex(this.contractType)) {

0 commit comments

Comments
 (0)