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

Commit

Permalink
feat(bastion-protocol): To templates (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Nov 16, 2022
1 parent 93df2f3 commit 4e0a394
Show file tree
Hide file tree
Showing 24 changed files with 854 additions and 872 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import {
CompoundBorrowContractPositionFetcher,
CompoundBorrowTokenDataProps,
GetMarketsParams,
} from '~apps/compound/common/compound.borrow.contract-position-fetcher';
import {
GetDataPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
} from '~position/template/contract-position.template.types';

import { BastionProtocolComptroller, BastionProtocolContractFactory, BastionProtocolCtoken } from '../contracts';

@PositionTemplate()
export class AuroraBastionProtocolAuroraEcosystemBorrowContractPositionFetcher extends CompoundBorrowContractPositionFetcher<
BastionProtocolCtoken,
BastionProtocolComptroller
> {
groupLabel = 'Aurora Ecosystem Realm';
comptrollerAddress = '0xe1cf09bda2e089c63330f0ffe3f6d6b790835973';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(BastionProtocolContractFactory) protected readonly contractFactory: BastionProtocolContractFactory,
) {
super(appToolkit);
}

getCompoundCTokenContract(address: string) {
return this.contractFactory.bastionProtocolCtoken({ address, network: this.network });
}

getCompoundComptrollerContract(address: string) {
return this.contractFactory.bastionProtocolComptroller({ address, network: this.network });
}

async getMarkets({ contract }: GetMarketsParams<BastionProtocolComptroller>) {
return contract.getAllMarkets();
}

async getUnderlyingAddress({ contract }: GetTokenDefinitionsParams<BastionProtocolCtoken>) {
return contract.underlying();
}

async getExchangeRate({ contract }: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.callStatic.exchangeRateCurrent();
}

async getExchangeRateMantissa(params: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
const [underlyingToken] = params.contractPosition.tokens;
const auTokenDecimals = await this.getCTokenDecimals(params);
return 18 + underlyingToken.decimals - auTokenDecimals;
}

async getBorrowRate({ contract }: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.callStatic.borrowRatePerBlock().catch(() => 0);
}

async getCash({ contract }: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.getCash();
}

async getCTokenSupply({ contract }: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.totalSupply();
}

async getCTokenDecimals({ contract }: GetDataPropsParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.decimals();
}

async getBorrowBalance({
address,
contract,
}: GetTokenBalancesParams<BastionProtocolCtoken, CompoundBorrowTokenDataProps>) {
return contract.callStatic.borrowBalanceCurrent(address);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Inject } from '@nestjs/common';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import { CompoundSupplyTokenFetcher, GetMarketsParams } from '~apps/compound/common/compound.supply.token-fetcher';
import {
GetUnderlyingTokensParams,
GetPricePerShareParams,
GetDataPropsParams,
} from '~position/template/app-token.template.types';

import { BastionProtocolComptroller, BastionProtocolContractFactory, BastionProtocolCtoken } from '../contracts';

@PositionTemplate()
export class AuroraBastionProtocolAuroraEcosystemSupplyTokenFetcher extends CompoundSupplyTokenFetcher<
BastionProtocolCtoken,
BastionProtocolComptroller
> {
groupLabel = 'Aurora Ecosystem Realm';
comptrollerAddress = '0xe1cf09bda2e089c63330f0ffe3f6d6b790835973';

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(BastionProtocolContractFactory) protected readonly contractFactory: BastionProtocolContractFactory,
) {
super(appToolkit);
}

getCompoundCTokenContract(address: string): BastionProtocolCtoken {
return this.contractFactory.bastionProtocolCtoken({ address, network: this.network });
}

getCompoundComptrollerContract(address: string) {
return this.contractFactory.bastionProtocolComptroller({ address, network: this.network });
}

async getMarkets({ contract }: GetMarketsParams<BastionProtocolComptroller>) {
return contract.getAllMarkets();
}

async getUnderlyingAddress({ contract }: GetUnderlyingTokensParams<BastionProtocolCtoken>) {
return contract.underlying();
}

async getExchangeRate({ contract }: GetPricePerShareParams<BastionProtocolCtoken>) {
return contract.callStatic.exchangeRateCurrent();
}

async getSupplyRate({ contract }: GetDataPropsParams<BastionProtocolCtoken>) {
return contract.supplyRatePerBlock();
}
}
153 changes: 0 additions & 153 deletions src/apps/bastion-protocol/aurora/bastion-protocol.balance-fetcher.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4e0a394

Please sign in to comment.