lending-apy-fetcher-ts
Version:
TypeScript library for fetching APYs from DeFi lending protocols
126 lines • 5.52 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppConfig = exports.ApiConfig = exports.AaveEthConfig = exports.KaminoConfig = exports.AddressConfig = void 0;
// Address configuration for token mappings across networks
class AddressConfig {
constructor(customMappings) {
this.mappings = {
...this.getDefaultMappings(),
...customMappings,
};
}
getDefaultMappings() {
return {
// Solana: {
// 'So11111111111111111111111111111111111111112': 'SOL',
// 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': 'USDC',
// 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': 'USDT',
// 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263': 'BONK',
// 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So': 'mSOL',
// 'bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1': 'bSOL',
// },
Ethereum: {
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': 'WETH',
'0xA0b86a33E6417c0F01C5b8b2a3C9C7C7e5C2Bc9F0': 'USDC',
'0x6B175474E89094C44Da98b954EedeAC495271d0F': 'DAI',
'0xdAC17F958D2ee523a2206206994597C13D831ec7': 'USDT',
'0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599': 'WBTC',
'0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0': 'wstETH',
'0xd31a59c85ae9d8edefec411d448f90841571b89c': 'WSOL',
},
Polygon: {
'0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270': 'WMATIC',
'0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174': 'USDC',
'0xc2132D05D31c914a87C6611C10748AEb04B58e8F': 'USDT',
'0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063': 'DAI',
},
Arbitrum: {
'0x82aF49447D8a07e3bd95BD0d56f35241523fBab1': 'USDC',
'0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': 'USDT'
},
Optimism: {
'0x7F5c764cBc14f9669B88837ca1490cCa17c31607': 'USDC',
'0x94b008aA00579c1307B0EF2c499aD98a8ce58e58': 'USDT',
'0xba1Cf949c382A32a09A17B2AdF3587fc7fA664f1': 'WSOL',
}
};
}
getSymbol(address, network) {
return this.mappings[network]?.[address];
}
addMapping(address, symbol, network) {
if (!this.mappings[network]) {
this.mappings[network] = {};
}
this.mappings[network][address] = symbol;
}
getAllMappings() {
return { ...this.mappings };
}
}
exports.AddressConfig = AddressConfig;
// Kamino protocol configuration
class KaminoConfig {
constructor(baseUrl = 'https://api.kamino.finance', lendingPath = '/kamino-market/7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF/reserves/metrics', stakingPath = '/v2/staking-yields', timeout = 10000, retryAttempts = 3, retryDelay = 1000) {
this.baseUrl = baseUrl;
this.lendingPath = lendingPath;
this.stakingPath = stakingPath;
this.timeout = timeout;
this.retryAttempts = retryAttempts;
this.retryDelay = retryDelay;
}
getLendingUrl() {
return `${this.baseUrl}${this.lendingPath}`;
}
getStakingUrl() {
return `${this.baseUrl}${this.stakingPath}`;
}
}
exports.KaminoConfig = KaminoConfig;
// Aave Ethereum configuration
class AaveEthConfig {
constructor(subgraphId = 'JCNWRypm7FYwV8fx5HhzZPSFaMxgkPuw4TnR3Gpi81zk', poolId = '0x87870bace213686c72ec8ce2bb4caf8c4f18a2c3f3b2b5e3', graphGatewayUrl = 'https://gateway.thegraph.com/api', timeout = 15000, retryAttempts = 3, retryDelay = 1000) {
this.subgraphId = subgraphId;
this.poolId = poolId;
this.graphGatewayUrl = graphGatewayUrl;
this.timeout = timeout;
this.retryAttempts = retryAttempts;
this.retryDelay = retryDelay;
}
getSubgraphUrl(apiKey) {
return `${this.graphGatewayUrl}/${apiKey}/subgraphs/id/${this.subgraphId}`;
}
}
exports.AaveEthConfig = AaveEthConfig;
// HTTP client configuration
class ApiConfig {
constructor(defaultTimeout = 10000, userAgent = 'lending-apy-fetcher-ts/1.0.0', retryAttempts = 3, retryDelay = 1000, enableLogging = false) {
this.defaultTimeout = defaultTimeout;
this.userAgent = userAgent;
this.retryAttempts = retryAttempts;
this.retryDelay = retryDelay;
this.enableLogging = enableLogging;
}
}
exports.ApiConfig = ApiConfig;
// Main application configuration
class AppConfig {
constructor(addressConfig = new AddressConfig(), kaminoConfig = new KaminoConfig(), aaveEthConfig = new AaveEthConfig(), apiConfig = new ApiConfig()) {
this.addressConfig = addressConfig;
this.kaminoConfig = kaminoConfig;
this.aaveEthConfig = aaveEthConfig;
this.apiConfig = apiConfig;
}
static fromEnvironment() {
// Load .env file if it exists
try {
require('dotenv').config();
}
catch (error) {
// dotenv is optional, continue if not available
}
return new AppConfig(new AddressConfig(), new KaminoConfig(), new AaveEthConfig(), new ApiConfig(parseInt(process.env.API_TIMEOUT || '10000'), process.env.USER_AGENT || 'lending-apy-fetcher-ts/1.0.0', parseInt(process.env.RETRY_ATTEMPTS || '3'), parseInt(process.env.RETRY_DELAY || '1000'), process.env.ENABLE_LOGGING === 'true'));
}
}
exports.AppConfig = AppConfig;
//# sourceMappingURL=index.js.map