This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maple): Implemented Maple v2 and migrate to template (#1910)
- Loading branch information
Showing
12 changed files
with
1,503 additions
and
3,274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { gql, GraphQLClient } from 'graphql-request'; | ||
|
||
import { CacheOnInterval } from '~cache/cache-on-interval.decorator'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { MAPLE_DEFINITION } from '../maple.definition'; | ||
|
||
type MaplePoolResponse = { | ||
poolV2S?: { | ||
id: string; | ||
name: string; | ||
apyData: { | ||
apy: string; | ||
}; | ||
}[]; | ||
}; | ||
|
||
const ALL_POOLS_QUERY = gql` | ||
{ | ||
poolV2S { | ||
id | ||
name | ||
apyData { | ||
apy | ||
} | ||
} | ||
} | ||
`; | ||
|
||
@Injectable() | ||
export class MaplePoolDefinitionResolver { | ||
@CacheOnInterval({ | ||
key: `studio:${MAPLE_DEFINITION.id}:${MAPLE_DEFINITION.groups.pool.id}:${Network.ETHEREUM_MAINNET}:pool-data`, | ||
timeout: 15 * 60 * 1000, | ||
failOnMissingData: false, | ||
}) | ||
async getPoolDefinitions() { | ||
const client = new GraphQLClient('https://api.maple.finance/v2/graphql', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
const pairsData = await client.request<MaplePoolResponse>(ALL_POOLS_QUERY); | ||
|
||
return (pairsData.poolV2S ?? []).map(pool => ({ | ||
address: pool.id.toLowerCase(), | ||
poolName: pool.name, | ||
apy: Number(pool.apyData.apy), | ||
})); | ||
} | ||
} |
Oops, something went wrong.