Skip to content

Commit 2d0c7db

Browse files
committed
chore(app): fmt
1 parent 9d14a08 commit 2d0c7db

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

app2/src/lib/services/incentive.ts

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { Array, BigDecimal, Data, Effect, pipe, Schema } from "effect"
1313
const REST_BASE_URL = "https://rest.union.build"
1414

1515
// Staker address that delegates to validators on behalf of liquid stakers
16-
const LIQUID_STAKING_STAKER_ADDRESS = "union19ydrfy0d80vgpvs6p0cljlahgxwrkz54ps8455q7jfdfape7ld7quaq69v"
16+
const LIQUID_STAKING_STAKER_ADDRESS =
17+
"union19ydrfy0d80vgpvs6p0cljlahgxwrkz54ps8455q7jfdfape7ld7quaq69v"
1718

1819
export class IncentiveError extends Data.TaggedError("IncentiveError")<{
1920
message: string
@@ -179,29 +180,37 @@ const getValidators = pipe(
179180
),
180181
)
181182

182-
const getDelegatorDelegations = (delegatorAddress: string) => pipe(
183-
HttpClient.HttpClient,
184-
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
185-
Effect.andThen((client) =>
186-
pipe(
187-
client.get(`${REST_BASE_URL}/cosmos/staking/v1beta1/delegations/${delegatorAddress}`),
188-
Effect.flatMap(HttpClientResponse.schemaBodyJson(DelegatorDelegationsResponse)),
189-
Effect.mapError((cause) =>
190-
new IncentiveError({
191-
message: "Failed to fetch delegator delegations",
192-
cause,
193-
})
194-
),
195-
)
196-
),
197-
)
183+
const getDelegatorDelegations = (delegatorAddress: string) =>
184+
pipe(
185+
HttpClient.HttpClient,
186+
Effect.map(HttpClient.withTracerDisabledWhen(() => true)),
187+
Effect.andThen((client) =>
188+
pipe(
189+
client.get(`${REST_BASE_URL}/cosmos/staking/v1beta1/delegations/${delegatorAddress}`),
190+
Effect.flatMap(HttpClientResponse.schemaBodyJson(DelegatorDelegationsResponse)),
191+
Effect.mapError((cause) =>
192+
new IncentiveError({
193+
message: "Failed to fetch delegator delegations",
194+
cause,
195+
})
196+
),
197+
)
198+
),
199+
)
198200

199201
export const calculateIncentive: Effect.Effect<
200202
IncentiveResult,
201203
IncentiveError,
202204
HttpClient.HttpClient
203205
> = Effect.gen(function*() {
204-
const [inflationData, stakingPoolData, distributionData, circulatingSupplyData, validatorsData, delegationsData] = yield* Effect
206+
const [
207+
inflationData,
208+
stakingPoolData,
209+
distributionData,
210+
circulatingSupplyData,
211+
validatorsData,
212+
delegationsData,
213+
] = yield* Effect
205214
.all([
206215
getInflation,
207216
getStakingPool,
@@ -263,7 +272,7 @@ export const calculateIncentive: Effect.Effect<
263272

264273
// Calculate weighted average validator commission
265274
const validatorMap = new Map(validatorsData.validators.map(v => [v.operator_address, v]))
266-
275+
267276
const validDelegations = pipe(
268277
delegationsData.delegation_responses,
269278
Array.filter(delegation => {
@@ -272,8 +281,9 @@ export const calculateIncentive: Effect.Effect<
272281
}),
273282
Array.map(delegation => ({
274283
amount: delegation.balance.amount,
275-
commission: validatorMap.get(delegation.delegation.validator_address)!.commission.commission_rates.rate
276-
}))
284+
commission:
285+
validatorMap.get(delegation.delegation.validator_address)!.commission.commission_rates.rate,
286+
})),
277287
)
278288

279289
const { totalAmount, weightedSum } = pipe(
@@ -282,22 +292,25 @@ export const calculateIncentive: Effect.Effect<
282292
{ totalAmount: BigDecimal.fromBigInt(0n), weightedSum: BigDecimal.fromBigInt(0n) },
283293
(acc, { amount, commission }) => ({
284294
totalAmount: BigDecimal.sum(acc.totalAmount, amount),
285-
weightedSum: BigDecimal.sum(acc.weightedSum, BigDecimal.multiply(amount, commission))
286-
})
287-
)
295+
weightedSum: BigDecimal.sum(acc.weightedSum, BigDecimal.multiply(amount, commission)),
296+
}),
297+
),
288298
)
289299

290300
const weightedAverageCommission = BigDecimal.isZero(totalAmount)
291301
? BigDecimal.fromBigInt(0n)
292302
: yield* BigDecimal.divide(weightedSum, totalAmount).pipe(
293-
Effect.mapError(() =>
294-
new IncentiveError({
295-
message: "Could not calculate weighted average commission",
296-
})
297-
),
298-
)
303+
Effect.mapError(() =>
304+
new IncentiveError({
305+
message: "Could not calculate weighted average commission",
306+
})
307+
),
308+
)
299309

300-
const validatorCommissionAmount = BigDecimal.multiply(incentiveAfterTax, weightedAverageCommission)
310+
const validatorCommissionAmount = BigDecimal.multiply(
311+
incentiveAfterTax,
312+
weightedAverageCommission,
313+
)
301314
const incentiveAfterCommission = BigDecimal.subtract(incentiveAfterTax, validatorCommissionAmount)
302315

303316
const bondedRatio = yield* BigDecimal.divide(bondedTokens, totalSupply).pipe(

0 commit comments

Comments
 (0)