# Skill: NeuroLink Agentic Terminal (`neurolink-agentic`)

A specialized skill for Autonomous AI Agents, LLMs, and the **Binance Agentic Wallet (`baw`)** to interact with the NeuroLink Cybernetic NFT and Neural Mining ecosystem on **BNB Smart Chain (BSC)**.

---

## 1. Network & Contract Directory

| Role | BSC Testnet (Chain ID `97` / `0x61`) | BNB Chain Mainnet (Chain ID `56` / `0x38`) |
|---|---|---|
| **RPC Endpoint** | `https://data-seed-prebsc-1-s1.binance.org:8545` | `https://bsc-dataseed.binance.org` |
| **NeuroLink NFT (`link`)** | `0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1` | (TBD upon mainnet deploy) |
| **NeuroLinkMining (`mining`)** | `0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271` | (TBD upon mainnet deploy) |
| **NeuroToken (`$NEURO`)** | `0xa5A7071042dB51fCE6c0811492308646fa72Fd1b` | (TBD upon mainnet deploy) |
| **NeuroLinkMarket (`market`)** | `0x11882b69EE44714c0B992349444BBC9C4a9DD99a` | (TBD upon mainnet deploy) |
| **Agent ID Registry** | `0xaF3bB3B4BF4aeb5aFF56680E8D3F6f13e8916d10` (Testnet Mock) | `0x60B9262456dE011F7d15a54CdD8c48bAaa8B022F` (SPACE ID) |
| **Chainlink BNB/USD Oracle** | `0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526` | `0x0567F2323251f0Aab15c8dFb1967E4e8A7D42aeE` |

---

## 2. Execution Modes

### Mode A: Binance Agentic Wallet (`baw` CLI)
Used when executing via the official Binance Agentic Wallet environment:
1. Preview the call:
   ```bash
   baw contract-call preview --binanceChainId <56|97> --from <AGENT_WALLET> --to <CONTRACT_ADDR> --value <WEI> --inputData <CALLDATA> --json
   ```
2. Inspect the returned JSON, verify `success: true` and note the `requestId`.
3. Confirm with user and execute:
   ```bash
   baw contract-call execute --requestId <REQUEST_ID> --json
   ```

### Mode B: Foundry `cast` / Direct RPC
Used by automated terminal agents with direct wallet access:
```bash
cast send <CONTRACT_ADDR> "<SIGNATURE>" <ARGS...> --value <WEI> --private-key <KEY> --rpc-url <RPC>
```

---

## 3. Function Signatures & Selectors Reference

| Function Signature | Selector | Description |
|---|---|---|
| `hasAgentId(address)` | `0x4eab3ef2` | View: Check if wallet holds an Agent ID (required for free mint) |
| `weightNow()` | `0x0a954472` | View: Current PoW difficulty bits (24..42) |
| `targetNow()` | `0x09a9efa7` | View: Current 256-bit target integer |
| `mint(uint256)` | `0xa0712d68` | Action: Free PoW mint with pre-computed nonce |
| `paidPriceWei()` | `0x48c64ab2` | View: Exact BNB cost in wei for $1.00 USD |
| `mintPaid()` | `0x69907b9b` | Action: Fast paid mint ($1.00 in BNB, payable) |
| `setApprovalForAll(address,bool)` | `0xa2201960` | Action: Approve Mining or Market contract |
| `stake(uint256)` | `0xa694fc3a` | Action: Stake single NeuroLink NFT |
| `stakeBatch(uint256[])` | `0x230f436d` | Action: Stake multiple NeuroLink NFTs |
| `claimPassive(uint256)` | `0x0ec2dcbe` | Action: Claim pending $NEURO rewards for token |
| `claimPassiveAll()` | `0x0f76aa39` | Action: Claim all pending $NEURO rewards for wallet |
| `unstake(uint256)` | `0x2e17de78` | Action: Claim rewards and unstake NFT back to wallet |
| `unstakeBatch(uint256[])` | `0xe64a21f3` | Action: Batch unstake NFTs |
| `activeMine(uint256,uint256)` | `0x9ccc5ac7` | Action: Overclock NFT & burst mine (token, nonce) |
| `floorWei()` | `0xbc63914a` | View: Market floor price protection in wei ($1.00 USD) |
| `list(uint256,uint256)` | `0x50fd7367` | Action: List token on market (tokenId, priceWei) |
| `buy(uint256)` | `0xd96a094a` | Action: Purchase listed token (payable) |
| `cancel(uint256)` | `0x40e58ee5` | Action: Cancel listing and return token to seller |
| `makeOffer(uint256)` | `0x9a2f6474` | Action: Escrow offer on any token (payable) |
| `acceptOffer(uint256)` | `0xc815729d` | Action: Seller accepts escrowed offer |
| `withdrawOffer(uint256)` | `0x8610f045` | Action: Buyer cancels and withdraws escrowed offer |

---

## 4. Operation Playbooks

### Workflow 1: Free PoW Mint (Agent ID Required)

1. **Pre-flight Check**: Check if the wallet holds an Agent ID:
   ```bash
   cast call 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "hasAgentId(address)(bool)" <AGENT_WALLET> --rpc-url <RPC>
   ```
   *If `false`, free mint will revert. Use Paid Mint instead.*

2. **Read Current PoW Target / Weight**:
   ```bash
   cast call 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "weightNow()(uint256)" --rpc-url <RPC>
   ```

3. **Mine Nonce**:
   Run the included multi-threaded solver script:
   ```bash
   node tools/pow.js search <AGENT_WALLET> <WEIGHT_BITS> [THREADS]
   ```
   Example output:
   ```json
   { "status": "SOLVED", "nonce": "184920491820491", "hash": "0x000000abc..." }
   ```

4. **Execute Mint**:
   - **Calldata**:
     Use `cast calldata "mint(uint256)" <NONCE>`
   - **Binance Agentic Wallet (`baw`)**:
     ```bash
     baw contract-call preview --binanceChainId 97 --from <AGENT_WALLET> --to 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 --value 0 --inputData 0xa0712d68<HEX_32BYTE_NONCE> --json
     baw contract-call execute --requestId <REQUEST_ID> --json
     ```
   - **Foundry `cast`**:
     ```bash
     cast send 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "mint(uint256)" <NONCE> --private-key <KEY> --rpc-url <RPC>
     ```

---

### Workflow 2: Fast Paid Mint ($1.00 USD in BNB)

*No Agent ID required. Publicly available.*

1. **Query Exact Price in Wei**:
   ```bash
   cast call 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "paidPriceWei()(uint256)" --rpc-url <RPC>
   ```
   *Example: `1432023236072152` wei (~0.00143 BNB)*

2. **Execute Mint with Exact or Slightly Higher Value** (excess BNB is auto-refunded):
   - **Binance Agentic Wallet (`baw`)**:
     ```bash
     baw contract-call preview --binanceChainId 97 --from <AGENT_WALLET> --to 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 --value <PRICE_WEI> --inputData 0x69907b9b --json
     baw contract-call execute --requestId <REQUEST_ID> --json
     ```
   - **Foundry `cast`**:
     ```bash
     cast send 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "mintPaid()" --value <PRICE_WEI> --private-key <KEY> --rpc-url <RPC>
     ```

---

### Workflow 3: Mining Rig Operations ($NEURO Staking & Yield)

#### Step 3.1: Approve Mining Contract (One-time)
Before staking for the first time, approve `NeuroLinkMining` (`0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271`):
```bash
# Calldata: setApprovalForAll(0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271, true)
cast calldata "setApprovalForAll(address,bool)" 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 true
# Selector: 0xa2201960
```
With `baw`:
```bash
baw contract-call preview --binanceChainId 97 --from <AGENT_WALLET> --to 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 --value 0 --inputData 0xa220196000000000000000000000000011882b69ee44714c0b992349444bbc9c4a9dd99a0000000000000000000000000000000000000000000000000000000000000001 --json
```

#### Step 3.2: Stake NFT(s)
- **Single NFT**:
  ```bash
  cast send 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 "stake(uint256)" <TOKEN_ID> --private-key <KEY> --rpc-url <RPC>
  ```
- **Batch Stake**:
  ```bash
  cast send 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 "stakeBatch(uint256[])" "[<ID1>,<ID2>]" --private-key <KEY> --rpc-url <RPC>
  ```

#### Step 3.3: Claim Yield Rewards ($NEURO)
- **Claim All Available**:
  ```bash
  # Calldata for claimPassiveAll(): 0x0f76aa39
  baw contract-call preview --binanceChainId 97 --from <AGENT_WALLET> --to 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 --value 0 --inputData 0x0f76aa39 --json
  baw contract-call execute --requestId <REQUEST_ID> --json
  ```

#### Step 3.4: Active Mining (Overclock 2x Burst)
Overclocks the NFT for 1 hour (+100% hash power) and yields an instant $NEURO token payout.
- Condition: Solve PoW for `keccak256("neurolink.active.mining.v1" ++ msg.sender ++ tokenId ++ nonce) <= target(24 bits)`.
- Find Nonce:
  ```bash
  node tools/pow.js active <AGENT_WALLET> <TOKEN_ID>
  ```
- Execute:
  ```bash
  cast send 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 "activeMine(uint256,uint256)" <TOKEN_ID> <NONCE> --private-key <KEY> --rpc-url <RPC>
  ```

#### Step 3.5: Unstake NFT(s)
Unstakes NFT back to agent wallet and automatically claims all remaining yield:
```bash
cast send 0x3C1CE79F38b41Df5a71AA5c6FA59cABc93dd2271 "unstake(uint256)" <TOKEN_ID> --private-key <KEY> --rpc-url <RPC>
```

---

### Workflow 4: Marketplace Operations

*Features Anti-Dump Floor Protection ($1.00 USD). Listings below floor are burnt on-chain.*

#### Step 4.1: Approve Marketplace (One-time)
Approve `NeuroLinkMarket` (`0x11882b69EE44714c0B992349444BBC9C4a9DD99a`):
```bash
# Call on NeuroLink NFT (0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1)
# Calldata: setApprovalForAll(0x11882b69EE44714c0B992349444BBC9C4a9DD99a, true)
cast send 0x3fEE525FC6Fb47e04d1823b33598B9c4c65682B1 "setApprovalForAll(address,bool)" 0x11882b69EE44714c0B992349444BBC9C4a9DD99a true --private-key <KEY> --rpc-url <RPC>
```

#### Step 4.2: Check Floor Price Protection
```bash
cast call 0x11882b69EE44714c0B992349444BBC9C4a9DD99a "floorWei()(uint256)" --rpc-url <RPC>
```
*Always ensure listing price >= `floorWei` to prevent floor burn.*

#### Step 4.3: List NFT for Sale
```bash
cast send 0x11882b69EE44714c0B992349444BBC9C4a9DD99a "list(uint256,uint256)" <TOKEN_ID> <PRICE_IN_WEI> --private-key <KEY> --rpc-url <RPC>
```

#### Step 4.4: Buy Listed NFT
```bash
cast send 0x11882b69EE44714c0B992349444BBC9C4a9DD99a "buy(uint256)" <TOKEN_ID> --value <PRICE_IN_WEI> --private-key <KEY> --rpc-url <RPC>
```

#### Step 4.5: Cancel Listing
```bash
cast send 0x11882b69EE44714c0B992349444BBC9C4a9DD99a "cancel(uint256)" <TOKEN_ID> --private-key <KEY> --rpc-url <RPC>
```

#### Step 4.6: Escrow Offers
- Make offer: `makeOffer(uint256 tokenId)` with `--value <OFFER_WEI>`
- Accept offer (seller): `acceptOffer(uint256 tokenId)`
- Withdraw offer (buyer): `withdrawOffer(uint256 tokenId)`

---

## 5. Automation Script Helper (`tools/agent-exec.js`)

A turnkey Node.js helper is available to format and broadcast actions with zero boilerplate:

```bash
# Check wallet eligibility & balances
node tools/agent-exec.js status <WALLET_ADDRESS>

# Mine and execute free mint in a single command
node tools/agent-exec.js free-mint --private-key <KEY>

# Execute paid mint
node tools/agent-exec.js paid-mint --private-key <KEY>

# Stake all idle wallet NFTs
node tools/agent-exec.js stake-all --private-key <KEY>

# Claim all mining rewards
node tools/agent-exec.js claim-all --private-key <KEY>
```

---

## 6. Common Revert Reasons & Diagnostics

| Revert Error | Meaning | Agent Action |
|---|---|---|
| `NoAgentId()` | Wallet does not hold an Agent ID. | Use Paid Lane (`mintPaid`) or acquire an Agent ID first. |
| `BadProof(uint256)` | Hash did not meet difficulty target. | Ladder likely stepped up. Re-read `weightNow()` and mine again. |
| `WalletLimit()` | Free lane limit reached (1 per wallet). | Use Paid Lane (`mintPaid()`) for up to 20 additional pieces. |
| `Underpaid(needed, sent)` | BNB sent was lower than `paidPriceWei()`. | Fetch fresh `paidPriceWei()` and re-submit. |
| `BelowFloor(minPrice, sent)` | Listing or offer is below the $1.00 USD floor. | Read `floorWei()` and set price above floor. |
| `LockedOnMarket()` | Token is currently listed on marketplace. | Call `market.cancel(tokenId)` before staking or mining. |
| `CannotStakeWhileOverclocked()` | Active mining overclock is still active. | Wait for overclock countdown to expire before unstaking. |
| `OverclockCooldown()` | Active burst mine is on 1-hour cooldown. | Wait for 3,600s cooldown period to end. |
