Skip to content

v7.2.0

Latest

Choose a tag to compare

@on47sky on47sky released this 11 Oct 16:58
f66d641

@azuro-org/toolkit v7.2.0

The freebet bettor share, recorded payouts in the bets report, and extended conditions starting with 6

What's new

  • New calcFreebetBettorShare returns what a freebet pays the bettor, in token base units. The liquidity pool
    pays a freebet's whole payout to the freebet contract, which splits it between the bettor and the freebet fund:

    import { parseUnits } from 'viem'
    import { calcFreebetBettorShare } from '@azuro-org/toolkit'
    
    // a returnable freebet of 1 USDT won at 1.5: the pool pays 1.5, the bettor receives 0.5
    const share = calcFreebetBettorShare({
      payout: parseUnits('1.5', 6),
      amount: parseUnits('1', 6),
      isAmountReturnable: true,
    })
    • A payout no greater than the stake returns 0n; a lost freebet pays 0 and a canceled one exactly its stake.
    • A returnable freebet returns payout - amount.
    • Otherwise, when the flag is exactly false, it returns the whole payout.
    • A null or absent flag counts as returnable. That is the smaller share, so an app never shows more than the
      bettor receives.
    • It is plain bigint math, so nothing is rounded. The params type is CalcFreebetBettorShareParams.
  • The bets report reads recorded payouts (getBetsReport / calcBetsReport).

    • A won or lost bet returns the payout the bets subgraph recorded (rawPayout). That is already priced by the
      protocol's rule and is the amount actually paid once the bet is redeemed. A combo is no longer re-priced from its
      leg odds.
    • A leg is void when its selection's result is Canceled.
    • The freebet line values each freebet at the bettor's share. returns is the sum of the shares, and profit equals
      returns, because the bettor staked nothing of their own. A canceled freebet adds its stake to refunded and
      nothing to returns.
  • BetsReportEntry:

    • It gains isFreebetAmountReturnable?: boolean | null, which getBetsReport fills; absent means returnable.
    • createdAt and BetsReportSelection.odds are optional, deprecated and ignored.
    • isRedeemed is deprecated and ignored, and its type is unchanged.

    Entries built by older callers still type-check.

  • New isExtendedConditionId(conditionId) tells whether a condition is extended from the first digit of its id:
    5 or 6. An extended condition is named from the titles the API sends with it, never from
    @azuro-org/dictionaries. groupConditionsByMarket and getPredefinedCombo now use it, so a condition starting
    with 6 takes the extended path as one starting with 5 does.

    import { isExtendedConditionId } from '@azuro-org/toolkit'
    
    isExtendedConditionId('6001000000000000000000000000001') // true
    isExtendedConditionId('1001000000000000000000000000001') // false
  • calcComboOdds single-leg boundary. The new constant SINGLE_MARGIN_REMOVED_AT marks the moment a single-leg
    bet stopped carrying the combo pricing rule. A single-leg list created at or after it prices at that leg's quoted
    odds. Two or more legs keep the combo rule.

  • Deprecated, still exported and still working:

    • calcComboOdds and MARGIN_APPLIED_AT: read a bet's odds / settledOdds and potentialPayout / payout (or
      rawPotentialPayout / rawPayout) instead of re-pricing its legs on the client.
    • isSelectionCanceled: read selection.result === SelectionResult.Canceled.

    calcMinOdds, which prices new bets, is unchanged.

  • GraphQL fragments. Fields are only added; none is removed.

    • Bet: rawAmount, rawPotentialPayout, rawPayout and core.liquidityPool.tokenDecimals.
    • BetReport: isFreebetAmountReturnable.
    • Bettor:
      • affiliate;
      • canceledBetsCount and cashedOutBetsCount;
      • freebetBetsCount, freebetWonBetsCount, freebetLostBetsCount and freebetCanceledBetsCount;
      • rawFreebetTurnover, rawFreebetInBets, rawFreebetToPayout and rawFreebetTotalPayout.
    • The v3 bets of GameBets: isFreebet and isFreebetAmountReturnable.
  • SelectionResult now has Canceled next to Won and Lost. An exhaustive switch over it needs the new
    case.

Changed meaning

  • The report's freebet returns and profit are the bettor's share. Before, returns summed the pool's whole
    payout, and profit was returns - turnover.
  • Extended conditions may start with 6. Replace any conditionId[0] === '5' test with isExtendedConditionId.
    Otherwise a condition starting with 6 is looked up in @azuro-org/dictionaries, which does not have it.

Docs:
getBetsReport
calcComboOdds
isExtendedConditionId
release notes

Full Changelog: v7.1.0...v7.2.0