Skip to content

Commit 5ee8e0b

Browse files
committed
fix: add methods to get gauges
1 parent aa52404 commit 5ee8e0b

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

src/sdk/base/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Address, Hex } from "viem";
66

77
import type {
88
iCreditAccountCompressorAbi,
9+
iGaugeCompressorAbi,
910
iMarketCompressorAbi,
1011
iPeripheryCompressorAbi,
1112
iRewardsCompressorAbi,
@@ -20,6 +21,10 @@ export interface BaseParams {
2021
serializedParams: Hex;
2122
}
2223

24+
export type MarketFilter = AbiParametersToPrimitiveTypes<
25+
ExtractAbiFunction<typeof iMarketCompressorAbi, "getMarkets">["inputs"]
26+
>[0];
27+
2328
export type CreditAccountData = Unarray<
2429
AbiParametersToPrimitiveTypes<
2530
ExtractAbiFunction<
@@ -47,6 +52,12 @@ export type ZapperData = Unarray<
4752
>
4853
>;
4954

55+
export type GaugeData = Unarray<
56+
AbiParametersToPrimitiveTypes<
57+
ExtractAbiFunction<typeof iGaugeCompressorAbi, "getGauge">["outputs"]
58+
>
59+
>;
60+
5061
export type BotData = Unarray<
5162
AbiParametersToPrimitiveTypes<
5263
ExtractAbiFunction<

src/sdk/market/MarketRegister.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import type { Address } from "viem";
22

3-
import { iMarketCompressorAbi, iPeripheryCompressorAbi } from "../abi";
4-
import type { MarketData, ZapperData } from "../base";
3+
import {
4+
iGaugeCompressorAbi,
5+
iMarketCompressorAbi,
6+
iPeripheryCompressorAbi,
7+
} from "../abi";
8+
import type { GaugeData, MarketData, MarketFilter, ZapperData } from "../base";
59
import { SDKConstruct } from "../base";
610
import {
711
ADDRESS_0X0,
12+
AP_GAUGE_COMPRESSOR,
813
AP_MARKET_COMPRESSOR,
914
AP_PERIPHERY_COMPRESSOR,
1015
} from "../constants";
@@ -32,6 +37,8 @@ export class MarketRegister extends SDKConstruct {
3237
#markets = new AddressMap<MarketSuite>();
3338
#zappers: ZapperData[] = [];
3439

40+
#marketFilter?: MarketFilter;
41+
3542
constructor(sdk: GearboxSDK, markets?: MarketData[]) {
3643
super(sdk);
3744
this.#logger = childLogger("MarketRegister", sdk.logger);
@@ -79,6 +86,36 @@ export class MarketRegister extends SDKConstruct {
7986
}
8087
}
8188

89+
public async getGauges(staker: Address): Promise<GaugeData[]> {
90+
const gcAddr =
91+
this.sdk.addressProvider.getLatestVersion(AP_GAUGE_COMPRESSOR);
92+
if (!this.#marketFilter) {
93+
throw new Error("market filter is not set");
94+
}
95+
const resp = await this.provider.publicClient.readContract({
96+
abi: iGaugeCompressorAbi,
97+
address: gcAddr,
98+
functionName: "getGauges",
99+
args: [this.#marketFilter, staker],
100+
});
101+
return [...resp];
102+
}
103+
104+
public async getGauge(gauge: Address, staker: Address): Promise<GaugeData> {
105+
const gcAddr =
106+
this.sdk.addressProvider.getLatestVersion(AP_GAUGE_COMPRESSOR);
107+
if (!this.#marketFilter) {
108+
throw new Error("market filter is not set");
109+
}
110+
const resp = await this.provider.publicClient.readContract({
111+
abi: iGaugeCompressorAbi,
112+
address: gcAddr,
113+
functionName: "getGauge",
114+
args: [gauge, staker],
115+
});
116+
return resp;
117+
}
118+
82119
public async syncState(): Promise<void> {
83120
const pools = this.markets
84121
.filter(m => m.dirty)
@@ -94,6 +131,11 @@ export class MarketRegister extends SDKConstruct {
94131
pools: Address[],
95132
ignoreUpdateablePrices?: boolean,
96133
): Promise<void> {
134+
this.#marketFilter = {
135+
configurators,
136+
pools,
137+
underlying: ADDRESS_0X0,
138+
};
97139
const marketCompressorAddress = this.sdk.addressProvider.getAddress(
98140
AP_MARKET_COMPRESSOR,
99141
3_10,
@@ -121,13 +163,7 @@ export class MarketRegister extends SDKConstruct {
121163
abi: iMarketCompressorAbi,
122164
address: marketCompressorAddress,
123165
functionName: "getMarkets",
124-
args: [
125-
{
126-
configurators,
127-
pools,
128-
underlying: ADDRESS_0X0,
129-
},
130-
],
166+
args: [this.#marketFilter],
131167
},
132168
],
133169
allowFailure: false,

0 commit comments

Comments
 (0)