Skip to content

Commit b0fb5ae

Browse files
committed
fix(app): use constant and get address dynamically from config
1 parent 2d0c7db commit b0fb5ae

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

app2/src/lib/services/incentive.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
*/
99

1010
import { HttpClient, HttpClientResponse } from "@effect/platform"
11+
import { EU_STAKING_HUB } from "@unionlabs/sdk/Constants"
1112
import { Array, BigDecimal, Data, Effect, pipe, Schema } from "effect"
1213

1314
const REST_BASE_URL = "https://rest.union.build"
1415

15-
// Staker address that delegates to validators on behalf of liquid stakers
16-
const LIQUID_STAKING_STAKER_ADDRESS =
17-
"union19ydrfy0d80vgpvs6p0cljlahgxwrkz54ps8455q7jfdfape7ld7quaq69v"
18-
1916
export class IncentiveError extends Data.TaggedError("IncentiveError")<{
2017
message: string
2118
cause?: unknown
@@ -76,6 +73,23 @@ const DelegatorDelegationsResponse = Schema.Struct({
7673
})),
7774
})
7875

76+
const LstConfigResponse = Schema.Struct({
77+
data: Schema.Struct({
78+
staker_address: Schema.String,
79+
native_token_denom: Schema.String,
80+
minimum_liquid_stake_amount: Schema.String,
81+
protocol_fee_config: Schema.Struct({
82+
fee_rate: Schema.String,
83+
fee_recipient: Schema.String,
84+
}),
85+
monitors: Schema.Array(Schema.String),
86+
lst_address: Schema.String,
87+
batch_period_seconds: Schema.Number,
88+
unbonding_period_seconds: Schema.Number,
89+
stopped: Schema.Boolean,
90+
}),
91+
})
92+
7993
export const IncentiveResult = Schema.Struct({
8094
rates: Schema.Struct({
8195
yearly: Schema.BigDecimalFromSelf,
@@ -180,6 +194,26 @@ const getValidators = pipe(
180194
),
181195
)
182196

197+
const getLstConfig = pipe(
198+
HttpClient.HttpClient,
199+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
200+
Effect.andThen((client) => {
201+
const queryMsg = btoa(JSON.stringify({ config: {} }))
202+
return pipe(
203+
client.get(
204+
`${REST_BASE_URL}/cosmwasm/wasm/v1/contract/${EU_STAKING_HUB.address}/smart/${queryMsg}`,
205+
),
206+
Effect.flatMap(HttpClientResponse.schemaBodyJson(LstConfigResponse)),
207+
Effect.mapError((cause) =>
208+
new IncentiveError({
209+
message: "Failed to fetch LST contract config",
210+
cause,
211+
})
212+
),
213+
)
214+
}),
215+
)
216+
183217
const getDelegatorDelegations = (delegatorAddress: string) =>
184218
pipe(
185219
HttpClient.HttpClient,
@@ -203,6 +237,10 @@ export const calculateIncentive: Effect.Effect<
203237
IncentiveError,
204238
HttpClient.HttpClient
205239
> = Effect.gen(function*() {
240+
// First get the LST config to find the staker address
241+
const lstConfig = yield* getLstConfig
242+
const stakerAddress = lstConfig.data.staker_address
243+
206244
const [
207245
inflationData,
208246
stakingPoolData,
@@ -217,7 +255,7 @@ export const calculateIncentive: Effect.Effect<
217255
getDistributionParams,
218256
getCirculatingSupply,
219257
getValidators,
220-
getDelegatorDelegations(LIQUID_STAKING_STAKER_ADDRESS),
258+
getDelegatorDelegations(stakerAddress),
221259
], { concurrency: "unbounded" })
222260

223261
const inflation = inflationData.inflation

0 commit comments

Comments
 (0)