@goat-sdk/plugin-betswirl
Version:
<div align="center"> <a href="https://github.com/goat-sdk/goat">
2 lines (1 loc) • 1.46 kB
JavaScript
import{a}from"./chunk-2EYWWA44.mjs";import{a as s}from"./chunk-YSXGDEY5.mjs";import{createTool as m}from"@goat-sdk/core";import{z as l}from"zod";import{CASINO_GAME_TYPE as d,FORMAT_TYPE as p,fetchBets as u,formatTxnUrl as c,slugById as f}from"@betswirl/sdk-core";function B(r,n){return m({name:"betswirl_getBets",description:"Get bets from BetSwirl. If no player is specified its listing the current connected player bets. If no game is specified its listing all games bets.",parameters:l.object({bettor:a.optional().describe("The bettor address"),game:l.nativeEnum(d).optional().describe("The game to get the bets for")})},async o=>{let i=o.bettor,t=o.game,e=r.getChain().id;return await g(e,i,t,n)})}s(B,"createGetBetsTool");async function g(r,n,o,i){try{let t=await u({chainId:r,theGraphKey:i,formatType:p.PRECISE},{bettor:n,game:o},void 0,5);if(t.error)throw new Error(`[${t.error.code}] Error fetching bets: ${t.error.message}`);return t.bets.map(e=>({id:String(e.id),input:e.decodedInput,betTxnHash:e.betTxnHash,betTxnLink:c(e.betTxnHash,r),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?c(e.rollTxnHash,r):null,linkOnBetSwirl:`https://www.betswirl.com/${f[r]}/casino/${e.game}/${e.id}`}))}catch(t){throw new Error(`An error occured while getting the bet: ${t}`)}}s(g,"getSubgraphBets");export{B as a};