Skip to content

Commit

Permalink
feat(koyo): Support Kōyō Finance on polygon (Zapper-fi#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
perpetuum7 authored and volt62 committed Aug 2, 2022
1 parent e01d7d9 commit c244419
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apps/koyo/koyo.definition.ts
Expand Up @@ -24,6 +24,7 @@ export const KOYO_DEFINITION = appDefinition({
supportedNetworks: {
[Network.AURORA_MAINNET]: [AppAction.VIEW],
[Network.MOONRIVER_MAINNET]: [AppAction.VIEW],
[Network.POLYGON_MAINNET]: [AppAction.VIEW],
},

primaryColor: '#fff',
Expand Down
4 changes: 4 additions & 0 deletions src/apps/koyo/koyo.module.ts
Expand Up @@ -9,6 +9,8 @@ import { AuroraKoyoPoolTokenFetcher } from './aurora/koyo.pool.token-fetcher';
import { KoyoAppDefinition, KOYO_DEFINITION } from './koyo.definition';
import { MoonriverKoyoBalanceFetcher } from './moonriver/koyo.balance-fetcher';
import { MoonriverKoyoPoolTokenFetcher } from './moonriver/koyo.pool.token-fetcher';
import { PolygonKoyoBalanceFetcher } from './polygon/koyo.balance-fetcher';
import { PolygonKoyoPoolTokenFetcher } from './polygon/koyo.pool.token-fetcher';

@Register.AppModule({
appId: KOYO_DEFINITION.id,
Expand All @@ -20,6 +22,8 @@ import { MoonriverKoyoPoolTokenFetcher } from './moonriver/koyo.pool.token-fetch
AuroraKoyoBalanceFetcher,
MoonriverKoyoPoolTokenFetcher,
MoonriverKoyoBalanceFetcher,
PolygonKoyoBalanceFetcher,
PolygonKoyoPoolTokenFetcher,
KoyoAppDefinition,
],
})
Expand Down
37 changes: 37 additions & 0 deletions src/apps/koyo/polygon/koyo.balance-fetcher.ts
@@ -0,0 +1,37 @@
import { Inject } from '@nestjs/common';

import { TokenBalanceHelper } from '~app-toolkit';
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { Network } from '~types/network.interface';

import { KOYO_DEFINITION } from '../koyo.definition';

const appId = KOYO_DEFINITION.id;
const network = Network.POLYGON_MAINNET;

@Register.BalanceFetcher(appId, network)
export class PolygonKoyoBalanceFetcher implements BalanceFetcher {
constructor(@Inject(TokenBalanceHelper) private readonly tokenBalanceHelper: TokenBalanceHelper) {}

async getPoolBalances(address: string) {
return this.tokenBalanceHelper.getTokenBalances({
address,
network,
appId,
groupId: KOYO_DEFINITION.groups.pool.id,
});
}

async getBalances(address: string) {
const [poolBalances] = await Promise.all([this.getPoolBalances(address)]);

return presentBalanceFetcherResponse([
{
label: 'Pools',
assets: poolBalances,
},
]);
}
}
35 changes: 35 additions & 0 deletions src/apps/koyo/polygon/koyo.pool.token-fetcher.ts
@@ -0,0 +1,35 @@
import { Inject } from '@nestjs/common';

import { Register } from '~app-toolkit/decorators';
import { BalancerV2PoolTokensHelper } from '~apps/balancer-v2';
import { BalancerV2TheGraphPoolTokenDataStrategy } from '~apps/balancer-v2/helpers/balancer-v2.the-graph.pool-token-address-strategy';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { AppTokenPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { KOYO_DEFINITION } from '../koyo.definition';

const appId = KOYO_DEFINITION.id;
const groupId = KOYO_DEFINITION.groups.pool.id;
const network = Network.POLYGON_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
export class PolygonKoyoPoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(BalancerV2PoolTokensHelper) private readonly poolTokensHelper: BalancerV2PoolTokensHelper,
@Inject(BalancerV2TheGraphPoolTokenDataStrategy)
private readonly theGraphPoolTokenDataStrategy: BalancerV2TheGraphPoolTokenDataStrategy,
) {}

getPositions() {
return this.poolTokensHelper.getTokenMarketData({
network,
appId,
groupId,
vaultAddress: '0xACf8489ccb47DA2D7306d827bbEDe05bFA6fea1b',
resolvePoolTokenAddresses: this.theGraphPoolTokenDataStrategy.build({
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/koyo-finance/exchange-subgraph-matic',
}),
});
}
}

0 comments on commit c244419

Please sign in to comment.