Skip to content

Instantly share code, notes, and snippets.

@olegpetroveth
Created May 28, 2024 02:59
Show Gist options
  • Save olegpetroveth/7549212f49019c5df258e63ef3ef53f9 to your computer and use it in GitHub Desktop.
Save olegpetroveth/7549212f49019c5df258e63ef3ef53f9 to your computer and use it in GitHub Desktop.
SwapKit API V1 WarningCodes
export interface IWarning {
warningCode: WarningCode;
warningMessage: string;
}
export enum WarningCode {
// transactional warnings
SwapAmountTooSmall = '1001',
LargeSwapAmount = '1002',
TinySwapNoLimit = '1003',
// Transaction object warnings
NoSourceAddress = '2001',
NoDestinationAddress = '2002',
InsufficientBalance = '2003',
TransactionUnknown = '2050',
// input parameters warnings
InvalidReferral = '4100',
// Slippage warning
SlippageTooHigh = '5001',
StreamingSlippageTooHigh = '5002',
DefaultSlippageUsed = '5003',
}
// four digit error codes
// 1xxx - where 1 is to recognize service `aggregator` and three digits are id of error
export const WARNINGS: Record<WarningCode, string> = {
[WarningCode.SwapAmountTooSmall]: 'Swap amount is small and is more likely to get reverted.',
[WarningCode.LargeSwapAmount]: 'Swap amount is large. Slippage might be too low to fill swap.',
[WarningCode.TinySwapNoLimit]: 'Swap size is small. No limit is set for this swap to avoid partial refunds.',
[WarningCode.NoSourceAddress]: 'Source address is not provided. Cannot provide a transaction object in response.',
[WarningCode.NoDestinationAddress]:
'Destination address is not provided. Cannot provide a transaction object in response.',
[WarningCode.InsufficientBalance]: 'Insufficient balance to complete the transaction.',
[WarningCode.TransactionUnknown]: 'Something went wrong creating the transaction object.',
[WarningCode.InvalidReferral]: 'Referral thornames should be registered TNS of 10 characters or less.',
[WarningCode.SlippageTooHigh]: 'Slippage for this transaction is higher than user provided',
[WarningCode.StreamingSlippageTooHigh]: 'Streaming swap slippage for this transaction is higher than user provided',
[WarningCode.DefaultSlippageUsed]: 'Default slippage is used for this quote',
};
export const getWarning = (warningCode: WarningCode): IWarning => {
return {
warningCode,
warningMessage: WARNINGS[warningCode],
};
};
export const getWarningMessage = (warningCode: WarningCode): string => {
return WARNINGS[warningCode];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment