Skip to content

LeoYeAI/agent-master-skills / skills/aurehub-xaut-trade

xaut-trade

Flagged

Buy or sell XAUT (Tether Gold) on Ethereum. Supports market orders (Uniswap V3) and limit orders (UniswapX). Wallet modes: Foundry keystore or WDK. Delegates non-XAUT intents to registered skills (e.g. Polymarket prediction markets, Hyperliquid trading). Triggers: buy XAUT, XAUT trade, swap USDT for XAUT, sell XAUT, swap XAUT for USDT, limit order, limit buy XAUT, limit sell XAUT, check limit order, cancel limit order, XAUT when, create wallet, setup wallet, polymarket, prediction market, bet on, odds on, hyperliquid, perp, perpetual, long, short, open long, open short, close position, leverage.

FileKindSize
README.mdmarkdown15.0 KB
SKILL.mdskill md29.2 KB
SKILL.tests.yamlconfig12.1 KB
_meta.jsonconfig991 B
config.example.yamlconfig1.7 KB
references/balance.mdmarkdown2.6 KB
references/buy.mdmarkdown3.8 KB
references/limit-order-buy-place.mdmarkdown4.6 KB
references/limit-order-cancel.mdmarkdown2.2 KB
references/limit-order-sell-place.mdmarkdown4.8 KB
references/limit-order-status.mdmarkdown1.6 KB
references/live-trading-runbook.mdmarkdown3.9 KB
references/onboarding.mdmarkdown12.9 KB
references/quote.mdmarkdown2.0 KB
references/sell.mdmarkdown5.9 KB
references/skill-delegation.mdmarkdown2.8 KB
references/wallet-modes.mdmarkdown1.3 KB
scripts/__tests__/helpers.test.jsscript2.7 KB
scripts/__tests__/integration.test.jsscript1.2 KB
scripts/__tests__/swap-cli.test.jsscript3.7 KB
scripts/__tests__/wallet-init.test.jsscript10.7 KB
scripts/helpers.jsscript1.2 KB
scripts/lib/__tests__/config.test.jsscript2.9 KB
scripts/lib/__tests__/create-wallet.test.jsscript6.1 KB
scripts/lib/__tests__/erc20.test.jsscript3.3 KB
scripts/lib/__tests__/provider.test.jsscript7.6 KB
scripts/lib/__tests__/signer.test.jsscript7.6 KB
scripts/lib/__tests__/uniswap.test.jsscript3.6 KB
scripts/lib/config.jsscript4.3 KB
scripts/lib/create-wallet.jsscript5.7 KB
scripts/lib/erc20.jsscript3.8 KB
scripts/lib/export-seed.jsscript6.5 KB
scripts/lib/provider.jsscript8.3 KB
scripts/lib/signer.jsscript6.8 KB
scripts/lib/uniswap.jsscript5.3 KB
scripts/limit-order.jsscript13.6 KB
scripts/package-lock.jsonmanifest182.2 KB
scripts/package.jsonmanifest703 B
scripts/setup.shscript29.5 KB
scripts/swap.jsscript15.7 KB

scripts/lib/erc20.js

View on GitHub
import { Interface, formatUnits, parseUnits } from 'ethers6';

const ERC20_ABI = [
  'function balanceOf(address) view returns (uint256)',
  'function allowance(address,address) view returns (uint256)',
  'function approve(address,uint256) returns (bool)',
];

const iface = new Interface(ERC20_ABI);

/**
 * Get the token balance of an address.
 *
 * @param {{ address: string, decimals: number }} token
 * @param {string} address
 * @param {object} provider  ethers provider (or compatible mock with .call())
 * @returns {Promise<string>}  Human-readable balance formatted with token decimals
 */
export async function getBalance(token, address, provider) {
  const data = iface.encodeFunctionData('balanceOf', [address]);
  const raw = await provider.call({ to: token.address, data });
  const [value] = iface.decodeFunctionResult('balanceOf', raw);
  return formatUnits(value, token.decimals);
}

/**
 * Get the ERC-20 allowance granted by owner to spender.
 *
 * @param {{ address: string, decimals: number }} token
 * @param {string} owner
 * @param {string} spender
 * @param {object} provider
 * @returns {Promise<string>}  Human-readable allowance formatted with token decimals
 */
export async function getAllowance(token, owner, spender, provider) {
  const data = iface.encodeFunctionData('allowance', [owner, spender]);
  const raw = await provider.call({ to: token.address, data });
  const [value] = iface.decodeFunctionResult('allowance', raw);
  return formatUnits(value, token.decimals);
}

/**
 * Approve a spender to transfer tokens on behalf of the signer.
 *
 * For tokens like USDT that revert when changing a non-zero allowance directly,
 * pass `opts.requiresResetApprove = true` to first reset to 0 before setting the
 * new value.
 *
 * @param {{ address: string, decimals: number }} token
 * @param {string} spender
 * @param {string} amount  Human-readable amount (e.g. "1000")
 * @param {object} signer  ethers signer (or compatible mock)
 * @param {{ requiresResetApprove?: boolean, fallbackProvider?: object }} opts
 * @returns {Promise<{ hash: string }>}
 */
export async function approve(token, spender, amount, signer, opts = {}) {
  const rawAmount = parseUnits(amount, token.decimals);
  const timeoutMs = (opts.timeoutSeconds ?? 300) * 1000;
  const waitForReceipt = async (sentTx) => {
    // Use fallbackProvider.waitForTransaction when available for RPC resilience
    if (opts.fallbackProvider?.waitForTransaction) {
      return Promise.race([
        opts.fallbackProvider.waitForTransaction(sentTx.hash, 1, timeoutMs),
        new Promise((_, reject) =>
          setTimeout(() => reject(new Error(
            `Approve tx not confirmed within ${timeoutMs / 1000}s (txHash: ${sentTx.hash}). It may still be pending.`
          )), timeoutMs)
        ),
      ]);
    }
    return Promise.race([
      sentTx.wait(),
      new Promise((_, reject) =>
        setTimeout(() => reject(new Error(
          `Approve tx not confirmed within ${timeoutMs / 1000}s (txHash: ${sentTx.hash}). It may still be pending.`
        )), timeoutMs)
      ),
    ]);
  };

  if (opts.requiresResetApprove) {
    const resetData = iface.encodeFunctionData('approve', [spender, 0n]);
    const resetTx = await signer.sendTransaction({ to: token.address, data: resetData });
    const resetReceipt = await waitForReceipt(resetTx);
    if (!resetReceipt || resetReceipt.status !== 1) {
      throw new Error(`Allowance reset failed (txHash: ${resetTx.hash}). Approval not sent.`);
    }
  }

  const data = iface.encodeFunctionData('approve', [spender, rawAmount]);
  const tx = await signer.sendTransaction({ to: token.address, data });
  const receipt = await waitForReceipt(tx);
  if (!receipt || receipt.status !== 1) {
    throw new Error(`Approval failed (txHash: ${tx.hash}). Check token contract and allowance.`);
  }

  return { hash: tx.hash };
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall