@lido-sdk/contracts
Version:
This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li
33 lines (30 loc) • 1.84 kB
JavaScript
import { AggregatorAbi__factory } from './generated/factories/AggregatorAbi__factory.js';
import { Erc20Abi__factory } from './generated/factories/Erc20Abi__factory.js';
import { StethAbi__factory } from './generated/factories/StethAbi__factory.js';
import { WstethAbi__factory } from './generated/factories/WstethAbi__factory.js';
import { LdoAbi__factory } from './generated/factories/LdoAbi__factory.js';
import { WithdrawalQueueAbi__factory } from './generated/factories/WithdrawalQueueAbi__factory.js';
const createContractGetter = (factory) => {
const providerCache = new WeakMap();
return (address, signerOrProvider, cacheSeed = 0) => {
const cacheByAddressKey = `${address}-${cacheSeed}`;
let cacheByAddress = providerCache.get(signerOrProvider);
let contract = cacheByAddress === null || cacheByAddress === void 0 ? void 0 : cacheByAddress[cacheByAddressKey];
if (!cacheByAddress) {
cacheByAddress = {};
providerCache.set(signerOrProvider, cacheByAddress);
}
if (!contract) {
contract = factory.connect(address, signerOrProvider);
cacheByAddress[cacheByAddressKey] = contract;
}
return contract;
};
};
const getAggregatorContract = createContractGetter(AggregatorAbi__factory);
const getERC20Contract = createContractGetter(Erc20Abi__factory);
const getSTETHContract = createContractGetter(StethAbi__factory);
const getWSTETHContract = createContractGetter(WstethAbi__factory);
const getLDOContract = createContractGetter(LdoAbi__factory);
const getWithdrawalQueueContract = createContractGetter(WithdrawalQueueAbi__factory);
export { createContractGetter, getAggregatorContract, getERC20Contract, getLDOContract, getSTETHContract, getWSTETHContract, getWithdrawalQueueContract };