Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(maple): Implemented Maple v2 and migrate to template (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin committed Dec 14, 2022
1 parent d1c2f2f commit d4634a1
Show file tree
Hide file tree
Showing 12 changed files with 1,503 additions and 3,274 deletions.
50 changes: 50 additions & 0 deletions src/apps/maple/common/maple.pool.definition-resolver.ts
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),
}));
}
}
Loading

0 comments on commit d4634a1

Please sign in to comment.