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 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(koyo): Support Kōyō Finance on polygon (#883)
- Loading branch information
1 parent
e82c8e7
commit 8e188be
Showing
4 changed files
with
77 additions
and
0 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
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
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,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, | ||
}, | ||
]); | ||
} | ||
} |
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,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', | ||
}), | ||
}); | ||
} | ||
} |