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(aurigami): Implement Aurigami (#640)
- Loading branch information
1 parent
fc61ed2
commit ffb3aa6
Showing
22 changed files
with
12,979 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,57 @@ | ||
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 AURIGAMI_DEFINITION = appDefinition({ | ||
id: 'aurigami', | ||
name: 'Aurigami', | ||
description: 'The native money market on Aurora.', | ||
url: 'https://www.aurigami.finance/', | ||
groups: { | ||
supply: { | ||
id: 'supply', | ||
type: GroupType.TOKEN, | ||
label: 'Supply', | ||
}, | ||
|
||
borrow: { | ||
id: 'borrow', | ||
type: GroupType.POSITION, | ||
label: 'Borrow', | ||
}, | ||
|
||
claimable: { | ||
id: 'claimable', | ||
type: GroupType.POSITION, | ||
label: 'Claimable', | ||
}, | ||
}, | ||
tags: [AppTag.LENDING], | ||
keywords: [], | ||
links: {}, | ||
|
||
supportedNetworks: { | ||
[Network.AURORA_MAINNET]: [AppAction.VIEW], | ||
}, | ||
|
||
primaryColor: '#fff', | ||
}); | ||
|
||
@Register.AppDefinition(AURIGAMI_DEFINITION.id) | ||
export class AurigamiAppDefinition extends AppDefinition { | ||
constructor() { | ||
super(AURIGAMI_DEFINITION); | ||
} | ||
} | ||
|
||
export const AURIGAMI_CONTRACT_ADDRESSES = { | ||
[Network.AURORA_MAINNET]: { | ||
fairLaunch: '0xC9A848AC73e378516B16E4EeBBa5ef6aFbC0BBc2', | ||
lens: '0xFfdFfBDB966Cb84B50e62d70105f2Dbf2e0A1e70', | ||
ply: '0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f', | ||
comptroller: '0x817af6cfAF35BdC1A634d6cC94eE9e4c68369Aeb', | ||
}, | ||
}; | ||
|
||
export default AURIGAMI_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,28 @@ | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { AbstractApp } from '~app/app.dynamic-module'; | ||
import { CompoundAppModule } from '~apps/compound'; | ||
|
||
import { AurigamiAppDefinition, AURIGAMI_DEFINITION } from './aurigami.definition'; | ||
import { AuroraAurigamiBalanceFetcher } from './aurora/aurigami.balance-fetcher'; | ||
import { AuroraAurigamiBorrowContractPositionFetcher } from './aurora/aurigami.borrow.contract-position-fetcher'; | ||
import { AuroraAurigamiSupplyTokenFetcher } from './aurora/aurigami.supply.token-fetcher'; | ||
import { AuroraAurigamiTvlFetcher } from './aurora/aurigami.tvl-fetcher'; | ||
import { AurigamiContractFactory } from './contracts'; | ||
import { AurigamiClaimableBalanceHelper } from './helper/aurigami.claimable.balance-helper'; | ||
|
||
@Register.AppModule({ | ||
appId: AURIGAMI_DEFINITION.id, | ||
imports: [CompoundAppModule], | ||
providers: [ | ||
AurigamiAppDefinition, | ||
AurigamiContractFactory, | ||
AuroraAurigamiBalanceFetcher, | ||
AuroraAurigamiBorrowContractPositionFetcher, | ||
AuroraAurigamiSupplyTokenFetcher, | ||
AuroraAurigamiTvlFetcher, | ||
|
||
// Helpers | ||
AurigamiClaimableBalanceHelper, | ||
], | ||
}) | ||
export class AurigamiAppModule 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,84 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { Register } from '~app-toolkit/decorators'; | ||
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present'; | ||
import { | ||
CompoundBorrowBalanceHelper, | ||
CompoundContractFactory, | ||
CompoundLendingMetaHelper, | ||
CompoundSupplyBalanceHelper, | ||
} from '~apps/compound'; | ||
import { BalanceFetcher } from '~balance/balance-fetcher.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { AURIGAMI_CONTRACT_ADDRESSES, AURIGAMI_DEFINITION } from '../aurigami.definition'; | ||
import { AurigamiClaimableBalanceHelper } from '../helper/aurigami.claimable.balance-helper'; | ||
|
||
const appId = AURIGAMI_DEFINITION.id; | ||
const network = Network.AURORA_MAINNET; | ||
|
||
@Register.BalanceFetcher(AURIGAMI_DEFINITION.id, network) | ||
export class AuroraAurigamiBalanceFetcher implements BalanceFetcher { | ||
constructor( | ||
@Inject(CompoundBorrowBalanceHelper) | ||
private readonly compoundBorrowBalanceHelper: CompoundBorrowBalanceHelper, | ||
@Inject(CompoundSupplyBalanceHelper) | ||
private readonly compoundSupplyBalanceHelper: CompoundSupplyBalanceHelper, | ||
@Inject(AurigamiClaimableBalanceHelper) | ||
private readonly aurigamiClaimableBalanceHelper: AurigamiClaimableBalanceHelper, | ||
@Inject(CompoundLendingMetaHelper) | ||
private readonly compoundLendingMetaHelper: CompoundLendingMetaHelper, | ||
@Inject(CompoundContractFactory) | ||
private readonly compoundContractFactory: CompoundContractFactory, | ||
) {} | ||
|
||
async getSupplyBalances(address: string) { | ||
return this.compoundSupplyBalanceHelper.getBalances({ | ||
address, | ||
appId, | ||
groupId: AURIGAMI_DEFINITION.groups.supply.id, | ||
network, | ||
getTokenContract: ({ address, network }) => this.compoundContractFactory.compoundCToken({ address, network }), | ||
getBalanceRaw: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address), | ||
}); | ||
} | ||
|
||
async getBorrowBalances(address: string) { | ||
return this.compoundBorrowBalanceHelper.getBalances({ | ||
address, | ||
appId, | ||
groupId: AURIGAMI_DEFINITION.groups.borrow.id, | ||
network, | ||
getTokenContract: ({ address, network }) => this.compoundContractFactory.compoundCToken({ address, network }), | ||
getBorrowBalanceRaw: ({ contract, address, multicall }) => multicall.wrap(contract).borrowBalanceCurrent(address), | ||
}); | ||
} | ||
|
||
async getClaimableBalances(address: string) { | ||
return this.aurigamiClaimableBalanceHelper.getBalances({ | ||
address, | ||
appId, | ||
groupId: AURIGAMI_DEFINITION.groups.claimable.id, | ||
network, | ||
lensAddress: AURIGAMI_CONTRACT_ADDRESSES[network].lens, | ||
comptrollerAddress: AURIGAMI_CONTRACT_ADDRESSES[network].comptroller, | ||
fairlaunchAddress: AURIGAMI_CONTRACT_ADDRESSES[network].fairLaunch, | ||
stakingPoolIds: [0], // Currently aurigami has only 1 staking pool | ||
rewardAddress: AURIGAMI_CONTRACT_ADDRESSES[network].ply, | ||
}); | ||
} | ||
|
||
async getBalances(address: string) { | ||
const [supplyBalances, borrowBalances, claimableBalances] = await Promise.all([ | ||
this.getSupplyBalances(address), | ||
this.getBorrowBalances(address), | ||
this.getClaimableBalances(address), | ||
]); | ||
|
||
const meta = this.compoundLendingMetaHelper.getMeta({ balances: [...supplyBalances, ...borrowBalances] }); | ||
const claimableProduct = { label: 'Claimable', assets: claimableBalances }; | ||
const lendingProduct = { label: 'Lending', assets: [...supplyBalances, ...borrowBalances], meta }; | ||
|
||
return presentBalanceFetcherResponse([lendingProduct, claimableProduct]); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/apps/aurigami/aurora/aurigami.borrow.contract-position-fetcher.ts
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,30 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { Register } from '~app-toolkit/decorators'; | ||
import { CompoundBorrowContractPositionHelper } from '~apps/compound'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { ContractPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { AURIGAMI_DEFINITION } from '../aurigami.definition'; | ||
|
||
const appId = AURIGAMI_DEFINITION.id; | ||
const groupId = AURIGAMI_DEFINITION.groups.borrow.id; | ||
const network = Network.AURORA_MAINNET; | ||
|
||
@Register.ContractPositionFetcher({ appId, groupId, network }) | ||
export class AuroraAurigamiBorrowContractPositionFetcher implements PositionFetcher<ContractPosition> { | ||
constructor( | ||
@Inject(CompoundBorrowContractPositionHelper) | ||
private readonly compoundBorrowContractPositionHelper: CompoundBorrowContractPositionHelper, | ||
) {} | ||
|
||
async getPositions() { | ||
return this.compoundBorrowContractPositionHelper.getPositions({ | ||
network, | ||
appId, | ||
groupId, | ||
supplyGroupId: AURIGAMI_DEFINITION.groups.supply.id, | ||
}); | ||
} | ||
} |
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,43 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { CompoundSupplyTokenHelper } from '~apps/compound'; | ||
import { PositionFetcher } from '~position/position-fetcher.interface'; | ||
import { AppTokenPosition } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { AURIGAMI_CONTRACT_ADDRESSES, AURIGAMI_DEFINITION } from '../aurigami.definition'; | ||
import { AurigamiAuToken, AurigamiComptroller, AurigamiContractFactory } from '../contracts'; | ||
|
||
const appId = AURIGAMI_DEFINITION.id; | ||
const groupId = AURIGAMI_DEFINITION.groups.supply.id; | ||
const network = Network.AURORA_MAINNET; | ||
|
||
@Register.TokenPositionFetcher({ appId, groupId, network }) | ||
export class AuroraAurigamiSupplyTokenFetcher implements PositionFetcher<AppTokenPosition> { | ||
constructor( | ||
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, | ||
@Inject(AurigamiContractFactory) private readonly aurigamiContractFactory: AurigamiContractFactory, | ||
@Inject(CompoundSupplyTokenHelper) private readonly compoundSupplyTokenHelper: CompoundSupplyTokenHelper, | ||
) {} | ||
|
||
async getPositions() { | ||
return this.compoundSupplyTokenHelper.getTokens<AurigamiComptroller, AurigamiAuToken>({ | ||
network, | ||
appId, | ||
groupId, | ||
comptrollerAddress: AURIGAMI_CONTRACT_ADDRESSES[network].comptroller, | ||
getComptrollerContract: ({ address, network }) => | ||
this.aurigamiContractFactory.aurigamiComptroller({ address, network }), | ||
getTokenContract: ({ address, network }) => this.aurigamiContractFactory.aurigamiAuToken({ address, network }), | ||
getAllMarkets: ({ contract, multicall }) => multicall.wrap(contract).getAllMarkets(), | ||
getExchangeRate: ({ contract, multicall }) => multicall.wrap(contract).callStatic.exchangeRateCurrent(), | ||
getSupplyRate: ({ contract, multicall }) => multicall.wrap(contract).supplyRatePerTimestamp(), | ||
getBorrowRate: ({ contract, multicall }) => multicall.wrap(contract).borrowRatePerTimestamp(), | ||
getUnderlyingAddress: ({ contract, multicall }) => multicall.wrap(contract).underlying(), | ||
getExchangeRateMantissa: ({ underlyingTokenDecimals, tokenDecimals }) => | ||
18 + underlyingTokenDecimals - tokenDecimals, | ||
}); | ||
} | ||
} |
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,28 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { sumBy } from 'lodash'; | ||
|
||
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Register } from '~app-toolkit/decorators'; | ||
import { CompoundSupplyTokenDataProps } from '~apps/compound/helper/compound.supply.token-helper'; | ||
import { TvlFetcher } from '~stats/tvl/tvl-fetcher.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { AURIGAMI_DEFINITION } from '../aurigami.definition'; | ||
|
||
const appId = AURIGAMI_DEFINITION.id; | ||
const network = Network.AURORA_MAINNET; | ||
|
||
@Register.TvlFetcher({ appId, network }) | ||
export class AuroraAurigamiTvlFetcher implements TvlFetcher { | ||
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} | ||
|
||
async getTvl() { | ||
const markets = await this.appToolkit.getAppTokenPositions<CompoundSupplyTokenDataProps>({ | ||
appId, | ||
groupIds: [AURIGAMI_DEFINITION.groups.supply.id], | ||
network, | ||
}); | ||
|
||
return sumBy(markets, b => b.dataProps.liquidity); | ||
} | ||
} |
Oops, something went wrong.