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

feat: add support for Kōyō Finance #876

Merged
merged 10 commits into from
Jul 14, 2022
Binary file added src/apps/koyo/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/apps/koyo/aurora/koyo.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -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.AURORA_MAINNET;

@Register.BalanceFetcher(appId, network)
export class AuroraKoyoBalanceFetcher 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/aurora/koyo.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -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.AURORA_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
export class AuroraKoyoPoolTokenFetcher 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: '0x0613adbd846cb73e65aa474b785f52697af04c0b',
resolvePoolTokenAddresses: this.theGraphPoolTokenDataStrategy.build({
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/koyo-finance/exchange-subgraph-aurora',
}),
});
}
}
3 changes: 3 additions & 0 deletions src/apps/koyo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { KOYO_DEFINITION, KoyoAppDefinition } from './koyo.definition';
export { KoyoAppModule } from './koyo.module';
export { KoyoContractFactory } from './contracts';
39 changes: 39 additions & 0 deletions src/apps/koyo/koyo.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Register } from '~app-toolkit/decorators';
import { appDefinition, AppDefinition } from '~app/app.definition';
import { AppAction, AppTag, GroupType } from '~app/app.interface';
import { Network } from '~types/network.interface';

export const KOYO_DEFINITION = appDefinition({
id: 'koyo',
name: 'Kōyō Finance',
description:
'Kōyō is a AMM protocol based on Balancer aimed at providing stable pools alongside variable rate, multi token pools.',
url: 'https://koyo.finance',
groups: {
pool: { id: 'pool', type: GroupType.TOKEN, label: 'Pools' },
},
tags: [AppTag.DECENTRALIZED_EXCHANGE],
keywords: [],

links: {
github: 'https://github.com/koyo-finance/',
twitter: 'https://twitter.com/koyofinance/',
discord: 'https://docs.koyo.finance/discord/',
},

supportedNetworks: {
[Network.AURORA_MAINNET]: [AppAction.VIEW],
[Network.MOONRIVER_MAINNET]: [AppAction.VIEW],
},

primaryColor: '#fff',
});

@Register.AppDefinition(KOYO_DEFINITION.id)
export class KoyoAppDefinition extends AppDefinition {
constructor() {
super(KOYO_DEFINITION);
}
}

export default KOYO_DEFINITION;
26 changes: 26 additions & 0 deletions src/apps/koyo/koyo.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Register } from '~app-toolkit/decorators';
import { AbstractApp } from '~app/app.dynamic-module';
import { BalancerV2ContractFactory } from '~apps/balancer-v2/contracts/index';
import { BalancerV2PoolTokensHelper } from '~apps/balancer-v2/helpers/balancer-v2.pool.token-helper';
import { BalancerV2TheGraphPoolTokenDataStrategy } from '~apps/balancer-v2/helpers/balancer-v2.the-graph.pool-token-address-strategy';

import { AuroraKoyoBalanceFetcher } from './aurora/koyo.balance-fetcher';
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';

@Register.AppModule({
appId: KOYO_DEFINITION.id,
providers: [
BalancerV2ContractFactory,
BalancerV2TheGraphPoolTokenDataStrategy,
BalancerV2PoolTokensHelper,
AuroraKoyoPoolTokenFetcher,
AuroraKoyoBalanceFetcher,
MoonriverKoyoPoolTokenFetcher,
MoonriverKoyoBalanceFetcher,
KoyoAppDefinition,
],
})
export class KoyoAppModule extends AbstractApp() {}
37 changes: 37 additions & 0 deletions src/apps/koyo/moonriver/koyo.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -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.MOONRIVER_MAINNET;

@Register.BalanceFetcher(appId, network)
export class MoonriverKoyoBalanceFetcher 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/moonriver/koyo.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -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.MOONRIVER_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
export class MoonriverKoyoPoolTokenFetcher 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: '0xea1e627c12df4e054d61fd408ff7186353ac6ca1',
resolvePoolTokenAddresses: this.theGraphPoolTokenDataStrategy.build({
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/koyo-finance/exchange-subgraph-moonriver',
}),
});
}
}