Skip to content

Commit fcb40f2

Browse files
feat: init plugin-bsc (#2)
1 parent f8b9e3e commit fcb40f2

25 files changed

+5743
-1
lines changed

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ STARGAZE_ENDPOINT=
495495
# GenLayer
496496
GENLAYER_PRIVATE_KEY= # Private key of the GenLayer account to use for the agent in this format (0x0000000000000000000000000000000000000000000000000000000000000000)
497497

498+
# BNB chain
499+
BNB_PRIVATE_KEY= # BNB chain private key
500+
BNB_PUBLIC_KEY= # BNB-smart-chain public key (address)
501+
BSC_PROVIDER_URL= # BNB-smart-chain rpc url
502+
OPBNB_PROVIDER_URL= # OPBNB rpc url
503+
498504
####################################
499505
#### Misc Plugin Configurations ####
500506
####################################

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ agent/content
6060

6161
eliza.manifest
6262
eliza.manifest.sgx
63-
eliza.sig
63+
eliza.sig

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@elizaos/plugin-coinmarketcap": "workspace:*",
4242
"@elizaos/plugin-binance": "workspace:*",
4343
"@elizaos/plugin-avail": "workspace:*",
44+
"@elizaos/plugin-bnb": "workspace:*",
4445
"@elizaos/plugin-bootstrap": "workspace:*",
4546
"@elizaos/plugin-cosmos": "workspace:*",
4647
"@elizaos/plugin-intiface": "workspace:*",

agent/src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { avalanchePlugin } from "@elizaos/plugin-avalanche";
5353
import { b2Plugin } from "@elizaos/plugin-b2";
5454
import { binancePlugin } from "@elizaos/plugin-binance";
5555
import { birdeyePlugin } from "@elizaos/plugin-birdeye";
56+
import { bnbPlugin } from "@elizaos/plugin-bnb";
5657
import {
5758
advancedTradePlugin,
5859
coinbaseCommercePlugin,
@@ -940,6 +941,11 @@ export async function createAgent(
940941
getSecret(character, "RESERVOIR_API_KEY")
941942
? createNFTCollectionsPlugin()
942943
: null,
944+
getSecret(character, "BNB_PRIVATE_KEY") ||
945+
(getSecret(character, "BNB_PUBLIC_KEY") &&
946+
getSecret(character, "BNB_PUBLIC_KEY")?.startsWith("0x"))
947+
? bnbPlugin
948+
: null,
943949
].filter(Boolean),
944950
providers: [],
945951
actions: [],

packages/plugin-bnb/README.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# `@ai16z/plugin-bnb`
2+
3+
This plugin enables interaction with the BNB Chain ecosystem, providing support for BNB Smart Chain, opBNB, and BNB Greenfield networks.
4+
5+
---
6+
7+
## Configuration
8+
9+
### Default Setup
10+
11+
By default, **plugin-bnb** is not enabled. To use it, simply add your private key and public key to the `.env` file:
12+
13+
```env
14+
BNB_PRIVATE_KEY=your-private-key-here
15+
BNB_PUBLIC_KEY=your-public-key-here
16+
```
17+
18+
### Custom RPC URLs
19+
20+
By default, the RPC URL is inferred from the `viem/chains` config. To use custom RPC URLs, add the following to your `.env` file:
21+
22+
```env
23+
BSC_PROVIDER_URL=https://your-custom-bsc-rpc-url
24+
OPBNB_PROVIDER_URL=https://your-custom-opbnb-rpc-url
25+
```
26+
27+
## Provider
28+
29+
The **Wallet Provider** initializes with BSC as the default. It:
30+
31+
- Provides the **context** of the currently connected address and its balance.
32+
- Creates **Public** and **Wallet clients** to interact with the supported chains.
33+
34+
---
35+
36+
## Actions
37+
38+
### Get Balance
39+
40+
Get the balance of an address on BSC. Just specify the:
41+
42+
- **Chain**
43+
- **Address**
44+
- **Token**
45+
46+
**Example usage:**
47+
48+
```bash
49+
Get the USDC balance of 0x1234567890 on BSC.
50+
```
51+
52+
### Transfer
53+
54+
Transfer tokens from one address to another on BSC/opBNB. Just specify the:
55+
56+
- **Chain**
57+
- **Token**
58+
- **Amount**
59+
- **Recipient Address**
60+
- **Data**(Optional)
61+
62+
**Example usage:**
63+
64+
```bash
65+
Transfer 1 BNB to 0xRecipient on BSC.
66+
```
67+
68+
### Swap
69+
70+
Swap tokens from one address to another on BSC. Just specify the:
71+
72+
- **Input Token**
73+
- **Output Token**
74+
- **Amount**
75+
- **Chain**
76+
- **Slippage**(Optional)
77+
78+
**Example usage:**
79+
80+
```bash
81+
Swap 1 BNB to USDC on BSC.
82+
```
83+
84+
### Bridge
85+
86+
Bridge tokens from one chain to another on BSC/opBNB. Just specify the:
87+
88+
- **From Chain**
89+
- **To Chain**
90+
- **From Token**
91+
- **To Token**
92+
- **Amount**
93+
- **Recipient Address**(Optional)
94+
95+
**Example usage:**
96+
97+
```bash
98+
Bridge 1 BNB from BSC to opBNB.
99+
```
100+
101+
### Stake
102+
103+
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:
104+
105+
- **Action**
106+
- **Amount**
107+
108+
**Example usage:**
109+
110+
```bash
111+
Deposit 1 BNB to Lista Dao.
112+
```
113+
114+
### Faucet
115+
116+
Request testnet tokens from the faucet. You could request any of the supported tokens(BNB, BTC, BUSD, DAI, ETH, USDC). Just specify the:
117+
118+
- **Token**(Optional)
119+
- **Recipient Address**
120+
121+
The recipient address must maintain a minimum balance of 0.002 BNB on BSC Mainnet to qualify.
122+
123+
**Example usage:**
124+
125+
```bash
126+
Get some testnet USDC from the faucet.
127+
```
128+
129+
---
130+
131+
## Contribution
132+
133+
The plugin contains tests. Whether you're using **TDD** or not, please make sure to run the tests before submitting a PR.
134+
135+
### Running Tests
136+
137+
Navigate to the `plugin-bnb` directory and run:
138+
139+
```bash
140+
pnpm test
141+
```

packages/plugin-bnb/package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@elizaos/plugin-bnb",
3+
"version": "0.1.0-alpha.1",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@elizaos/core": "workspace:*",
9+
"@lifi/data-types": "5.15.5",
10+
"@lifi/sdk": "3.4.1",
11+
"@lifi/types": "16.3.0",
12+
"@web3-name-sdk/core": "^0.3.2",
13+
"@openzeppelin/contracts": "^5.1.0",
14+
"@types/node": "^22.10.5",
15+
"solc": "^0.8.28",
16+
"tsup": "8.3.5",
17+
"viem": "2.21.53",
18+
"ws": "^8.18.0"
19+
},
20+
"scripts": {
21+
"build": "tsup --format esm --dts",
22+
"dev": "tsup --format esm --dts --watch",
23+
"test": "vitest run",
24+
"lint": "eslint --fix --cache ."
25+
},
26+
"peerDependencies": {
27+
"whatwg-url": "7.1.0"
28+
}
29+
}

0 commit comments

Comments
 (0)