UNPKG

@goat-sdk/plugin-modespray

Version:

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

2 lines (1 loc) 5.4 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkBGNMOTZGjs = require('./chunk-BGNMOTZG.js');var _chunk7JFOMUF7js = require('./chunk-7JFOMUF7.js');var _chunk4QHH652Jjs = require('./chunk-4QHH652J.js');var _chunkEI7MMDWYjs = require('./chunk-EI7MMDWY.js');var _core = require('@goat-sdk/core');var _walletevm = require('@goat-sdk/wallet-evm');var _viem = require('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}_chunkEI7MMDWYjs.a.call(void 0, m,"_ts_decorate");function a(d,o){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(d,o)}_chunkEI7MMDWYjs.a.call(void 0, a,"_ts_metadata");var f=class{static{_chunkEI7MMDWYjs.a.call(void 0, this,"ModeSprayService")}async sprayEther(o,s){let e=o.getChain();try{let{recipients:t,amounts:n}=s;if(!_optionalChain([e, 'optionalAccess', _2 => _2.id]))throw new Error("Unable to determine chain ID from wallet client");let r=_chunk7JFOMUF7js.b.call(void 0, 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(!_optionalChain([e, 'optionalAccess', _3 => _3.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=_chunk7JFOMUF7js.b.call(void 0, e.id),g=r.reduce((T,O)=>T+BigInt(O),BigInt(0)),b=await o.read({address:t,abi:_viem.erc20Abi,functionName:"allowance",args:[i,p.address]}),S=BigInt(b.value),E=BigInt(g);return S<E&&await o.sendTransaction({to:t,abi:_viem.erc20Abi,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(!_optionalChain([e, 'optionalAccess', _4 => _4.id]))throw new Error("Unable to determine chain ID from wallet client");let t=s.token.toUpperCase(),n=_chunk4QHH652Jjs.a[t];if(!n){let r=Object.keys(_chunk4QHH652Jjs.a).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(_optionalChain([e, 'optionalAccess', _5 => _5.id])){let t={};for(let[n,r]of Object.entries(_chunk4QHH652Jjs.a))r.chains[e.id]&&(t[n]=r);return t}return _chunk4QHH652Jjs.a}};m([_core.Tool.call(void 0, {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 _walletevm.EVMWalletClient>"u"?Object:_walletevm.EVMWalletClient,typeof _chunkBGNMOTZGjs.a>"u"?Object:_chunkBGNMOTZGjs.a]),a("design:returntype",Promise)],f.prototype,"sprayEther",null);m([_core.Tool.call(void 0, {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 _walletevm.EVMWalletClient>"u"?Object:_walletevm.EVMWalletClient,typeof _chunkBGNMOTZGjs.b>"u"?Object:_chunkBGNMOTZGjs.b]),a("design:returntype",Promise)],f.prototype,"sprayToken",null);m([_core.Tool.call(void 0, {name:"get_spray_token_info_by_symbol",description:"Get Spray token info by symbol"}),a("design:type",Function),a("design:paramtypes",[typeof _walletevm.EVMWalletClient>"u"?Object:_walletevm.EVMWalletClient,typeof _chunkBGNMOTZGjs.c>"u"?Object:_chunkBGNMOTZGjs.c]),a("design:returntype",Promise)],f.prototype,"getSprayTokenInfoBySymbol",null);m([_core.Tool.call(void 0, {name:"get_spray_supported_tokens",description:"Get a list of all tokens supported by ModeSpray"}),a("design:type",Function),a("design:paramtypes",[typeof _walletevm.EVMWalletClient>"u"?Object:_walletevm.EVMWalletClient,typeof _chunkBGNMOTZGjs.c>"u"?Object:_chunkBGNMOTZGjs.c]),a("design:returntype",Promise)],f.prototype,"getSpraySupportedTokens",null);exports.a = f;