1- import type { Abi , UnionOmit } from "viem" ;
1+ import type { Abi , RequiredBy , UnionOmit } from "viem" ;
22
33import { ilpPriceFeedAbi } from "../../abi" ;
44import type { PriceFeedTreeNode } from "../../base" ;
@@ -8,8 +8,13 @@ import type { PriceFeedStateHuman } from "../../types";
88import { PriceFeedRef } from "./PriceFeedRef" ;
99import type { IPriceFeedContract , PriceFeedContractType } from "./types" ;
1010
11+ export type PartialPriceFeedTreeNode = RequiredBy <
12+ Partial < PriceFeedTreeNode > ,
13+ "baseParams"
14+ > ;
15+
1116export type PriceFeedConstructorArgs < abi extends Abi | readonly unknown [ ] > =
12- PriceFeedTreeNode & {
17+ PartialPriceFeedTreeNode & {
1318 abi : abi ;
1419 name : string ;
1520 } ;
@@ -23,10 +28,11 @@ export abstract class AbstractPriceFeedContract<
2328 /**
2429 * True if the contract deployed at this address implements IUpdatablePriceFeed interface
2530 */
26- public readonly updatable : boolean ;
27- public readonly decimals : number ;
28- public readonly underlyingPriceFeeds : PriceFeedRef [ ] ;
29- public readonly skipCheck : boolean ;
31+ #updatable?: boolean ;
32+ #decimals?: number ;
33+ #underlyingPriceFeeds?: readonly PriceFeedRef [ ] ;
34+ #skipCheck?: boolean ;
35+
3036 public hasLowerBoundCap = false ;
3137
3238 constructor ( sdk : GearboxSDK , args : PriceFeedConstructorArgs < abi > ) {
@@ -37,13 +43,52 @@ export abstract class AbstractPriceFeedContract<
3743 contractType : args . baseParams . contractType ,
3844 version : args . baseParams . version ,
3945 } ) ;
40- this . decimals = args . decimals ;
41- this . updatable = args . updatable ;
42- this . skipCheck = args . skipCheck ;
43- this . underlyingPriceFeeds = args . underlyingFeeds . map (
44- ( address , i ) =>
45- new PriceFeedRef ( this . sdk , address , args . underlyingStalenessPeriods [ i ] ) ,
46- ) ;
46+ this . #decimals = args . decimals ;
47+ this . #updatable = args . updatable ;
48+ this . #skipCheck = args . skipCheck ;
49+
50+ if ( args . underlyingFeeds && args . underlyingStalenessPeriods ) {
51+ this . #underlyingPriceFeeds = args . underlyingFeeds . map (
52+ ( address , i ) =>
53+ new PriceFeedRef (
54+ this . sdk ,
55+ address ,
56+ args . underlyingStalenessPeriods ! [ i ] ,
57+ ) ,
58+ ) ;
59+ }
60+ }
61+
62+ public get loaded ( ) : boolean {
63+ return this . #decimals !== undefined ;
64+ }
65+
66+ public get decimals ( ) : number {
67+ if ( this . #decimals === undefined ) {
68+ throw new Error ( "price feed has been initialized with BaseParams only" ) ;
69+ }
70+ return this . #decimals;
71+ }
72+
73+ public get updatable ( ) : boolean {
74+ if ( this . #updatable === undefined ) {
75+ throw new Error ( "price feed has been initialized with BaseParams only" ) ;
76+ }
77+ return this . #updatable;
78+ }
79+
80+ public get skipCheck ( ) : boolean {
81+ if ( this . #skipCheck === undefined ) {
82+ throw new Error ( "price feed has been initialized with BaseParams only" ) ;
83+ }
84+ return this . #skipCheck;
85+ }
86+
87+ public get underlyingPriceFeeds ( ) : readonly PriceFeedRef [ ] {
88+ if ( ! this . #underlyingPriceFeeds) {
89+ throw new Error ( "price feed has been initialized with BaseParams only" ) ;
90+ }
91+ return this . #underlyingPriceFeeds;
4792 }
4893
4994 public get priceFeedType ( ) : PriceFeedContractType {
0 commit comments