|
| 1 | +import { type SignTypedDataParameters, type Address, type TypedDataDomain } from 'viem' |
| 2 | + |
| 3 | +import { |
| 4 | + type ChainId, |
| 5 | + chainsData, |
| 6 | + liveSupportedChains, |
| 7 | + LIVE_BET_DATA_TYPES, |
| 8 | + LIVE_TYPED_DATA_DOMAIN_NAME, |
| 9 | + LIVE_TYPED_DATA_DOMAIN_VERSION, |
| 10 | +} from '../config' |
| 11 | +import { type LiveBet } from '../global' |
| 12 | + |
| 13 | + |
| 14 | +type Props = { |
| 15 | + chainId: ChainId |
| 16 | + account: Address |
| 17 | + bet: LiveBet |
| 18 | +} |
| 19 | + |
| 20 | +export const getLiveBetTypedData = ({ account, chainId, bet }: Props): SignTypedDataParameters => { |
| 21 | + if (!liveSupportedChains.includes(chainId)) { |
| 22 | + throw new Error('provided chainId is not supported for live bet') |
| 23 | + } |
| 24 | + |
| 25 | + const { contracts } = chainsData[chainId] |
| 26 | + |
| 27 | + const EIP712Domain: TypedDataDomain = { |
| 28 | + name: LIVE_TYPED_DATA_DOMAIN_NAME, |
| 29 | + version: LIVE_TYPED_DATA_DOMAIN_VERSION, |
| 30 | + chainId, |
| 31 | + verifyingContract: contracts.liveCore!.address, |
| 32 | + } |
| 33 | + |
| 34 | + return { |
| 35 | + account: account, |
| 36 | + domain: EIP712Domain, |
| 37 | + primaryType: 'ClientBetData', |
| 38 | + types: LIVE_BET_DATA_TYPES, |
| 39 | + message: { |
| 40 | + attention: bet.attention, |
| 41 | + affiliate: bet.affiliate, |
| 42 | + core: bet.core, |
| 43 | + amount: BigInt(bet.amount), |
| 44 | + nonce: BigInt(bet.nonce), |
| 45 | + conditionId: BigInt(bet.conditionId), |
| 46 | + outcomeId: BigInt(bet.outcomeId), |
| 47 | + minOdds: BigInt(bet.minOdds), |
| 48 | + expiresAt: BigInt(bet.expiresAt), |
| 49 | + chainId: BigInt(bet.chainId), |
| 50 | + relayerFeeAmount: BigInt(bet.relayerFeeAmount), |
| 51 | + }, |
| 52 | + } |
| 53 | +} |
0 commit comments