Skip to content

Commit 36dae41

Browse files
committed
fix: move contractType decoding to base contract
1 parent f838419 commit 36dae41

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/base/BaseContract.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@ import type {
1010
Hex,
1111
Log,
1212
} from "viem";
13-
import { decodeFunctionData, getContract } from "viem";
13+
import { decodeFunctionData, getContract, isHex } from "viem";
1414

1515
import { iVersionAbi } from "../abi";
1616
import { ADDRESS_0X0 } from "../constants";
1717
import type { GearboxSDK } from "../GearboxSDK";
1818
import type { BaseContractState } from "../state";
1919
import type { ILogger, RawTx } from "../types";
20-
import { childLogger, createRawTx, json_stringify } from "../utils";
20+
import {
21+
bytes32ToString,
22+
childLogger,
23+
createRawTx,
24+
json_stringify,
25+
} from "../utils";
2126
import type { IAddressLabeller } from "./IAddressLabeller";
2227
import { SDKConstruct } from "./SDKConstruct";
2328

2429
export interface BaseContractOptions<abi extends Abi | readonly unknown[]> {
2530
abi: abi;
2631
address: Address;
27-
name: string;
32+
name?: string;
2833
version?: number;
2934
contractType?: string;
3035
}
@@ -53,9 +58,12 @@ export abstract class BaseContract<
5358
public: sdk.provider.publicClient,
5459
},
5560
});
56-
this.name = this.#name = args.name || args.contractType || this.#address;
5761
this.version = args.version || 0;
58-
this.contractType = args.contractType || "";
62+
this.contractType = args.contractType ?? "";
63+
if (isHex(this.contractType)) {
64+
this.contractType = bytes32ToString(this.contractType);
65+
}
66+
this.name = this.#name = args.name || this.contractType || this.#address;
5967
this.logger = childLogger(this.name, sdk.logger);
6068

6169
// register contract by address

src/market/pricefeeds/AbstractPriceFeed.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { Abi, Hex } from "viem";
1+
import type { Abi } from "viem";
22

33
import { ilpPriceFeedAbi } from "../../abi";
44
import type { PriceFeedTreeNode } from "../../base";
55
import { BaseContract } from "../../base";
66
import type { GearboxSDK } from "../../GearboxSDK";
77
import type { PriceFeedState } from "../../state";
8-
import { bytes32ToString } from "../../utils";
98
import { PriceFeedRef } from "./PriceFeedRef";
109
import type { IPriceFeedContract, PriceFeedContractType } from "./types";
1110

@@ -25,23 +24,18 @@ export abstract class AbstractPriceFeedContract<
2524
* True if the contract deployed at this address implements IUpdatablePriceFeed interface
2625
*/
2726
public readonly updatable: boolean;
28-
public readonly priceFeedType: PriceFeedContractType;
2927
public readonly decimals: number;
3028
public readonly underlyingPriceFeeds: PriceFeedRef[];
3129
public hasLowerBoundCap = false;
3230

3331
constructor(sdk: GearboxSDK, args: PriceFeedConstructorArgs<abi>) {
34-
const priceFeedType = bytes32ToString(
35-
args.baseParams.contractType as Hex,
36-
) as PriceFeedContractType;
3732
super(sdk, {
3833
abi: args.abi,
3934
address: args.baseParams.addr,
4035
name: args.name,
41-
contractType: priceFeedType,
36+
contractType: args.baseParams.contractType,
4237
version: Number(args.baseParams.version),
4338
});
44-
this.priceFeedType = priceFeedType;
4539
this.decimals = args.decimals;
4640
this.updatable = args.updatable;
4741
this.underlyingPriceFeeds = args.underlyingFeeds.map(
@@ -50,6 +44,10 @@ export abstract class AbstractPriceFeedContract<
5044
);
5145
}
5246

47+
public get priceFeedType(): PriceFeedContractType {
48+
return this.contractType as PriceFeedContractType;
49+
}
50+
5351
public abstract get state(): Omit<PriceFeedState, "stalenessPeriod">;
5452

5553
async currentLowerBound(): Promise<bigint> {

0 commit comments

Comments
 (0)