Skip to content

Commit

Permalink
Merge branch 'main' into feature-carbon-defi
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipenunes committed Jan 11, 2024
2 parents 533b1d5 + 30851d8 commit 1b2ac72
Show file tree
Hide file tree
Showing 108 changed files with 30,219 additions and 8,096 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ DEFI_ADAPTERS_PROVIDER_FANTOM=https://rpc.ftm.tools
DEFI_ADAPTERS_PROVIDER_BASE=https://1rpc.io/base
DEFI_ADAPTERS_PROVIDER_ARBITRUM=https://arbitrum-mainnet.infura.io/v3/abafec30d6aa45ffa0c763b5552a2d02
DEFI_ADAPTERS_PROVIDER_AVALANCHE=https://avalanche-mainnet.infura.io/v3/abafec30d6aa45ffa0c763b5552a2d02
DEFI_ADAPTERS_PROVIDER_LINEA=https://linea-mainnet.infura.io/v3/abafec30d6aa45ffa0c763b5552a2d02
DEFI_ADAPTERS_PROVIDER_LINEA=https://linea-mainnet.infura.io/v3/abafec30d6aa45ffa0c763b5552a2d02
DEFI_ADAPTERS_ENABLE_USD_PRICES_FOR_POSITIONS=true
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- main

jobs:
build-and-test:
lint-and-verify-cli:
runs-on: ubuntu-latest

steps:
Expand All @@ -17,12 +17,49 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'


- name: Install dependencies
run: npm ci

- name: Verify eslint config
run: npm run lint

- name: Verify prettier config
run: npm run prettier

- name: Build
run: npm run build

- name: Create new adapter with DefaultAdapter template
run: |
npm run new-adapter -- -p test-default-adapter-protocol -pd test-default-adapter-product -c 1 -t DefaultAdapter -y
npm run build
- name: Create new adapter with SimplePoolAdapter template
run: |
npm run new-adapter -- -p test-simple-pool-adapter-protocol -pd test-simple-pool-adapter-product -c 1 -t SimplePoolAdapter -y
npm run build
npm run build-metadata -- -p test-simple-pool-adapter-protocol
npm run build
run-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm test
run: npm run test:cov
env:
ETHEREUM_PROVIDER_URL: ${{ secrets.ETHEREUM_PROVIDER_URL }}
OPTIMISM_PROVIDER_URL: ${{ secrets.OPTIMISM_PROVIDER_URL }}
Expand All @@ -34,12 +71,3 @@ jobs:
AVALANCHE_PROVIDER_URL: ${{ secrets.AVALANCHE_PROVIDER_URL }}
LINEA_PROVIDER_URL: ${{ secrets.LINEA_PROVIDER_URL }}
ENABLE_MULTICALL_QUEUE: true

- name: Verify eslint config
run: npm run lint

- name: Verify prettier config
run: npm run prettier

- name: Verify that the code builds
run: npm run build
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ To build an adapter follow these steps:
- `npm run new-adapter`
4. To create a typescript-smart-contract class create a json file with your abi and add it to your ${protocolName}/contracts/abis/ folder, then run:
- `npm run build-types`
5. To build metadata files run:
- `npm run build-metadata`
6. To build snapshot tests run:
- `npm run build-snapshots`
5. To build metadata files run (replace \<protocol-id> with the id of your protocol):
- `npm run build-metadata -- -p <protocol-id>`
6. To build snapshot tests run (replace \<protocol-id> with the id of your protocol):
- `npm run build-snapshots -- -p <protocol-id>`
7. To run tests run:
- `npm run test`
8. To test your adapter further you can use the following commands, update userAddress and other params accordingly:
Expand Down Expand Up @@ -121,36 +121,32 @@ In this example, the user holds positions in both Stargate and Uniswap.

A few hours for those with knowledge of Typescript, Ethers, and the DeFi protocol.

7. What is the getProfits method?

It returns profit on individual open positions by considering weekly changes and transactions in and out of the position.

8. How do you calculate profits?
7. How do you calculate profits?

- We capture users' positions from 7 days ago using the `get positions` adapter method with a `blocknumber override`.
- We then obtain the current positions.
- To account for deposits and withdrawals in this period, we examine `mint` and `burn` events of LP tokens and convert these back to underlying tokens.
- We found this method works for the majority of protocols. However, adapt as necessary for your protocol. For example, if there are better event logs available for your protocol, use them.

9. Some adapter methods don't make sense for my DeFi-protocol?
8. Some adapter methods don't make sense for my DeFi-protocol?

Throw an error: new Error('Does not apply').

10. Can I use an API for results?
9. Can I use an API for results?

We recommend getting data directly from the blockchain over centralized APIs.

11. My protocol only has a few pools, can I hardcode the buildMetadata() result?
10. My protocol only has a few pools, can I hardcode the buildMetadata() result?

Yes. Feel free to hardcode this result if it doesn't make sense to fetch pool data on chain.

12. My protocol has more than one product, should I create separate adapters?
11. My protocol has more than one product, should I create separate adapters?

Yes. We find this reduces complexity.

13. Im getting `>> TypeError: Cannot read properties of undefined (reading 'F_OK')` error when running `npm run new-adapter`
12. Im getting `>> TypeError: Cannot read properties of undefined (reading 'F_OK')` error when running `npm run new-adapter`

Make sure you are using Node 20. Run `nvm use`
Make sure you are using Node 20. Run `nvm use`

13. How can I share feedback or proposals?

Expand Down
62 changes: 23 additions & 39 deletions docs/interfaces/IProtocolAdapter.IProtocolAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [protocolId](IProtocolAdapter.IProtocolAdapter.md#protocolid)
- [chainId](IProtocolAdapter.IProtocolAdapter.md#chainid)
- [productId](IProtocolAdapter.IProtocolAdapter.md#productid)
- [adaptersController](IProtocolAdapter.IProtocolAdapter.md#adapterscontroller)

### Methods

Expand All @@ -21,7 +22,6 @@
- [getWithdrawals](IProtocolAdapter.IProtocolAdapter.md#getwithdrawals)
- [getDeposits](IProtocolAdapter.IProtocolAdapter.md#getdeposits)
- [getTotalValueLocked](IProtocolAdapter.IProtocolAdapter.md#gettotalvaluelocked)
- [getProfits](IProtocolAdapter.IProtocolAdapter.md#getprofits)
- [getApy](IProtocolAdapter.IProtocolAdapter.md#getapy)
- [getApr](IProtocolAdapter.IProtocolAdapter.md#getapr)

Expand All @@ -35,7 +35,7 @@ Unique identifier of the protocol.

#### Defined in

[IProtocolAdapter.ts:26](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L26)
[IProtocolAdapter.ts:25](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L25)

___

Expand All @@ -47,7 +47,7 @@ Unique identifier of the blockchain network.

#### Defined in

[IProtocolAdapter.ts:31](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L31)
[IProtocolAdapter.ts:30](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L30)

___

Expand All @@ -59,7 +59,17 @@ Unique identifier for this protocol adapter

#### Defined in

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

___

### adaptersController

**adaptersController**: `AdaptersController`

#### Defined in

[IProtocolAdapter.ts:37](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L37)

## Methods

Expand All @@ -79,7 +89,7 @@ Returns high level metadata for the protocol

#### Defined in

[IProtocolAdapter.ts:43](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L43)
[IProtocolAdapter.ts:44](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L44)

___

Expand All @@ -99,7 +109,7 @@ Returns array of pool tokens (lp tokens) for the protocol

#### Defined in

[IProtocolAdapter.ts:50](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L50)
[IProtocolAdapter.ts:51](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L51)

___

Expand All @@ -125,7 +135,7 @@ Returns array of user positions opened in this protocol

#### Defined in

[IProtocolAdapter.ts:59](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L59)
[IProtocolAdapter.ts:60](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L60)

___

Expand All @@ -151,7 +161,7 @@ Returns "price" of lp-tokens in the form of the underlying tokens

#### Defined in

[IProtocolAdapter.ts:68](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L68)
[IProtocolAdapter.ts:69](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L69)

___

Expand All @@ -177,7 +187,7 @@ Returns the user's withdrawals from a position

#### Defined in

[IProtocolAdapter.ts:79](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L79)
[IProtocolAdapter.ts:80](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L80)

___

Expand All @@ -203,7 +213,7 @@ Returns the user's deposits to a position

#### Defined in

[IProtocolAdapter.ts:88](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L88)
[IProtocolAdapter.ts:89](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L89)

___

Expand All @@ -229,33 +239,7 @@ Returns the Tvl per pool defined in the underlying token

#### Defined in

[IProtocolAdapter.ts:97](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L97)

___

### getProfits

**getProfits**(`input`): [`Promise`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<[`ProfitsWithRange`](adapter.ProfitsWithRange.md)\>

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `input` | [`GetProfitsInput`](adapter.GetProfitsInput.md) | Object specifying user-address and the block range for the profit calculation. |

#### Returns

[`Promise`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<[`ProfitsWithRange`](adapter.ProfitsWithRange.md)\>

Object containing the starting and ending block numbers, and an array of objects detailing the profit information for each token.

**`Remarks`**

Returns the user's profits made on open positions. Accepts blockNumber override.

#### Defined in

[IProtocolAdapter.ts:108](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L108)
[IProtocolAdapter.ts:98](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L98)

___

Expand All @@ -281,7 +265,7 @@ Returns Apy per pool

#### Defined in

[IProtocolAdapter.ts:117](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L117)
[IProtocolAdapter.ts:109](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L109)

___

Expand All @@ -307,4 +291,4 @@ Returns Apr made per pool

#### Defined in

[IProtocolAdapter.ts:126](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L126)
[IProtocolAdapter.ts:118](https://github.com/consensys-vertical-apps/mmi-defi-adapters/blob/main/src/types/IProtocolAdapter.ts#L118)
Loading

0 comments on commit 1b2ac72

Please sign in to comment.