defmodule Polymarket.Schemas.ClobReward do @moduledoc """ A CLOB liquidity-reward configuration attached to a `Polymarket.Schemas.Market`. Returned (as `clobRewards`) by the single-event Gamma endpoints (`GET /events/:id`, `/events/slug/:slug`); the keyset endpoint omits it. """ use TypedEctoSchema alias Polymarket.JsonUtil alias Polymarket.Schemas.Coerce @primary_key false @derive Jason.Encoder typed_embedded_schema do field(:id, :string) field(:condition_id, :string) field(:asset_address, :string) field(:rewards_amount, :float) field(:rewards_daily_rate, :float) field(:start_date, :date) field(:end_date, :date) end @doc "Builds a `ClobReward` from a decoded (JSON) map, coercing each field." @spec from_attrs(map()) :: {:ok, t()} def from_attrs(attrs) do attrs = JsonUtil.snake_case_keys(attrs) {:ok, %__MODULE__{ id: attrs["id"], condition_id: attrs["condition_id"], asset_address: attrs["asset_address"], rewards_amount: Coerce.to_float(attrs["rewards_amount"]), rewards_daily_rate: Coerce.to_float(attrs["rewards_daily_rate"]), start_date: Coerce.to_date(attrs["start_date"]), end_date: Coerce.to_date(attrs["end_date"]) }} end end