import { BondType , NetworkAddresses } from "./constants" ; import { Networks } from "../../constants/blockchain" ; import { ContractInterface , Contract } from "ethers" ; import React from "react" ; import { JsonRpcSigner , StaticJsonRpcProvider } from "@ethersproject/providers" ; import { getTokenPrice } from "../token-price" ; export interface BondOpts { readonly name : string ; readonly displayName : string ; readonly bondIconSvg : string ; readonly bondContractABI : ContractInterface ; readonly networkAddrs : NetworkAddresses ; readonly bondToken : string ; } export abstract class Bond { public readonly name : string ; public readonly displayName : string ; public readonly type : BondType ; public readonly bondIconSvg : string ; public readonly bondContractABI : ContractInterface ; public readonly networkAddrs : NetworkAddresses ; public readonly bondToken : string ; public readonly lpUrl ? : string ; public readonly tokensInStrategy ? : string ; public abstract isLP : boolean ; protected abstract reserveContractAbi : ContractInterface ; public abstract displayUnits : string ; public abstract getTreasuryBalance ( networkID , provider ) ; public abstract getTokenAmount ( networkID , provider ) ; public abstract getTimeAmount ( networkID , provider ) ; constructor ( type , bondOpts ) { this . name = bondOpts . name ; this . displayName = bondOpts . displayName ; this . type = type ; this . bondIconSvg = bondOpts . bondIconSvg ; this . bondContractABI = bondOpts . bondContractABI ; this . networkAddrs = bondOpts . networkAddrs ; this . bondToken = bondOpts . bondToken ; } public getAddressForBond ( networkID ) { return this . networkAddrs [ networkID ] . bondAddress ; } public getContractForBond ( networkID , provider ) { const bondAddress = this . getAddressForBond ( networkID ) ; return new Contract ( bondAddress , this . bondContractABI , provider ) ; } public getAddressForReserve ( networkID ) { return this . networkAddrs [ networkID ] . reserveAddress ; } public getContractForReserve ( networkID , provider ) { const reserveAddress = this . getAddressForReserve ( networkID ) ; return new Contract ( reserveAddress , this . reserveContractAbi , provider ) ; } protected getTokenPrice ( ) { return getTokenPrice ( this . bondToken ) ; } }