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

feat: add plugin-bnb to support BNB chain #2278

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,9 @@ FUEL_WALLET_PRIVATE_KEY=
# Tokenizer Settings
TOKENIZER_MODEL= # Specify the tokenizer model to be used.
TOKENIZER_TYPE= # Options: tiktoken (for OpenAI models) or auto (AutoTokenizer from Hugging Face for non-OpenAI models). Default: tiktoken.

# BNB chain
BNB_PRIVATE_KEY= # BNB chain private key
BNB_PUBLIC_KEY= # BNB-smart-chain public key (address)
BSC_PROVIDER_URL= # BNB-smart-chain rpc url
OPBNB_PROVIDER_URL= # OPBNB rpc url
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ coverage
.eslintcache

agent/content

.idea/
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@elizaos/plugin-0g": "workspace:*",
"@elizaos/plugin-abstract": "workspace:*",
"@elizaos/plugin-aptos": "workspace:*",
"@elizaos/plugin-bnb": "workspace:*",
"@elizaos/plugin-bootstrap": "workspace:*",
"@elizaos/plugin-intiface": "workspace:*",
"@elizaos/plugin-coinbase": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import createGoatPlugin from "@elizaos/plugin-goat";
// import { intifacePlugin } from "@elizaos/plugin-intiface";
import { DirectClient } from "@elizaos/client-direct";
import { aptosPlugin } from "@elizaos/plugin-aptos";
import { bnbPlugin } from "@elizaos/plugin-bnb";
import {
advancedTradePlugin,
coinbaseCommercePlugin,
Expand Down Expand Up @@ -609,6 +610,11 @@ export async function createAgent(
getSecret(character, "ECHOCHAMBERS_API_KEY")
? echoChamberPlugin
: null,
getSecret(character, "BNB_PRIVATE_KEY") ||
(getSecret(character, "BNB_PUBLIC_KEY") &&
getSecret(character, "BNB_PUBLIC_KEY")?.startsWith("0x"))
? bnbPlugin
: null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down
141 changes: 141 additions & 0 deletions packages/plugin-bnb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# `@ai16z/plugin-bnb`

This plugin enables interaction with the BNB Chain ecosystem, providing support for BNB Smart Chain, opBNB, and BNB Greenfield networks.

---

## Configuration

### Default Setup

By default, **plugin-bnb** is not enabled. To use it, simply add your private key and public key to the `.env` file:

```env
BNB_PRIVATE_KEY=your-private-key-here
BNB_PUBLIC_KEY=your-public-key-here
```

### Custom RPC URLs

By default, the RPC URL is inferred from the `viem/chains` config. To use custom RPC URLs, add the following to your `.env` file:

```env
BSC_PROVIDER_URL=https://your-custom-bsc-rpc-url
OPBNB_PROVIDER_URL=https://your-custom-opbnb-rpc-url
```

## Provider

The **Wallet Provider** initializes with BSC as the default. It:

- Provides the **context** of the currently connected address and its balance.
- Creates **Public** and **Wallet clients** to interact with the supported chains.

---

## Actions

### Get Balance

Get the balance of an address on BSC. Just specify the:

- **Chain**
- **Address**
- **Token**

**Example usage:**

```bash
Get the USDC balance of 0x1234567890 on BSC.
```

### Transfer

Transfer tokens from one address to another on BSC/opBNB. Just specify the:

- **Chain**
- **Token**
- **Amount**
- **Recipient Address**
- **Data**(Optional)

**Example usage:**

```bash
Transfer 1 BNB to 0xRecipient on BSC.
```

### Swap

Swap tokens from one address to another on BSC. Just specify the:

- **Input Token**
- **Output Token**
- **Amount**
- **Chain**
- **Slippage**(Optional)

**Example usage:**

```bash
Swap 1 BNB to USDC on BSC.
```

### Bridge

Bridge tokens from one chain to another on BSC/opBNB. Just specify the:

- **From Chain**
- **To Chain**
- **From Token**
- **To Token**
- **Amount**
- **Recipient Address**(Optional)

**Example usage:**

```bash
Bridge 1 BNB from BSC to opBNB.
```

### Stake

Perform staking operations on BSC through [Lista Dao](https://lista.org/liquid-staking/BNB). User will receive sliBNB(0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B) as staking credit. Just specify the:

- **Action**
- **Amount**

**Example usage:**

```bash
Deposit 1 BNB to Lista Dao.
```

### Faucet

Request testnet tokens from the faucet. You could request any of the supported tokens(BNB, BTC, BUSD, DAI, ETH, USDC). Just specify the:

- **Token**(Optional)
- **Recipient Address**

The recipient address must maintain a minimum balance of 0.002 BNB on BSC Mainnet to qualify.

**Example usage:**

```bash
Get some testnet USDC from the faucet.
```

---

## Contribution

The plugin contains tests. Whether you're using **TDD** or not, please make sure to run the tests before submitting a PR.

### Running Tests

Navigate to the `plugin-bnb` directory and run:

```bash
pnpm test
```
29 changes: 29 additions & 0 deletions packages/plugin-bnb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@elizaos/plugin-bnb",
"version": "0.1.0-alpha.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@lifi/data-types": "5.15.5",
"@lifi/sdk": "3.4.1",
"@lifi/types": "16.3.0",
"@web3-name-sdk/core": "^0.3.2",
"@openzeppelin/contracts": "^5.1.0",
"@types/node": "^22.10.5",
"solc": "^0.8.28",
"tsup": "8.3.5",
"viem": "2.21.53",
"ws": "^8.18.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
Loading
Loading