-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track future cashflows per asset
Fixes #196
- Loading branch information
Showing
5 changed files
with
105 additions
and
25 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
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,29 @@ | ||
import { ExtendedCall } from '../../helpers/types' | ||
import { AssetCashflow } from '../../types/models/AssetCashflow' | ||
|
||
export class AssetCashflowService extends AssetCashflow { | ||
static init(poolId: string, assetId: string, timestamp: Date, principal: bigint, interest: bigint) { | ||
logger.info(`Initialising new AssetCashflow with Id ${chainId}`) | ||
return new this( | ||
`${poolId}-${assetId}-${timestamp}`, | ||
assetId, | ||
timestamp, | ||
principal, | ||
interest | ||
) | ||
} | ||
|
||
static async recordAssetCashflows(poolId: string, assetId: string) { | ||
const specVersion = api.runtimeVersion.specVersion.toNumber() | ||
if(specVersion < 1103) return | ||
const apiCall = api.call as ExtendedCall | ||
const response = await apiCall.loansApi.expectedCashflows(poolId, assetId) | ||
const saves = response.map( ( cf ) => { | ||
const { when, principal, interest } = cf | ||
const timestamp = new Date(when.toNumber() * 1000) | ||
const cashflow = this.init(poolId, assetId, timestamp, principal.toBigInt(), interest.toBigInt()) | ||
return cashflow.save() | ||
}) | ||
return Promise.all(saves) | ||
} | ||
} |