@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
107 lines (68 loc) • 4.52 kB
Markdown
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 Lido Protocol.
Contracts for Lido Finance projects.
Part of [Lido JS SDK](https://github.com/lidofinance/lido-js-sdk/#readme)
A Contract is an abstraction of code that has been deployed to the blockchain. A Contract may be sent transactions, which will trigger its code to be run with the input of the transaction data. More details in the [ethers docs](https://docs.ethers.io/v5/api/contract/contract/).
It uses [TypeChain](https://github.com/ethereum-ts/TypeChain) under the hood to generate TypeScript typings for contacts.
- [Install](
- [Getters](
- [getERC20Contract](
- [getWSTETHContract](
- [getSTETHContract](
- [getLDOContract](
- [getWithdrawalQueueContract](
- [getAggregatorContract](
- [Cache](
```bash
yarn add @lido-sdk/contracts
```
[](src/contracts.ts)
Each getter returns a cached [Contract](https://docs.ethers.io/v5/api/contract/contract/#Contract--creating) instance with an attached [Provider](https://docs.ethers.io/v5/api/providers/) and an [ABI](https://docs.ethers.io/v5/api/utils/abi/). The Provider is required to work with the network and sign transactions and the ABI contains information about methods of the contract on the ethereum side. So, the resulting instance contains all the methods supported by the contract and allows you to call them.
_If a contract method requires signing a transaction, then you need a provider with [Signer](https://docs.ethers.io/v5/api/signer/)_
Returns an instance of `Contract` based on [ERC20](https://eips.ethereum.org/EIPS/eip-20) standard contract ABI.
```ts
import { getERC20Contract } from '@lido-sdk/contracts';
import { JsonRpcProvider } from '@ethersproject/providers';
const provider = new JsonRpcProvider('http://localhost:8545');
const contract = getERC20Contract(
'0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
provider,
);
const symbol = await contract.symbol();
const decimals = await contract.decimals();
```
Returns an instance of `Contract` based on wstETH contract [ABI](https://docs.ethers.io/v5/api/utils/abi/). Available contract methods and detailed documentation can be found here: https://docs.lido.fi/contracts/wsteth
Returns an instance of `Contract` based on stETH contract [ABI](https://docs.ethers.io/v5/api/utils/abi/). Available contract methods and detailed documentation can be found here: https://docs.lido.fi/contracts/lido
Returns an instance of `Contract` based on LDO token [ABI](https://docs.ethers.io/v5/api/utils/abi/). LDO Token docs can be found here: https://docs.lido.fi/lido-dao/#ldo-token
Returns an instance of `Contract` based on WithdrawalQueue contract [ABI](https://docs.ethers.io/v5/api/utils/abi/). Contract docs here: https://docs.lido.fi/contracts/withdrawal-queue-erc721
Returns an instance of `Contract` based on ChainLink USD/ETH price oracle [ABI](https://docs.ethers.io/v5/api/utils/abi/). EACAggregatorProxy https://etherscan.io/address/0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
To get another contract instance, getters have a third optional parameter `cacheSeed`.
Calls without `cacheSeed` or with the same `cacheSeed` return the same contracts:
```ts
const contractFirst = getERC20Contract('0x0...', provider, 1);
const contractSecond = getERC20Contract('0x0...', provider, 1);
contractFirst === contractSecond; // true
```
Calls with different `cacheSeed` return different contracts:
```ts
const contractFirst = getERC20Contract('0x0...', provider, 1);
const contractSecond = getERC20Contract('0x0...', provider, 2);
contractFirst !== contractSecond; // true
```
Of course, if the `cacheSeed` is the same, but `address` or `provider` are different the result contracts will also be different:
```ts
const contractFirst = getERC20Contract('0x1...', provider, 1);
const contractSecond = getERC20Contract('0x0...', provider, 1);
contractFirst !== contractSecond; // true, because the addresses are different
```