Skip to content

Commit

Permalink
feat: stableBlockNumber (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsains authored Oct 19, 2023
1 parent 589079f commit 60526ae
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 87 deletions.
86 changes: 43 additions & 43 deletions docs/modules/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

[adapter.ts:11](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L11)

___
---

### PositionType

Expand All @@ -70,102 +70,102 @@ ___

[adapter.ts:34](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L34)

___
---

### GetBalancesInput

Ƭ **GetBalancesInput**: [`GetPositionsInput`](../interfaces/adapter.GetPositionsInput.md) & { `provider`: `ethers.JsonRpcProvider` ; `chainId`: `Chain` ; `tokens`: [`Erc20Metadata`](erc20Metadata.md#erc20metadata)[] }
Ƭ **GetBalancesInput**: [`GetPositionsInput`](../interfaces/adapter.GetPositionsInput.md) & { `provider`: `CustomJsonRpcProvider ; `chainId`: `Chain`;`tokens`: [`Erc20Metadata`](erc20Metadata.md#erc20metadata)[] }

#### Defined in

[adapter.ts:36](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L36)

___
---

### GetConversionRateInput

Ƭ **GetConversionRateInput**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `blockNumber?` | `number` | Optional override param |
| Name | Type | Description |
| :--------------------- | :------- | :----------------------------------------- |
| `blockNumber?` | `number` | Optional override param |
| `protocolTokenAddress` | `string` | Protocol token address (LP token address). |

#### Defined in

[adapter.ts:42](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L42)

___
---

### GetApyInput

Ƭ **GetApyInput**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `blockNumber?` | `number` | Optional override param |
| Name | Type | Description |
| :--------------------- | :------- | :----------------------------------------- |
| `blockNumber?` | `number` | Optional override param |
| `protocolTokenAddress` | `string` | Protocol token address (LP token address). |

#### Defined in

[adapter.ts:52](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L52)

___
---

### GetAprInput

Ƭ **GetAprInput**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `blockNumber?` | `number` | Optional override param |
| Name | Type | Description |
| :--------------------- | :------- | :----------------------------------------- |
| `blockNumber?` | `number` | Optional override param |
| `protocolTokenAddress` | `string` | Protocol token address (LP token address). |

#### Defined in

[adapter.ts:63](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L63)

___
---

### GetEventsInput

Ƭ **GetEventsInput**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `userAddress` | `string` | User address we want to get events for |
| `protocolTokenAddress` | `string` | Protocol token we want to check related events for |
| `fromBlock` | `number` | Starting blocknumber to check from |
| `toBlock` | `number` | End blocknumber we want to check to e.g. current blocknumber |
| Name | Type | Description |
| :--------------------- | :------- | :----------------------------------------------------------- |
| `userAddress` | `string` | User address we want to get events for |
| `protocolTokenAddress` | `string` | Protocol token we want to check related events for |
| `fromBlock` | `number` | Starting blocknumber to check from |
| `toBlock` | `number` | End blocknumber we want to check to e.g. current blocknumber |

#### Defined in

[adapter.ts:74](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L74)

___
---

### ProtocolDetails

Ƭ **ProtocolDetails**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `protocolId` | `Protocol` | Unique protocol id |
| `chainId` | `Chain` | Chain this adapter is for |
| `name` | `string` | Name of protocol |
| `description` | `string` | Description of protocol |
| `iconUrl` | `string` | Protocol icon |
| `siteUrl` | `string` | Protocol website |
| Name | Type | Description |
| :------------- | :---------------------------------------- | :------------------------------------ |
| `protocolId` | `Protocol` | Unique protocol id |
| `chainId` | `Chain` | Chain this adapter is for |
| `name` | `string` | Name of protocol |
| `description` | `string` | Description of protocol |
| `iconUrl` | `string` | Protocol icon |
| `siteUrl` | `string` | Protocol website |
| `positionType` | [`PositionType`](adapter.md#positiontype) | Type of position One adapter per type |

#### Defined in
Expand All @@ -180,32 +180,32 @@ ___

#### Type declaration

| Name | Type |
| :------ | :------ |
| `Protocol` | ``"protocol"`` |
| `Reward` | ``"claimable"`` |
| `Underlying` | ``"underlying"`` |
| Name | Type |
| :----------- | :------------- |
| `Protocol` | `"protocol"` |
| `Reward` | `"claimable"` |
| `Underlying` | `"underlying"` |

#### Defined in

[adapter.ts:6](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L6)

[adapter.ts:11](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/adapter.ts#L11)

___
---

### PositionType

`Const` **PositionType**: `Object`

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `Supply` | ``"supply"`` | Liquidity position e.g. a dex pool |
| `Lend` | ``"lend"`` | Providing liquidity to a lending and borrow protocol |
| `Borrow` | ``"borrow"`` | Getting a loan from a lending and borrow protocol |
| `Staked` | ``"stake"`` | Staking a token e.g. staking eth or staking an lp token |
| Name | Type | Description |
| :------- | :--------- | :------------------------------------------------------ |
| `Supply` | `"supply"` | Liquidity position e.g. a dex pool |
| `Lend` | `"lend"` | Providing liquidity to a lending and borrow protocol |
| `Borrow` | `"borrow"` | Getting a loan from a lending and borrow protocol |
| `Staked` | `"stake"` | Staking a token e.g. staking eth or staking an lp token |

#### Defined in

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import { Chain } from '../../../../core/constants/chains'
import { CustomJsonRpcProvider } from '../../../../core/utils/customJsonRpcProvider'
import {
GetAprInput,
GetApyInput,
Expand Down Expand Up @@ -31,7 +31,7 @@ export class ExampleProductAdapter implements IProtocolAdapter {

product = 'example-pool'

private provider: ethers.JsonRpcProvider
private provider: CustomJsonRpcProvider

constructor({ provider, chainId, protocolId }: ProtocolAdapterParams) {
this.provider = provider
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const supportedProtocols: Record<
[Protocol.Example]: {
[Chain.Ethereum]: [ExampleProductAdapter],
},

[Protocol.AaveV2]: {
[Chain.Ethereum]: [
AaveV2ATokenPoolAdapter,
Expand All @@ -45,6 +46,7 @@ export const supportedProtocols: Record<
AaveV2VariableDebtTokenPoolAdapter,
],
},

[Protocol.AaveV3]: {
[Chain.Ethereum]: [
AaveV3ATokenPoolAdapter,
Expand Down Expand Up @@ -82,6 +84,7 @@ export const supportedProtocols: Record<
AaveV3VariableDebtTokenPoolAdapter,
],
},

[Protocol.UniswapV3]: {
[Chain.Ethereum]: [UniswapV3PoolAdapter],
[Chain.Arbitrum]: [UniswapV3PoolAdapter],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ethers } from 'ethers'
import { Chain } from '../../../../core/constants/chains'
import {
CacheToFile,
IMetadataBuilder,
} from '../../../../core/decorators/cacheToFile'
import { NotImplementedError } from '../../../../core/errors/errors'
import { CustomJsonRpcProvider } from '../../../../core/utils/customJsonRpcProvider'
import { getTokenMetadata } from '../../../../core/utils/getTokenMetadata'
import {
GetAprInput,
Expand Down Expand Up @@ -42,7 +42,7 @@ export class StargateVestingAdapter
protocolId: Protocol
chainId: Chain

private provider: ethers.JsonRpcProvider
private provider: CustomJsonRpcProvider

constructor({ provider, chainId, protocolId }: ProtocolAdapterParams) {
this.provider = provider
Expand Down
5 changes: 3 additions & 2 deletions src/adapters/uniswap-v3/products/pool/uniswapV3PoolAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ethers, formatUnits } from 'ethers'
import { formatUnits } from 'ethers'
import { Chain } from '../../../../core/constants/chains'
import { NotImplementedError } from '../../../../core/errors/errors'
import { aggregateTrades } from '../../../../core/utils/aggregateTrades'
import { CustomJsonRpcProvider } from '../../../../core/utils/customJsonRpcProvider'
import { filterMapAsync } from '../../../../core/utils/filters'
import { getTokenMetadata } from '../../../../core/utils/getTokenMetadata'
import { formatProtocolTokenArrayToMap } from '../../../../core/utils/protocolTokenToMap'
Expand Down Expand Up @@ -71,7 +72,7 @@ export class UniswapV3PoolAdapter implements IProtocolAdapter {
protocolId: Protocol
chainId: Chain

private provider: ethers.JsonRpcProvider
private provider: CustomJsonRpcProvider

constructor({ provider, chainId, protocolId }: ProtocolAdapterParams) {
this.provider = provider
Expand Down
4 changes: 2 additions & 2 deletions src/core/adapters/SimplePoolAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ethers } from 'ethers'
import { formatUnits } from 'ethers'
import { Protocol } from '../../adapters/protocols'
import { Erc20__factory } from '../../contracts'
Expand Down Expand Up @@ -33,14 +32,15 @@ import { IProtocolAdapter } from '../../types/IProtocolAdapter'
import { Chain } from '../constants/chains'
import { ZERO_ADDRESS } from '../constants/ZERO_ADDRESS'
import { aggregateTrades } from '../utils/aggregateTrades'
import { CustomJsonRpcProvider } from '../utils/customJsonRpcProvider'
import { getBalances } from '../utils/getBalances'
import { formatProtocolTokenArrayToMap } from '../utils/protocolTokenToMap'

export abstract class SimplePoolAdapter implements IProtocolAdapter {
chainId: Chain
protocolId: Protocol

protected provider: ethers.JsonRpcProvider
protected provider: CustomJsonRpcProvider

constructor({ provider, chainId, protocolId }: ProtocolAdapterParams) {
this.provider = provider
Expand Down
11 changes: 11 additions & 0 deletions src/core/constants/AVERAGE_BLOCKS_PER_10_MINS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AVERAGE_BLOCKS_PER_DAY } from './AVERAGE_BLOCKS_PER_DAY'
import { Chain } from './chains'

export const AVERAGE_BLOCKS_PER_10_MINUTES: Record<Chain, number> =
Object.entries(AVERAGE_BLOCKS_PER_DAY).reduce(
(acc, [chain, blocksPerDay]) => {
acc[chain as unknown as Chain] = (blocksPerDay * 10) / (24 * 60)
return acc
},
{} as Record<Chain, number>,
)
4 changes: 2 additions & 2 deletions src/core/utils/CustomMulticallJsonRpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('CustomMulticallJsonRpcProvider', () => {

const provider = new CustomMulticallJsonRpcProvider({
url: 'www.oioi.com',
network: 1,
chainId: 1,
multicallQueue,
})

Expand All @@ -23,7 +23,7 @@ describe('CustomMulticallJsonRpcProvider', () => {
it('sends normal eth_call', async () => {
const provider = new CustomMulticallJsonRpcProvider({
url: 'www.oioi.com',
network: 1,
chainId: 1,
multicallQueue: {} as MulticallQueue,
})

Expand Down
12 changes: 7 additions & 5 deletions src/core/utils/CustomMulticallJsonRpcProvider.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { JsonRpcProvider, Networkish, TransactionRequest } from 'ethers'
import { TransactionRequest } from 'ethers'
import { Chain } from '../constants/chains'
import { CustomJsonRpcProvider } from './customJsonRpcProvider'
import { logger } from './logger'
import { MulticallQueue } from './multicall'

export class CustomMulticallJsonRpcProvider extends JsonRpcProvider {
export class CustomMulticallJsonRpcProvider extends CustomJsonRpcProvider {
private multicallQueue: MulticallQueue
constructor({
url,
network,
chainId,
multicallQueue,
}: {
url: string
network: Networkish
chainId: Chain
multicallQueue: MulticallQueue
}) {
super(url, network)
super({ url, chainId })
this.multicallQueue = multicallQueue
}

Expand Down
Loading

0 comments on commit 60526ae

Please sign in to comment.