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(diffusion-protocol): Add Diffusion Pools (#629)
- Loading branch information
1 parent
7fc2291
commit fac4d88
Showing
5 changed files
with
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { ContractFactory } from '~contract/contracts'; | ||
import { Network } from '~types/network.interface'; | ||
// eslint-disable-next-line | ||
type ContractOpts = { address: string; network: Network }; | ||
|
||
@Injectable() | ||
export class DiffusionContractFactory extends ContractFactory { | ||
constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) { | ||
super((network: Network) => appToolkit.getNetworkProvider(network)); | ||
} | ||
} |
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,46 @@ | ||
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 DIFFUSION_DEFINITION = appDefinition({ | ||
id: 'diffusion', | ||
name: 'Diffusion Finance', | ||
description: 'The Evmos AMM ⚛️💙🐧', | ||
url: 'https://app.diffusion.fi/', | ||
|
||
groups: { | ||
pool: { id: 'pool', type: GroupType.TOKEN, label: 'Pools' }, | ||
farm: { id: 'farm', type: GroupType.TOKEN, label: 'Staked', groupLabel: 'Farms' }, | ||
diffStaking: { id: 'diff-staking', type: GroupType.TOKEN, label: 'xDiff Pools', groupLabel: 'Pools' }, | ||
}, | ||
|
||
tags: [AppTag.DECENTRALIZED_EXCHANGE, AppTag.FARMING, AppTag.LIQUIDITY_POOL, AppTag.STAKING], | ||
|
||
keywords: ['dex', 'defi', 'evmos', 'cosmos', 'decentralized finance', 'diffusion', 'pools', 'liquidity', 'staking'], | ||
links: { | ||
github: 'https://github.com/diffusion-fi', | ||
twitter: 'https://twitter.com/diffusion_fi', | ||
discord: 'http://discord.gg/diffusion-fi', | ||
}, | ||
|
||
supportedNetworks: { | ||
[Network.EVMOS_MAINNET]: [AppAction.VIEW], | ||
}, | ||
|
||
token: { | ||
address: '0x3f75ceabcdfed1aca03257dc6bdc0408e2b4b026', | ||
network: Network.EVMOS_MAINNET, | ||
}, | ||
|
||
primaryColor: '#27D2EA', | ||
}); | ||
|
||
@Register.AppDefinition(DIFFUSION_DEFINITION.id) | ||
export class DiffusionAppDefinition extends AppDefinition { | ||
constructor() { | ||
super(DIFFUSION_DEFINITION); | ||
} | ||
} | ||
|
||
export default DIFFUSION_DEFINITION; |
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,14 @@ | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { AbstractApp } from '~app/app.dynamic-module'; | ||
import { UniswapV2AppModule } from '~apps/uniswap-v2'; | ||
|
||
import { DiffusionContractFactory } from './contracts'; | ||
import { DiffusionAppDefinition, DIFFUSION_DEFINITION } from './diffusion.definition'; | ||
import { EvmosDiffusionPoolTokenFetcher } from './evmos/diffusion.pool.token-fetcher'; | ||
|
||
@Register.AppModule({ | ||
appId: DIFFUSION_DEFINITION.id, | ||
providers: [DiffusionAppDefinition, DiffusionContractFactory, EvmosDiffusionPoolTokenFetcher, UniswapV2AppModule], | ||
imports: [UniswapV2AppModule], | ||
}) | ||
export class DiffusionAppModule extends AbstractApp() {} |
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,59 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { UniswapV2ContractFactory } from '~apps/uniswap-v2/contracts'; | ||
import { UniswapV2OnChainPoolTokenAddressStrategy } from '~apps/uniswap-v2/helpers/uniswap-v2.on-chain.pool-token-address-strategy'; | ||
import { UniswapV2PoolTokenHelper } from '~apps/uniswap-v2/helpers/uniswap-v2.pool.token-helper'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { DiffusionContractFactory } from '../contracts'; | ||
import { DIFFUSION_DEFINITION } from '../diffusion.definition'; | ||
|
||
const appId = DIFFUSION_DEFINITION.id; | ||
const groupId = DIFFUSION_DEFINITION.groups.pool.id; | ||
const network = Network.EVMOS_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class EvmosDiffusionPoolTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(UniswapV2ContractFactory) | ||
private readonly uniswapV2ContractFactory: UniswapV2ContractFactory, | ||
@Inject(UniswapV2OnChainPoolTokenAddressStrategy) | ||
private readonly uniswapV2OnChainPoolTokenAddressStrategy: UniswapV2OnChainPoolTokenAddressStrategy, | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(UniswapV2PoolTokenHelper) | ||
@Inject(DiffusionContractFactory) | ||
private readonly diffusionContractFactory: DiffusionContractFactory, | ||
@Inject(UniswapV2PoolTokenHelper) | ||
private readonly uniswapV2PoolTokenHelper: UniswapV2PoolTokenHelper, | ||
) {} | ||
|
||
async getPositions() { | ||
return await this.uniswapV2PoolTokenHelper.getTokens({ | ||
network, | ||
appId, | ||
groupId, | ||
factoryAddress: '0x6aBdDa34Fb225be4610a2d153845e09429523Cd2', | ||
resolveFactoryContract: ({ address, network }) => | ||
this.uniswapV2ContractFactory.uniswapFactory({ address, network }), | ||
resolvePoolContract: ({ address, network }) => this.uniswapV2ContractFactory.uniswapPair({ address, network }), | ||
resolvePoolTokenAddresses: this.uniswapV2OnChainPoolTokenAddressStrategy.build({ | ||
resolvePoolsLength: ({ multicall, factoryContract }) => multicall.wrap(factoryContract).allPairsLength(), | ||
resolvePoolAddress: ({ multicall, factoryContract, poolIndex }) => | ||
multicall.wrap(factoryContract).allPairs(poolIndex), | ||
}), | ||
resolvePoolTokenSymbol: ({ multicall, poolContract }) => multicall.wrap(poolContract).symbol(), | ||
resolvePoolTokenSupply: ({ multicall, poolContract }) => multicall.wrap(poolContract).totalSupply(), | ||
resolvePoolReserves: async ({ multicall, poolContract }) => | ||
multicall | ||
.wrap(poolContract) | ||
.getReserves() | ||
.then(v => [v[0], v[1]]), | ||
resolvePoolUnderlyingTokenAddresses: async ({ multicall, poolContract }) => | ||
Promise.all([multicall.wrap(poolContract).token0(), multicall.wrap(poolContract).token1()]), | ||
}); | ||
} | ||
} |
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,3 @@ | ||
export { DIFFUSION_DEFINITION, DiffusionAppDefinition } from './diffusion.definition'; | ||
export { DiffusionAppModule } from './diffusion.module'; | ||
export { DiffusionContractFactory } from './contracts'; |