Skip to content

Commit

Permalink
feat: use the amount in bond account for each party instead of commit…
Browse files Browse the repository at this point in the history
…tmentAmount
  • Loading branch information
ciaran- committed Oct 25, 2023
1 parent 83120bc commit 6446faa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/hooks/use-market-liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const MarketLpDocument = gql`
triggeringRatio
}
}
networkParameter(key: "market.liquidity.stakeToCcyVolume") {
key
value
}
}
${LiquidityProvisionFieldsFragmentDoc}
`
Expand Down
30 changes: 24 additions & 6 deletions src/pages/liquidity-provision/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,13 @@ const MarketsLiquidity = () => {
const settlementAssetDecimals =
marketWithLiquidityData.market.tradableInstrument
.instrument.product.settlementAsset.decimals

const networkStakeToCcyVolume =
marketWithLiquidityData.networkParameter?.value || 1
const feeLevels = getFeeLevels(
marketWithLiquidityData.market
?.liquidityProvisionsConnection?.edges || []
?.liquidityProvisionsConnection?.edges || [],
networkStakeToCcyVolume
)

const tradingMode = params.data.node.data.marketTradingMode
Expand Down Expand Up @@ -673,28 +677,42 @@ const intentForProvisionedLiquidity = (
return Intent.Primary
}

export const getFeeLevels = (providers: any[]) => {
export const getFeeLevels = (
providers: any[],
networkStakeToCcyVolume: number
) => {
const parsedProviders = providers.map((p) => {
const node = p?.node || {}
return node
})
const lp = parsedProviders.reduce(
(total: { [x: string]: number }, current) => {
const { fee = '0', commitmentAmount = '0' } = current
const {
fee = '0',
commitmentAmount = '0',
party: {
accountsConnection: { edges },
},
} = current
const bondAccountBalance =
parseInt(edges[0]?.node?.balance, 10) * networkStakeToCcyVolume
const ca = parseInt(commitmentAmount, 10)

return {
...total,
[fee]: total[fee] ? total[fee] + ca : ca,
[fee]: total[fee]
? total[fee] + bondAccountBalance
: bondAccountBalance,
}
},
{}
)

const sortedProviders = Object.keys(lp)
.sort()
.map((p) => ({ fee: p, commitmentAmount: lp[p] }))

.map((p) => {
return { fee: p, commitmentAmount: lp[p] }
})
return sortedProviders
}

Expand Down

0 comments on commit 6446faa

Please sign in to comment.