Skip to content

Commit

Permalink
Merge pull request #66 from lidofinance/develop
Browse files Browse the repository at this point in the history
Minor v2 release
  • Loading branch information
Jeday committed Nov 16, 2023
2 parents 71d8ec2 + 155c55a commit 89cd92b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 17 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
![Lido SDK Logo](./assets/package_logo.png)

# Lido Ethereum SDK
<div style="display: flex;" align="center">
<h1 align="center">Lido Ethereum SDK</h1>
</div>

<div style="display: flex;" align="center">
<img alt="GitHub license" src="https://img.shields.io/github/license/lidofinance/lido-ethereum-sdk?color=limegreen">
<img alt="Downloads npm" src="https://img.shields.io/npm/dm/@lidofinance/lido-ethereum-sdk?color=limegreen">
<img alt="Version npm" src="https://img.shields.io/npm/v/@lidofinance/lido-ethereum-sdk?label=version">
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/@lidofinance/lido-ethereum-sdk">
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/lidofinance/lido-ethereum-sdk">
<img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/lidofinance/lido-ethereum-sdk">
<img alt="GitHub open issues" src="https://img.shields.io/github/issues/lidofinance/lido-ethereum-sdk">
</div>
<br/>

**Lido Ethereum SDK** is a package that provides convenient tools for interacting with Lido contracts on the Ethereum network through a software development kit (SDK). This SDK simplifies working with Lido contracts and accessing their functionality.

Expand Down
15 changes: 14 additions & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Lido Ethereum SDK
<div style="display: flex;" align="center">
<h1 align="center">Lido Ethereum SDK</h1>
</div>

<div style="display: flex;" align="center">
<img alt="GitHub license" src="https://img.shields.io/github/license/lidofinance/lido-ethereum-sdk?color=limegreen">
<img alt="Downloads npm" src="https://img.shields.io/npm/dm/@lidofinance/lido-ethereum-sdk?color=limegreen">
<img alt="Version npm" src="https://img.shields.io/npm/v/@lidofinance/lido-ethereum-sdk?label=version">
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/@lidofinance/lido-ethereum-sdk">
<img alt="GitHub top language" src="https://img.shields.io/github/languages/top/lidofinance/lido-ethereum-sdk">
<img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/lidofinance/lido-ethereum-sdk">
<img alt="GitHub open issues" src="https://img.shields.io/github/issues/lidofinance/lido-ethereum-sdk">
</div>
<br/>

**Lido Ethereum SDK** is a package that provides convenient tools for interacting with Lido contracts on the Ethereum network through a software development kit (SDK). This SDK simplifies working with Lido contracts and accessing their functionality.

Expand Down
15 changes: 2 additions & 13 deletions packages/sdk/src/erc20/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
PublicClient,
WalletClient,
encodeFunctionData,
getContract,
} from 'viem';
import { NOOP, PERMIT_MESSAGE_TYPES } from '../common/constants.js';
import { parseValue } from '../common/utils/parse-value.js';
Expand All @@ -45,19 +44,9 @@ export abstract class AbstractLidoSDKErc20 {

public abstract contractAddress(): Promise<Address>;

@Logger('Contracts:')
@Cache(30 * 60 * 1000, ['core.chain.id', 'contractAddressWstETH'])
public async getContract(): Promise<
public abstract getContract(): Promise<
GetContractReturnType<typeof erc20abi, PublicClient, WalletClient>
> {
const address = await this.contractAddress();
return getContract({
address,
abi: erc20abi,
publicClient: this.core.rpcProvider,
walletClient: this.core.web3Provider,
});
}
>;

// Balance

Expand Down
23 changes: 22 additions & 1 deletion packages/sdk/src/erc20/steth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Address } from 'viem';
import {
Address,
GetContractReturnType,
PublicClient,
WalletClient,
getContract as getContractViem,
} from 'viem';
import { AbstractLidoSDKErc20 } from './erc20.js';
import { Logger, Cache } from '../common/decorators/index.js';
import { LIDO_CONTRACT_NAMES } from '../common/constants.js';
import invariant from 'tiny-invariant';
import { erc20abi } from './abi/erc20abi.js';

export class LidoSDKstETH extends AbstractLidoSDKErc20 {
@Logger('Contracts:')
Expand All @@ -11,4 +18,18 @@ export class LidoSDKstETH extends AbstractLidoSDKErc20 {
invariant(this.core.chain, 'Chain is not defined');
return this.core.getContractAddress(LIDO_CONTRACT_NAMES.lido);
}

@Logger('Contracts:')
@Cache(30 * 60 * 1000, ['core.chain.id', 'contractAddressStETH'])
public override async getContract(): Promise<
GetContractReturnType<typeof erc20abi, PublicClient, WalletClient>
> {
const address = await this.contractAddress();
return getContractViem({
address,
abi: erc20abi,
publicClient: this.core.rpcProvider,
walletClient: this.core.web3Provider,
});
}
}
23 changes: 22 additions & 1 deletion packages/sdk/src/erc20/wsteth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Address } from 'viem';
import {
Address,
GetContractReturnType,
PublicClient,
WalletClient,
getContract as getContractViem,
} from 'viem';
import { AbstractLidoSDKErc20 } from './erc20.js';
import { Logger, Cache } from '../common/decorators/index.js';
import { LIDO_CONTRACT_NAMES } from '../common/constants.js';
import invariant from 'tiny-invariant';
import { erc20abi } from './abi/erc20abi.js';

export class LidoSDKwstETH extends AbstractLidoSDKErc20 {
@Logger('Contracts:')
Expand All @@ -25,4 +32,18 @@ export class LidoSDKwstETH extends AbstractLidoSDKErc20 {
verifyingContract: await this.contractAddress(),
};
}

@Logger('Contracts:')
@Cache(30 * 60 * 1000, ['core.chain.id', 'contractAddressWstETH'])
public override async getContract(): Promise<
GetContractReturnType<typeof erc20abi, PublicClient, WalletClient>
> {
const address = await this.contractAddress();
return getContractViem({
address,
abi: erc20abi,
publicClient: this.core.rpcProvider,
walletClient: this.core.web3Provider,
});
}
}

0 comments on commit 89cd92b

Please sign in to comment.