@goat-sdk/plugin-betswirl
Version:
<div align="center"> <a href="https://github.com/goat-sdk/goat">
2 lines (1 loc) • 4.32 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});var _chunkEI7MMDWYjs = require('./chunk-EI7MMDWY.js');var _sdkcore = require('@betswirl/sdk-core');var _viem = require('viem');async function I(r,n){let o=r.getChain().id,a=_sdkcore.casinoChainById[o],t;if(n&&n!==a.viemChain.nativeCurrency.symbol){let s=await A(r);if(t=s.find(i=>i.symbol===n),!t)throw new Error(`The token must be one of ${s.map(i=>i.symbol).join(", ")}`)}else t=_sdkcore.chainNativeCurrencyToToken.call(void 0, a.viemChain.nativeCurrency);return t}_chunkEI7MMDWYjs.a.call(void 0, I,"getBetToken");function R(r,n){let o=_viem.parseUnits.call(void 0, r,n.decimals);if(o<=0n)throw new Error("The bet amount must be greater than 0");return o}_chunkEI7MMDWYjs.a.call(void 0, R,"getBetAmountInWei");async function C(r,n,o,a){let t=r.getChain().id;try{let s=_sdkcore.getBetRequirementsFunctionData.call(void 0, o.address,a,t),{value:i}=await r.read({address:s.data.to,functionName:s.data.functionName,abi:s.data.abi,args:s.data.args});return _sdkcore.parseRawBetRequirements.call(void 0, i,o,a,n,t)}catch(s){throw new Error(`An error occured while getting the bet requirements: ${s}`)}}_chunkEI7MMDWYjs.a.call(void 0, C,"getBetRequirements");async function x(r,n,o,a,t){let s=r.getChain().id;try{let i=new URLSearchParams({game:n.toString(),tokenAddress:o,betCount:a.toString(),chainId:s.toString()}),e=await fetch(`https://api.betswirl.com/api/vrfFees?${i}`,{});if(!e.ok)throw new Error(`An error occured while fetching the chainlink vrf cost from API: ${e.statusText}`);return BigInt(await e.json())}catch(i){throw new Error(`An error occured while getting the chainlink vrf cost: ${i}`)}}_chunkEI7MMDWYjs.a.call(void 0, x,"getChainlinkVrfCost");async function D(r,n,o,a,t){let s=r.getChain().id,i=await C(r,n,t.betToken,a);if(!i.isAllowed)throw new Error("The token isn't allowed for betting");if(t.betAmount>i.maxBetAmount)throw new Error(`Bet amount should be less than ${i.maxBetAmount}`);if(t.betCount>i.maxBetCount)throw new Error(`Bet count should be less than ${i.maxBetCount}`);let e=_sdkcore.getPlaceBetFunctionData.call(void 0, {betAmount:t.betAmount,game:n,gameEncodedInput:o,receiver:t.receiver,betCount:t.betCount,tokenAddress:t.betToken.address,stopGain:t.stopGain,stopLoss:t.stopLoss},s);try{let u=await x(r,n,t.betToken.address,t.betCount,0n)*120n/100n,{hash:w}=await r.sendTransaction({to:e.data.to,functionName:e.data.functionName,args:e.data.args,value:e.extraData.getValue(u),abi:e.data.abi});return w}catch(u){throw new Error(`An error occured while placing the bet: ${u}`)}}_chunkEI7MMDWYjs.a.call(void 0, D,"placeBet");async function N(r,n,o){let a=r.getChain().id;try{let t=await _sdkcore.fetchBetByHash.call(void 0, n,{chainId:a,theGraphKey:o,formatType:_sdkcore.FORMAT_TYPE.PRECISE}),s=Date.now(),i=6e4;for(;(!t.bet||!t.bet.isResolved)&&!t.error;){if(Date.now()-s>=i)throw new Error("Timeout: Bet data retrieval exceeded 1 minute.");if(await new Promise(u=>setTimeout(u,1e3)),t=await _sdkcore.fetchBetByHash.call(void 0, n,{chainId:a,theGraphKey:o}),t.error)break}if(t.error)throw new Error(`[${t.error.code}] Error fetching bet: ${t.error.message}`);if(!t.bet)throw new Error(`The bet hasn't been indexed in time, please retry later: ${n}`);let e=t.bet;return{id:String(e.id),input:e.decodedInput,betTxnHash:e.betTxnHash,betTxnLink:_sdkcore.formatTxnUrl.call(void 0, e.betTxnHash,a),betAmount:e.formattedBetAmount,token:e.token.symbol,isWin:e.isWin,payoutMultiplier:e.payoutMultiplier,rolled:e.decodedRolled,payout:e.formattedPayout,rollTxnHash:e.rollTxnHash,rollTxnLink:e.rollTxnHash?_sdkcore.formatTxnUrl.call(void 0, e.rollTxnHash,a):null,linkOnBetSwirl:`https://www.betswirl.com/${_sdkcore.slugById[a]}/casino/${e.game}/${e.id}`}}catch(t){throw new Error(`An error occured while getting the bet: ${t}`)}}_chunkEI7MMDWYjs.a.call(void 0, N,"getBet");async function A(r){let n=r.getChain().id,o=_sdkcore.getCasinoTokensFunctionData.call(void 0, n),{value:a}=await r.read({address:o.data.to,functionName:o.data.functionName,abi:o.data.abi});return a.filter(t=>t.token.allowed&&!t.token.paused).map(t=>({..._sdkcore.rawTokenToToken.call(void 0, t,n),decimals:Number(t.decimals)}))}_chunkEI7MMDWYjs.a.call(void 0, A,"getCasinoTokens");exports.a = I; exports.b = R; exports.c = D; exports.d = N; exports.e = A;