Skip to content

Commit

Permalink
Merge pull request #36 from lidofinance/feature/si-827-apr
Browse files Browse the repository at this point in the history
Feature/si 827 apr
  • Loading branch information
Jeday authored Oct 6, 2023
2 parents 4c260f0 + af9ffa1 commit 1000b51
Show file tree
Hide file tree
Showing 19 changed files with 612 additions and 7 deletions.
46 changes: 46 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ The project is currently under development and may change in the future.
- [(w)stETH](#wsteth)
- [unstETH NFT](#unsteth-nft)
- [Lido contract addresses](#lido-contract-addresses)
- [Lido statistics](#lido-statistics)
- [APR](#apr)
- [Lido events](#lido-events)
- [Rebase](#rebase)

## Installation

Expand Down Expand Up @@ -1076,3 +1080,45 @@ const wsteth = await lidoSDK.core.getContractAddress(
LIDO_CONTRACT_NAMES.wsteth,
);
```

## Lido statistics

### APR

```ts
import { LidoSDK } from '@lidofinance/lido-ethereum-sdk';

const lidoSDK = new LidoSDK({
rpcUrls: ['https://rpc-url'],
chainId: 5,
});

const lastApr = await lidoSDK.statistics.apr.getLastApr();
const smaApr = await lidoSDK.statistics.apr.getSmaApr();

console.log(lastApr, 'last apr');
console.log(smaApr, 'sma apr');
```

## Lido events

### Rebase

```ts
import { LidoSDK } from '@lidofinance/lido-ethereum-sdk';

const lidoSDK = new LidoSDK({
rpcUrls: ['https://rpc-url'],
chainId: 5,
});

const lastRebaseEvent = await lidoSDK.events.stethEvents.getLastRebaseEvent();
const lastRebaseEventsByCount =
await lidoSDK.events.stethEvents.getRebaseEvents({ count: 10 });
const lastRebaseEventsByDays =
await lidoSDK.events.stethEvents.getRebaseEventByDays({ days: 10 });

console.log(lastRebaseEvent, 'last rebase event');
console.log(lastRebaseEventsByCount, 'last rebase events by count');
console.log(lastRebaseEventsByDays, 'last rebase events by days');
```
10 changes: 10 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
"default": "./dist/cjs/unsteth/index.js",
"types": "./dist/types/unsteth/index.d.ts"
},
"./statistics": {
"import": "./dist/esm/statistics/index.js",
"default": "./dist/cjs/statistics/index.js",
"types": "./dist/types/statistics/index.d.ts"
},
"./events": {
"import": "./dist/esm/events/index.js",
"default": "./dist/cjs/events/index.js",
"types": "./dist/types/events/index.d.ts"
},
"./package.json": "./package.json"
},
"typesVersions": {
Expand Down
5 changes: 0 additions & 5 deletions packages/sdk/src/common/decorators/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export const ErrorHandler = function (headMessage: HeadMessage = 'Error:') {
throw txError;
}) as Return;
} else {
callConsoleMessage.call(
this,
headMessage,
`Exiting method '${methodName}'.`,
);
return result;
}
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/common/decorators/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const ConsoleCss: Record<HeadMessage, string> = {
'LOG:': 'color: lightblue',
'Cache:': 'color: mediumvioletred',
'Permit:': 'color: lime',
'Events:': 'color: salmon',
'Statistic:': 'color: purple',
'Init:':
'color: #33F3FF;text-shadow: 0px 0px 0 #899CD5, 1px 1px 0 #8194CD, 2px 2px 0 #788BC4, 3px 3px 0 #6F82BB, 4px 4px 0 #677AB3, 5px 5px 0 #5E71AA, 6px 6px 0 #5568A1, 7px 7px 0 #4C5F98, 8px 8px 0 #445790, 9px 9px 0 #3B4E87, 10px 10px 0 #32457E, 11px 11px 0 #2A3D76, 12px 12px 0 #21346D, 13px 13px 0 #182B64, 14px 14px 0 #0F225B, 15px 15px 0 #071A53, 16px 16px 0 #02114A, 17px 17px 0 #0B0841, 18px 18px 0 #130039, 19px 19px 0 #1C0930, 20px 20px 0 #251227, 21px 21px 20px rgba(0,0,0,1), 21px 21px 1px rgba(0,0,0,0.5), 0px 0px 20px rgba(0,0,0,.2);font-size: 50px;',
};
4 changes: 3 additions & 1 deletion packages/sdk/src/common/decorators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export type HeadMessage =
| 'LOG:'
| 'Cache:'
| 'Init:'
| 'Permit:';
| 'Permit:'
| 'Events:'
| 'Statistic:';
191 changes: 191 additions & 0 deletions packages/sdk/src/events/abi/stethEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
export const StethEventsAbi = [
{ payable: true, stateMutability: 'payable', type: 'fallback' },
{
anonymous: false,
inputs: [],
name: 'StakingPaused',
type: 'event',
},
{
anonymous: false,
inputs: [],
name: 'StakingResumed',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: false, name: 'maxStakeLimit', type: 'uint256' },
{
indexed: false,
name: 'stakeLimitIncreasePerBlock',
type: 'uint256',
},
],
name: 'StakingLimitSet',
type: 'event',
},
{
anonymous: false,
inputs: [],
name: 'StakingLimitRemoved',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'reportTimestamp', type: 'uint256' },
{ indexed: false, name: 'preCLValidators', type: 'uint256' },
{ indexed: false, name: 'postCLValidators', type: 'uint256' },
],
name: 'CLValidatorsUpdated',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'depositedValidators', type: 'uint256' }],
name: 'DepositedValidatorsChanged',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'reportTimestamp', type: 'uint256' },
{ indexed: false, name: 'preCLBalance', type: 'uint256' },
{ indexed: false, name: 'postCLBalance', type: 'uint256' },
{ indexed: false, name: 'withdrawalsWithdrawn', type: 'uint256' },
{
indexed: false,
name: 'executionLayerRewardsWithdrawn',
type: 'uint256',
},
{ indexed: false, name: 'postBufferedEther', type: 'uint256' },
],
name: 'ETHDistributed',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'reportTimestamp', type: 'uint256' },
{ indexed: false, name: 'timeElapsed', type: 'uint256' },
{ indexed: false, name: 'preTotalShares', type: 'uint256' },
{ indexed: false, name: 'preTotalEther', type: 'uint256' },
{ indexed: false, name: 'postTotalShares', type: 'uint256' },
{ indexed: false, name: 'postTotalEther', type: 'uint256' },
{ indexed: false, name: 'sharesMintedAsFees', type: 'uint256' },
],
name: 'TokenRebased',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'lidoLocator', type: 'address' }],
name: 'LidoLocatorSet',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'amount', type: 'uint256' }],
name: 'ELRewardsReceived',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'amount', type: 'uint256' }],
name: 'WithdrawalsReceived',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'sender', type: 'address' },
{ indexed: false, name: 'amount', type: 'uint256' },
{ indexed: false, name: 'referral', type: 'address' },
],
name: 'Submitted',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'amount', type: 'uint256' }],
name: 'Unbuffered',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'executor', type: 'address' },
{ indexed: false, name: 'script', type: 'bytes' },
{ indexed: false, name: 'input', type: 'bytes' },
{ indexed: false, name: 'returnData', type: 'bytes' },
],
name: 'ScriptResult',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'vault', type: 'address' },
{ indexed: true, name: 'token', type: 'address' },
{ indexed: false, name: 'amount', type: 'uint256' },
],
name: 'RecoverToVault',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'eip712StETH', type: 'address' }],
name: 'EIP712StETHInitialized',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'sharesValue', type: 'uint256' },
],
name: 'TransferShares',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'account', type: 'address' },
{ indexed: false, name: 'preRebaseTokenAmount', type: 'uint256' },
{ indexed: false, name: 'postRebaseTokenAmount', type: 'uint256' },
{ indexed: false, name: 'sharesAmount', type: 'uint256' },
],
name: 'SharesBurnt',
type: 'event',
},
{ anonymous: false, inputs: [], name: 'Stopped', type: 'event' },
{ anonymous: false, inputs: [], name: 'Resumed', type: 'event' },
{
anonymous: false,
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Transfer',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'owner', type: 'address' },
{ indexed: true, name: 'spender', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Approval',
type: 'event',
},
{
anonymous: false,
inputs: [{ indexed: false, name: 'version', type: 'uint256' }],
name: 'ContractVersionSet',
type: 'event',
},
] as const;
19 changes: 19 additions & 0 deletions packages/sdk/src/events/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { LidoSDKCore } from '../core/index.js';
import { version } from '../version.js';

import { LidoSDKStethEvents } from './stethEvents.js';
import type { LidoSDKEventsProps } from './types.js';

export class LidoSDKEvents {
readonly core: LidoSDKCore;
readonly stethEvents: LidoSDKStethEvents;

constructor(props: LidoSDKEventsProps) {
const { core, ...rest } = props;

if (core) this.core = core;
else this.core = new LidoSDKCore(rest, version);

this.stethEvents = new LidoSDKStethEvents({ ...rest, core: this.core });
}
}
1 change: 1 addition & 0 deletions packages/sdk/src/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LidoSDKEvents } from './events.js';
Loading

0 comments on commit 1000b51

Please sign in to comment.