UNPKG

@lifi/sdk

Version:

LI.FI Any-to-Any Cross-Chain-Swap SDK

32 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkPermitSupport = void 0; const types_1 = require("@lifi/types"); const config_js_1 = require("../../config.js"); const getActionWithFallback_js_1 = require("./getActionWithFallback.js"); const getAllowance_js_1 = require("./getAllowance.js"); const getNativePermit_js_1 = require("./permits/getNativePermit.js"); const publicClient_js_1 = require("./publicClient.js"); const checkPermitSupport = async ({ chain, tokenAddress, ownerAddress, amount, }) => { const provider = config_js_1.config.getProvider(types_1.ChainType.EVM); let client = await provider?.getWalletClient?.(); if (!client) { client = await (0, publicClient_js_1.getPublicClient)(chain.id); } const nativePermit = await (0, getActionWithFallback_js_1.getActionWithFallback)(client, getNativePermit_js_1.getNativePermit, 'getNativePermit', { chainId: chain.id, tokenAddress, spenderAddress: chain.permit2Proxy, amount, }); let permit2Allowance; if (chain.permit2) { permit2Allowance = await (0, getAllowance_js_1.getAllowance)(client, tokenAddress, ownerAddress, chain.permit2); } return { nativePermitSupported: !!nativePermit, permit2AllowanceSufficient: !!permit2Allowance && permit2Allowance >= amount, }; }; exports.checkPermitSupport = checkPermitSupport; //# sourceMappingURL=checkPermitSupport.js.map