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

Commit

Permalink
feat(diffusion-protocol): Add Diffusion Pools (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffy-dev authored Jun 15, 2022
1 parent 7fc2291 commit fac4d88
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/apps/diffusion/contracts/index.ts
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));
}
}
46 changes: 46 additions & 0 deletions src/apps/diffusion/diffusion.definition.ts
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;
14 changes: 14 additions & 0 deletions src/apps/diffusion/diffusion.module.ts
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() {}
59 changes: 59 additions & 0 deletions src/apps/diffusion/evmos/diffusion.pool.token-fetcher.ts
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()]),
});
}
}
3 changes: 3 additions & 0 deletions src/apps/diffusion/index.ts
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';

0 comments on commit fac4d88

Please sign in to comment.