@lifi/sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
53 lines • 2.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isToken = exports.isStep = exports.isRoutesRequest = void 0;
const isRoutesRequest = (routesRequest) => {
const { fromChainId, fromAmount, fromTokenAddress, toChainId, toTokenAddress, options, } = routesRequest;
return (typeof fromChainId === 'number' &&
typeof fromAmount === 'string' &&
fromAmount !== '' &&
typeof fromTokenAddress === 'string' &&
fromTokenAddress !== '' &&
typeof toChainId === 'number' &&
typeof toTokenAddress === 'string' &&
toTokenAddress !== '' &&
(!options || isRoutesOptions(options)));
};
exports.isRoutesRequest = isRoutesRequest;
const isRoutesOptions = (routeOptions) => !routeOptions?.slippage || typeof routeOptions.slippage === 'number';
const isStep = (step) => {
const { id, type, tool, action, estimate } = step;
return (typeof id === 'string' &&
['swap', 'cross', 'lifi'].includes(type) &&
typeof tool === 'string' &&
isAction(action) &&
isEstimate(estimate));
};
exports.isStep = isStep;
const isAction = (action) => {
const { fromChainId, fromAmount, fromToken, toChainId, toToken } = action;
return (typeof fromChainId === 'number' &&
typeof fromAmount === 'string' &&
fromAmount !== '' &&
(0, exports.isToken)(fromToken) &&
typeof toChainId === 'number' &&
(0, exports.isToken)(toToken));
};
const isEstimate = (estimate) => {
const { fromAmount, toAmount, toAmountMin, approvalAddress } = estimate;
return (typeof fromAmount === 'string' &&
fromAmount !== '' &&
typeof toAmount === 'string' &&
toAmount !== '' &&
typeof toAmountMin === 'string' &&
toAmountMin !== '' &&
(typeof approvalAddress === 'string' || approvalAddress === null));
};
const isToken = (token) => {
const { address, decimals, chainId } = token;
return (typeof address === 'string' &&
typeof decimals === 'number' &&
typeof chainId === 'number');
};
exports.isToken = isToken;
//# sourceMappingURL=typeguards.js.map
;