Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built the Merchant moe Plugin for Interacting on Mantle #343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions typescript/packages/plugins/merchantmoe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# MerchantMoe Plugin

A GOAT SDK plugin for interacting with MerchantMoe protocol on Mode Network. This plugin provides a comprehensive interface for MOE token operations, staking, liquidity management, and token swaps.

## Features

### MOE Token Operations
- Check MOE token balances
- View veMOE balances
- Track token positions

### Staking Functionality
- Stake MOE tokens
- Unstake MOE tokens
- View staking positions
- Claim staking rewards
- Check earned rewards
- Complete staking exit (withdraw + claim)

### DEX Operations
- Swap tokens through MerchantMoe router
- Get token pair addresses
- View liquidity pairs
- Calculate swap amounts and rates
- Execute token swaps with slippage protection

## Installation

```bash
pnpm add @goat-sdk/plugin-merchantmoe
```

## Usage

### Basic Setup

```typescript
import { MerchantMoePlugin } from "@goat-sdk/plugin-merchantmoe";
import { getOnChainTools } from "@goat-sdk/adapter-vercel-ai";
import { viem } from "@goat-sdk/wallet-viem";

// Initialize the plugin
const merchantmoePlugin = new MerchantMoePlugin({
rpcUrl: "https://mainnet.mode.network",
});

// Set up tools with the plugin
const tools = await getOnChainTools({
wallet: viem(walletClient),
plugins: [merchantmoePlugin],
});
```

### Example Operations

#### Check MOE Balance
```typescript
// Get MOE token balance
const balance = await merchantmoe_get_moe_balance({
address: "0x..."
});
```

#### Stake MOE Tokens
```typescript
// Stake 100 MOE tokens
const stakeResult = await merchantmoe_stake_moe({
amount: "100"
});
```

#### Swap Tokens
```typescript
// Swap USDC for MOE
const swapResult = await merchantmoe_swap_tokens({
amountIn: "10000000", // 10 USDC (6 decimals)
amountOutMin: "9000000", // Minimum MOE to receive
path: [USDC_ADDRESS, MOE_TOKEN_ADDRESS],
to: "0x...",
deadline: 300 // 5 minutes
});
```

## Contract Addresses

The plugin interacts with the following Mode Network contracts:

- MOE Token: `0x4515A45337F461A11Ff0FE8aBF3c606AE5dC00c9`
- MOE Staking: `0xE92249760e1443FbBeA45B03f607Ba84471Fa793`
- MOE Router: `0xeaEE7EE68874218c3558b40063c42B82D3E7232a`
- MOE Factory: `0x5bef015ca9424a7c07b68490616a4c1f094bedec`
- veMOE: `0x240616e2448e078934863fB6eb5133834BF14Ef1`

## Supported Networks

- Mode Network (Chain ID: 5000)

## API Reference

### Token Operations
- `getMoeBalance(address)`: Get MOE token balance
- `getVeMoeBalance(address)`: Get veMOE balance

### Staking Operations
- `stakeMoe(amount)`: Stake MOE tokens
- `unstakeMoe(amount)`: Unstake MOE tokens
- `getEarnedMoe(address)`: Get earned rewards
- `claimRewards()`: Claim staking rewards
- `exitStaking()`: Exit staking position

### DEX Operations
- `getAmountsOut(amountIn, path)`: Calculate output amounts
- `swapExactTokensForTokens(params)`: Execute token swap
- `getPair(tokenA, tokenB)`: Get liquidity pair address
- `getAllPairsLength()`: Get total number of pairs
- `getPairAtIndex(index)`: Get pair by index

## Error Handling

The plugin includes comprehensive error handling for:
- Invalid addresses
- Insufficient balances
- Failed transactions
- Network issues
- Contract interactions

## Security

- All contract interactions require explicit wallet approval
- Slippage protection for swaps
- Transaction deadline enforcement
- Safe type handling for addresses and amounts

## Dependencies

- `@goat-sdk/core`
- `@goat-sdk/wallet-evm`
- `viem`
- `zod`

## Contributing

Contributions are welcome! Please check our contributing guidelines for details.

## License

MIT License - see LICENSE file for details.

## Links

- [Mode Network](https://mode.network)
- [MerchantMoe Documentation](https://docs.merchantmoe.com)
- [GOAT SDK](https://docs.ohmygoat.dev)
34 changes: 34 additions & 0 deletions typescript/packages/plugins/merchantmoe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@goat-sdk/plugin-merchantmoe",
"version": "0.1.10",
"files": ["dist/**/*", "README.md", "package.json"],
"scripts": {
"build": "tsup",
"clean": "rm -rf dist",
"test": "vitest run --passWithNoTests"
},
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@goat-sdk/core": "workspace:*",
"@goat-sdk/wallet-evm": "workspace:*",
"viem": "catalog:",
"zod": "catalog:"
},
"peerDependencies": {
"@goat-sdk/core": "workspace:*",
"viem": "catalog:"
},
"homepage": "https://ohmygoat.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/goat-sdk/goat.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/goat-sdk/goat/issues"
},
"keywords": ["ai", "agents", "web3"]
}
68 changes: 68 additions & 0 deletions typescript/packages/plugins/merchantmoe/src/abi/erc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export const erc20ABI = [
{
inputs: [{ name: "owner", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ name: "spender", type: "address" },
{ name: "amount", type: "uint256" },
],
name: "approve",
outputs: [{ name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "decimals",
outputs: [{ name: "", type: "uint8" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "symbol",
outputs: [{ name: "", type: "string" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "name",
outputs: [{ name: "", type: "string" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "totalSupply",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ name: "recipient", type: "address" },
{ name: "amount", type: "uint256" },
],
name: "transfer",
outputs: [{ name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ name: "sender", type: "address" },
{ name: "recipient", type: "address" },
{ name: "amount", type: "uint256" },
],
name: "transferFrom",
outputs: [{ name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
] as const;
50 changes: 50 additions & 0 deletions typescript/packages/plugins/merchantmoe/src/abi/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export const factoryABI = [
{
inputs: [
{ name: "tokenA", type: "address" },
{ name: "tokenB", type: "address" },
],
name: "getPair",
outputs: [{ name: "pair", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ name: "tokenA", type: "address" },
{ name: "tokenB", type: "address" },
],
name: "createPair",
outputs: [{ name: "pair", type: "address" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "allPairsLength",
outputs: [{ name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [{ name: "", type: "uint256" }],
name: "allPairs",
outputs: [{ name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "feeTo",
outputs: [{ name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "feeToSetter",
outputs: [{ name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
] as const;
4 changes: 4 additions & 0 deletions typescript/packages/plugins/merchantmoe/src/abi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { erc20ABI } from "./erc20";
export { routerABI } from "./router";
export { factoryABI } from "./factory";
export { stakingABI } from "./staking";
63 changes: 63 additions & 0 deletions typescript/packages/plugins/merchantmoe/src/abi/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export const routerABI = [
{
inputs: [
{ name: "amountIn", type: "uint256" },
{ name: "path", type: "address[]" },
],
name: "getAmountsOut",
outputs: [{ name: "amounts", type: "uint256[]" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ name: "amountIn", type: "uint256" },
{ name: "amountOutMin", type: "uint256" },
{ name: "path", type: "address[]" },
{ name: "to", type: "address" },
{ name: "deadline", type: "uint256" },
],
name: "swapExactTokensForTokens",
outputs: [{ name: "amounts", type: "uint256[]" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ name: "amountOut", type: "uint256" },
{ name: "amountInMax", type: "uint256" },
{ name: "path", type: "address[]" },
{ name: "to", type: "address" },
{ name: "deadline", type: "uint256" },
],
name: "swapTokensForExactTokens",
outputs: [{ name: "amounts", type: "uint256[]" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ name: "amountIn", type: "uint256" },
{ name: "amountOutMin", type: "uint256" },
{ name: "path", type: "address[]" },
{ name: "to", type: "address" },
{ name: "deadline", type: "uint256" },
],
name: "swapExactTokensForETH",
outputs: [{ name: "amounts", type: "uint256[]" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ name: "amountOut", type: "uint256" },
{ name: "path", type: "address[]" },
{ name: "to", type: "address" },
{ name: "deadline", type: "uint256" },
],
name: "swapExactETHForTokens",
outputs: [{ name: "amounts", type: "uint256[]" }],
stateMutability: "payable",
type: "function",
},
] as const;
Loading
Loading