8
8
*/
9
9
10
10
import { HttpClient , HttpClientResponse } from "@effect/platform"
11
+ import { EU_STAKING_HUB } from "@unionlabs/sdk/Constants"
11
12
import { Array , BigDecimal , Data , Effect , pipe , Schema } from "effect"
12
13
13
14
const REST_BASE_URL = "https://rest.union.build"
14
15
15
- // Staker address that delegates to validators on behalf of liquid stakers
16
- const LIQUID_STAKING_STAKER_ADDRESS =
17
- "union19ydrfy0d80vgpvs6p0cljlahgxwrkz54ps8455q7jfdfape7ld7quaq69v"
18
-
19
16
export class IncentiveError extends Data . TaggedError ( "IncentiveError" ) < {
20
17
message : string
21
18
cause ?: unknown
@@ -76,6 +73,23 @@ const DelegatorDelegationsResponse = Schema.Struct({
76
73
} ) ) ,
77
74
} )
78
75
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
+
79
93
export const IncentiveResult = Schema . Struct ( {
80
94
rates : Schema . Struct ( {
81
95
yearly : Schema . BigDecimalFromSelf ,
@@ -180,6 +194,26 @@ const getValidators = pipe(
180
194
) ,
181
195
)
182
196
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
+
183
217
const getDelegatorDelegations = ( delegatorAddress : string ) =>
184
218
pipe (
185
219
HttpClient . HttpClient ,
@@ -203,6 +237,10 @@ export const calculateIncentive: Effect.Effect<
203
237
IncentiveError ,
204
238
HttpClient . HttpClient
205
239
> = 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
+
206
244
const [
207
245
inflationData ,
208
246
stakingPoolData ,
@@ -217,7 +255,7 @@ export const calculateIncentive: Effect.Effect<
217
255
getDistributionParams ,
218
256
getCirculatingSupply ,
219
257
getValidators ,
220
- getDelegatorDelegations ( LIQUID_STAKING_STAKER_ADDRESS ) ,
258
+ getDelegatorDelegations ( stakerAddress ) ,
221
259
] , { concurrency : "unbounded" } )
222
260
223
261
const inflation = inflationData . inflation
0 commit comments