UNPKG

@paxoslabs/earn-sdk

Version:
93 lines (89 loc) 2.3 kB
export { fetchWithdrawAssets, getAssetSlippage } from './chunk-3K72Y6ME.mjs'; export { getPausedStates } from './chunk-XT2SWHA6.mjs'; import { getClient } from './chunk-SBKCBPE3.mjs'; export { getErc20Allowance, getErc20Balance, getErc20Decimals, getPreviewFee, getRateInQuoteWithAssetDecimals } from './chunk-SBKCBPE3.mjs'; export { fetchVaultConfig, toChainId } from './chunk-4URQP4CS.mjs'; import { CHAINLINK_ADDRESS } from './chunk-NTRZGVUA.mjs'; import { erc20Abi } from 'viem'; async function getVaultAllowance({ tokenAddress, spenderAddress, userAddress, chainId }) { const client = await getClient(chainId); const allowance = await client.readContract({ abi: erc20Abi, address: tokenAddress, functionName: "allowance", args: [userAddress, spenderAddress] }); return allowance; } async function getTotalSupply({ tokenAddress, chainId }) { const client = await getClient(chainId); const totalSupply = await client.readContract({ abi: erc20Abi, address: tokenAddress, functionName: "totalSupply" }); return totalSupply; } // src/contracts/chainlink-abi.ts var ChainlinkAbi = [ { type: "function", name: "latestRoundData", inputs: [], outputs: [ { name: "roundId", type: "uint80", internalType: "uint80" }, { name: "answer", type: "int256", internalType: "int256" }, { name: "startedAt", type: "uint256", internalType: "uint256" }, { name: "updatedAt", type: "uint256", internalType: "uint256" }, { name: "answeredInRound", type: "uint80", internalType: "uint80" } ], stateMutability: "view" } ]; // src/api/chainlink.ts async function getEthPrice({ chainId }) { const client = await getClient(chainId); const priceData = await client.readContract({ abi: ChainlinkAbi, address: CHAINLINK_ADDRESS, functionName: "latestRoundData", args: [] }); if (!priceData || !priceData[1]) { throw new Error("Failed to fetch ETH price from Chainlink"); } return priceData[1]; } export { getEthPrice, getTotalSupply, getVaultAllowance }; //# sourceMappingURL=core.mjs.map //# sourceMappingURL=core.mjs.map