import { n as __exportAll } from "./chunk-BEJ448es.mjs";
//#region extensions/crypto/src/lib/contract-registry.ts
const AAVE = {
	pool: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
	poolDataProvider: "0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac",
	oracle: "0x2Cc0Fc26eD4563A5ce5e8bdcFe1A2878676Ae156",
	aTokens: {
		WETH: {
			aToken: "0xD4a0e0b9149BCee3C920d2E00b5dE09138fd8bb7",
			debtToken: "0x24e6e0795b3c7c71D965fCc4f371803d1c1DcA1E"
		},
		USDC: {
			aToken: "0x4e65fE4DbA92790696d040ac24Aa414708F5c0AB",
			debtToken: "0x59dca05b6c26dbd64b5381374aAaC5CD05644C28"
		},
		cbETH: {
			aToken: "0xcf3D55c10DB69f28fD1A75Bd73f3D8A2d9c595ad",
			debtToken: "0x1DabC36c04f3C3Fc41Da4385e7Aa38f7684C4A13"
		},
		USDbC: {
			aToken: "0x0a1d576f3eFeF75b330424287a95A366e8281D54",
			debtToken: "0x7376b2F323dC56fCd4C191B34163ac8a84702DAB"
		}
	},
	governance: {
		governor: "0xEC568fffba86c094cf06b22134B23074DFE2252c",
		token: "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"
	}
};
const LIDO = {
	ethereum: {
		stETH: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
		wstETH: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
	},
	base: { wstETH: "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452" }
};
const ROCKET_POOL = {
	ethereum: {
		rETH: "0xae78736Cd615f374D3085123A210448E74Fc6393",
		depositPool: "0xDD3f50F8A6CafbE9b31a427582963f465E745AF8"
	},
	base: { rETH: "0xB6fe221Fe9EeF5aBa221c348bA20A1Bf5e73624c" }
};
const CBETH = {
	ethereum: "0xBe9895146f7AF43049ca1c1AE358B0541Ea49BBf",
	base: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22"
};
const MORPHO = {
	core: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
	token: "0x58D97B57BB95320F9a05dC918Aef65434969c2B2",
	claimContract: "0x678dDC1d07eaa166E502E4eb00E6752Ec7BFc530"
};
const YEARN = { base: {
	yvUSDC: "0x528D0A9F0F3e2BDD98De14163C5E3CB289F37daF",
	yvWETH: "0xa0225CBE2feAD5efA5E5d5C7f5291e7e2a6C02E4",
	yvDAI: "0x305F25377d0a39091e99B975558b1bdfC3975654"
} };
const UNISWAP = {
	universalRouter: "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
	v2Router: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
	v3Router: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
	base: {
		universalRouter: "0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC",
		v4PositionManager: "0x7C5f5A4bBd8fD63184577525326123B519429bDc"
	},
	governance: {
		governor: "0x408ED6354d4973f66138C91495F2f2FCbd8724C3",
		token: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
	}
};
const AERODROME = {
	governor: "0x77758EBdD55270809E96DCfe3CDEBe26d4A0eFb1",
	token: "0x940181a94A35A4569E4529A3CDfB74e38FD98631"
};
const ENS = {
	governor: "0x323A76393544d5ecca80cd6ef2A560C6a395b7E3",
	token: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72"
};
const TOKENS = {
	base: {
		USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
		WETH: "0x4200000000000000000000000000000000000006",
		USDT: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2",
		DAI: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
		USDbC: "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
		CLAWNCH: "0xa1F72459dfA10BAD200Ac160eCd78C6b77a747be"
	},
	ethereum: {
		USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
		WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
		USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
		DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
		WBTC: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
		LINK: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
		UNI: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
		AAVE: "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"
	},
	arbitrum: {
		USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
		WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
		USDT: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
		ARB: "0x912CE59144191C1204E64559FE8253a0e49E6548",
		DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"
	},
	optimism: {
		USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
		WETH: "0x4200000000000000000000000000000000000006",
		USDT: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
		OP: "0x4200000000000000000000000000000000000042",
		DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"
	},
	polygon: {
		USDC: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
		WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
		USDT: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
		WMATIC: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
		DAI: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
		USDCe: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174"
	}
};
MORPHO.token, MORPHO.claimContract;
//#endregion
//#region extensions/crypto/src/services/lending-service.ts
var lending_service_exports = /* @__PURE__ */ __exportAll({
	AAVE_POOL_ABI: () => AAVE_POOL_ABI,
	ERC20_APPROVE_ABI: () => ERC20_APPROVE_ABI,
	LENDING_ASSETS: () => LENDING_ASSETS,
	LENDING_CONTRACTS: () => LENDING_CONTRACTS,
	LendingService: () => LendingService,
	getLendingService: () => getLendingService
});
const LENDING_CONTRACTS = {
	aave: {
		pool: AAVE.pool,
		poolDataProvider: AAVE.poolDataProvider,
		oracle: AAVE.oracle,
		chain: 8453,
		name: "Aave V3 Base"
	},
	morpho: {
		core: MORPHO.core,
		chain: 8453,
		name: "Morpho Base"
	}
};
const LENDING_ASSETS = {
	ETH: {
		symbol: "ETH",
		address: TOKENS.base.WETH,
		decimals: 18,
		aToken: AAVE.aTokens.WETH.aToken,
		variableDebtToken: AAVE.aTokens.WETH.debtToken
	},
	USDC: {
		symbol: "USDC",
		address: TOKENS.base.USDC,
		decimals: 6,
		aToken: AAVE.aTokens.USDC.aToken,
		variableDebtToken: AAVE.aTokens.USDC.debtToken
	},
	cbETH: {
		symbol: "cbETH",
		address: CBETH.base,
		decimals: 18,
		aToken: AAVE.aTokens.cbETH.aToken,
		variableDebtToken: AAVE.aTokens.cbETH.debtToken
	},
	USDbC: {
		symbol: "USDbC",
		address: TOKENS.base.USDbC,
		decimals: 6,
		aToken: AAVE.aTokens.USDbC.aToken,
		variableDebtToken: AAVE.aTokens.USDbC.debtToken
	}
};
const AAVE_POOL_ABI = [
	{
		name: "supply",
		type: "function",
		stateMutability: "nonpayable",
		inputs: [
			{
				name: "asset",
				type: "address"
			},
			{
				name: "amount",
				type: "uint256"
			},
			{
				name: "onBehalfOf",
				type: "address"
			},
			{
				name: "referralCode",
				type: "uint16"
			}
		],
		outputs: []
	},
	{
		name: "borrow",
		type: "function",
		stateMutability: "nonpayable",
		inputs: [
			{
				name: "asset",
				type: "address"
			},
			{
				name: "amount",
				type: "uint256"
			},
			{
				name: "interestRateMode",
				type: "uint256"
			},
			{
				name: "referralCode",
				type: "uint16"
			},
			{
				name: "onBehalfOf",
				type: "address"
			}
		],
		outputs: []
	},
	{
		name: "repay",
		type: "function",
		stateMutability: "nonpayable",
		inputs: [
			{
				name: "asset",
				type: "address"
			},
			{
				name: "amount",
				type: "uint256"
			},
			{
				name: "interestRateMode",
				type: "uint256"
			},
			{
				name: "onBehalfOf",
				type: "address"
			}
		],
		outputs: [{
			name: "",
			type: "uint256"
		}]
	},
	{
		name: "withdraw",
		type: "function",
		stateMutability: "nonpayable",
		inputs: [
			{
				name: "asset",
				type: "address"
			},
			{
				name: "amount",
				type: "uint256"
			},
			{
				name: "to",
				type: "address"
			}
		],
		outputs: [{
			name: "",
			type: "uint256"
		}]
	},
	{
		name: "getUserAccountData",
		type: "function",
		stateMutability: "view",
		inputs: [{
			name: "user",
			type: "address"
		}],
		outputs: [
			{
				name: "totalCollateralBase",
				type: "uint256"
			},
			{
				name: "totalDebtBase",
				type: "uint256"
			},
			{
				name: "availableBorrowsBase",
				type: "uint256"
			},
			{
				name: "currentLiquidationThreshold",
				type: "uint256"
			},
			{
				name: "ltv",
				type: "uint256"
			},
			{
				name: "healthFactor",
				type: "uint256"
			}
		]
	}
];
const ERC20_APPROVE_ABI = [{
	name: "approve",
	type: "function",
	stateMutability: "nonpayable",
	inputs: [{
		name: "spender",
		type: "address"
	}, {
		name: "amount",
		type: "uint256"
	}],
	outputs: [{
		name: "",
		type: "bool"
	}]
}, {
	name: "allowance",
	type: "function",
	stateMutability: "view",
	inputs: [{
		name: "owner",
		type: "address"
	}, {
		name: "spender",
		type: "address"
	}],
	outputs: [{
		name: "",
		type: "uint256"
	}]
}];
var LendingService = class {
	/**
	* Resolve asset symbol to lending asset info.
	*/
	resolveAsset(symbolOrAddress) {
		const upper = symbolOrAddress.toUpperCase();
		if (LENDING_ASSETS[upper]) return LENDING_ASSETS[upper];
		const lower = symbolOrAddress.toLowerCase();
		for (const asset of Object.values(LENDING_ASSETS)) if (asset.address.toLowerCase() === lower) return asset;
		return null;
	}
	/**
	* Get user account data from Aave V3 (health factor, collateral, debt).
	*/
	async getUserAccountData(userAddress, publicClient) {
		const [totalCollateral, totalDebt, availableBorrows, liqThreshold, ltv, healthFactor] = await publicClient.readContract({
			address: LENDING_CONTRACTS.aave.pool,
			abi: AAVE_POOL_ABI,
			functionName: "getUserAccountData",
			args: [userAddress]
		});
		return {
			totalCollateralUsd: Number(totalCollateral) / 1e8,
			totalDebtUsd: Number(totalDebt) / 1e8,
			availableBorrowsUsd: Number(availableBorrows) / 1e8,
			liquidationThreshold: Number(liqThreshold) / 100,
			ltv: Number(ltv) / 100,
			healthFactor: healthFactor >= BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") ? Infinity : Number(healthFactor) / 0xde0b6b3a7640000
		};
	}
	/**
	* Supply an asset to Aave V3.
	* Returns the confirmed transaction hash.
	*/
	async supply(asset, amount, userAddress, walletClient, publicClient) {
		await this.ensureApproval(asset.address, LENDING_CONTRACTS.aave.pool, amount, userAddress, walletClient, publicClient);
		const hash = await walletClient.writeContract({
			address: LENDING_CONTRACTS.aave.pool,
			abi: AAVE_POOL_ABI,
			functionName: "supply",
			args: [
				asset.address,
				amount,
				userAddress,
				0
			]
		});
		await publicClient.waitForTransactionReceipt({ hash });
		return {
			hash,
			action: "supply",
			asset: asset.symbol,
			amount: amount.toString()
		};
	}
	/**
	* Borrow an asset from Aave V3 (variable rate).
	*/
	async borrow(asset, amount, userAddress, walletClient, publicClient) {
		const hash = await walletClient.writeContract({
			address: LENDING_CONTRACTS.aave.pool,
			abi: AAVE_POOL_ABI,
			functionName: "borrow",
			args: [
				asset.address,
				amount,
				BigInt(2),
				0,
				userAddress
			]
		});
		if (publicClient) await publicClient.waitForTransactionReceipt({ hash });
		return {
			hash,
			action: "borrow",
			asset: asset.symbol,
			amount: amount.toString()
		};
	}
	/**
	* Repay a borrowed asset on Aave V3.
	* Use amount = MaxUint256 to repay entire debt.
	*
	* When skipApproval is true, the caller has already handled approval
	* (e.g. for max repay with bounded approval instead of MaxUint256).
	*/
	async repay(asset, amount, userAddress, walletClient, publicClient, skipApproval = false) {
		if (!skipApproval) await this.ensureApproval(asset.address, LENDING_CONTRACTS.aave.pool, amount, userAddress, walletClient, publicClient);
		const hash = await walletClient.writeContract({
			address: LENDING_CONTRACTS.aave.pool,
			abi: AAVE_POOL_ABI,
			functionName: "repay",
			args: [
				asset.address,
				amount,
				BigInt(2),
				userAddress
			]
		});
		await publicClient.waitForTransactionReceipt({ hash });
		return {
			hash,
			action: "repay",
			asset: asset.symbol,
			amount: amount.toString()
		};
	}
	/**
	* Withdraw a supplied asset from Aave V3.
	* Use amount = MaxUint256 to withdraw entire balance.
	*/
	async withdraw(asset, amount, userAddress, walletClient, publicClient) {
		const hash = await walletClient.writeContract({
			address: LENDING_CONTRACTS.aave.pool,
			abi: AAVE_POOL_ABI,
			functionName: "withdraw",
			args: [
				asset.address,
				amount,
				userAddress
			]
		});
		if (publicClient) await publicClient.waitForTransactionReceipt({ hash });
		return {
			hash,
			action: "withdraw",
			asset: asset.symbol,
			amount: amount.toString()
		};
	}
	/**
	* Get list of supported lending assets.
	*/
	getSupportedAssets() {
		return Object.values(LENDING_ASSETS);
	}
	/**
	* Get supported protocols.
	* Note: Morpho contract address is defined in LENDING_CONTRACTS for future use,
	* but is not yet implemented. Only Aave V3 is currently supported.
	*/
	getSupportedProtocols() {
		return [{
			id: "aave",
			name: LENDING_CONTRACTS.aave.name,
			chain: LENDING_CONTRACTS.aave.chain
		}];
	}
	/**
	* Get the current variable debt balance for an asset.
	* Useful for calculating exact repay amounts instead of MaxUint256 approvals.
	*/
	async getDebtBalance(asset, userAddress, publicClient) {
		if (!asset.variableDebtToken) return 0n;
		const { erc20Abi } = await import("./_esm-BKtdEVdT.mjs").then((n) => n.t);
		return await publicClient.readContract({
			address: asset.variableDebtToken,
			abi: erc20Abi,
			functionName: "balanceOf",
			args: [userAddress]
		});
	}
	/**
	* Public wrapper for ensureApproval — used when the caller needs to
	* control the approval amount separately (e.g. max repay with bounded approval).
	*/
	async ensureApprovalPublic(tokenAddress, amount, owner, walletClient, publicClient) {
		await this.ensureApproval(tokenAddress, LENDING_CONTRACTS.aave.pool, amount, owner, walletClient, publicClient);
	}
	async ensureApproval(tokenAddress, spender, amount, owner, walletClient, publicClient) {
		if (await publicClient.readContract({
			address: tokenAddress,
			abi: ERC20_APPROVE_ABI,
			functionName: "allowance",
			args: [owner, spender]
		}) < amount) {
			const approveHash = await walletClient.writeContract({
				address: tokenAddress,
				abi: ERC20_APPROVE_ABI,
				functionName: "approve",
				args: [spender, amount]
			});
			await publicClient.waitForTransactionReceipt({ hash: approveHash });
		}
	}
};
let _instance = null;
function getLendingService() {
	if (!_instance) _instance = new LendingService();
	return _instance;
}
//#endregion
export { CBETH as a, ROCKET_POOL as c, YEARN as d, AERODROME as i, TOKENS as l, lending_service_exports as n, ENS as o, AAVE as r, LIDO as s, getLendingService as t, UNISWAP as u };

//# sourceMappingURL=lending-service-CxrgIJZg.mjs.map