UNPKG

@goat-sdk/plugin-modespray

Version:

<div align="center"> <a href="https://github.com/goat-sdk/goat">

2 lines (1 loc) 3.94 kB
import{a as w,b as _,c as u}from"./chunk-EI56VJPQ.mjs";import{b as k}from"./chunk-46NDQGZV.mjs";import{a as y}from"./chunk-LTREOOJZ.mjs";import{a as l}from"./chunk-YSXGDEY5.mjs";import{Tool as h}from"@goat-sdk/core";import{EVMWalletClient as c}from"@goat-sdk/wallet-evm";import{erc20Abi as I}from"viem";function m(d,o,s,e){var t=arguments.length,n=t<3?o:e===null?e=Object.getOwnPropertyDescriptor(o,s):e,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(d,o,s,e);else for(var i=d.length-1;i>=0;i--)(r=d[i])&&(n=(t<3?r(n):t>3?r(o,s,n):r(o,s))||n);return t>3&&n&&Object.defineProperty(o,s,n),n}l(m,"_ts_decorate");function a(d,o){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(d,o)}l(a,"_ts_metadata");var f=class{static{l(this,"ModeSprayService")}async sprayEther(o,s){let e=o.getChain();try{let{recipients:t,amounts:n}=s;if(!e?.id)throw new Error("Unable to determine chain ID from wallet client");let r=k(e.id),i=n.reduce((g,b)=>g+BigInt(b),BigInt(0)),{hash:p}=await o.sendTransaction({to:r.address,abi:r.abi,functionName:"disperseEther",args:[t,n],value:i});return{txHash:p,chainId:e.id,message:"You have sprayed ETH successfully"}}catch(t){return{chainId:e.id,message:t instanceof Error?t.message:JSON.stringify(t)}}}async sprayToken(o,s){let e=o.getChain();try{let{token:t,recipients:n,amounts:r}=s;if(!e?.id)throw new Error("Unable to determine chain ID from wallet client");let i=o.getAddress();if(!i)throw new Error("Could not get user address");let p=k(e.id),g=r.reduce((T,O)=>T+BigInt(O),BigInt(0)),b=await o.read({address:t,abi:I,functionName:"allowance",args:[i,p.address]}),S=BigInt(b.value),E=BigInt(g);return S<E&&await o.sendTransaction({to:t,abi:I,functionName:"approve",args:[p.address,E]}),{txHash:(await o.sendTransaction({to:p.address,abi:p.abi,functionName:"disperseToken",args:[t,n,r]})).hash,chainId:e.id,message:"You have sprayed the tokens successfully"}}catch(t){return{chainId:e.id,message:t instanceof Error?t.message:JSON.stringify(t)}}}async getSprayTokenInfoBySymbol(o,s){let e=o.getChain();if(!s.token)throw new Error("You should provide a token name");if(!e?.id)throw new Error("Unable to determine chain ID from wallet client");let t=s.token.toUpperCase(),n=y[t];if(!n){let r=Object.keys(y).join(", ");throw new Error(`Token "${s.token}" not found. Available tokens: ${r}`)}if(!n.chains[e.id]){let r=Object.keys(n.chains).join(", ");throw new Error(`Token "${s.token}" is not supported on chain ${e.id}. Supported chains: ${r}`)}return{decimals:n.decimals,symbol:n.symbol,name:n.name,chains:{[e.id]:n.chains[e.id]}}}async getSpraySupportedTokens(o,s){let e=o.getChain();if(e?.id){let t={};for(let[n,r]of Object.entries(y))r.chains[e.id]&&(t[n]=r);return t}return y}};m([h({name:"disperse_eth_to_multiple_addresses",description:"Spray or Disperse Ether to multiple recipients in a single transaction"}),a("design:type",Function),a("design:paramtypes",[typeof c>"u"?Object:c,typeof w>"u"?Object:w]),a("design:returntype",Promise)],f.prototype,"sprayEther",null);m([h({name:"disperse_erc20_token_to_multiple_addresses",description:"Spray or Disperse ERC-20 tokens to multiple recipients in a single transaction"}),a("design:type",Function),a("design:paramtypes",[typeof c>"u"?Object:c,typeof _>"u"?Object:_]),a("design:returntype",Promise)],f.prototype,"sprayToken",null);m([h({name:"get_spray_token_info_by_symbol",description:"Get Spray token info by symbol"}),a("design:type",Function),a("design:paramtypes",[typeof c>"u"?Object:c,typeof u>"u"?Object:u]),a("design:returntype",Promise)],f.prototype,"getSprayTokenInfoBySymbol",null);m([h({name:"get_spray_supported_tokens",description:"Get a list of all tokens supported by ModeSpray"}),a("design:type",Function),a("design:paramtypes",[typeof c>"u"?Object:c,typeof u>"u"?Object:u]),a("design:returntype",Promise)],f.prototype,"getSpraySupportedTokens",null);export{f as a};