import {
encodeDeposit,
readVaultInfo,
CHAIN_IDS,
} from "@sherwoodagent/sdk";
import { createPublicClient, createWalletClient, defineChain, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
// Robinhood testnet (chain 46630) is Sherwood's current deployment target.
const robinhoodTestnet = defineChain({
id: CHAIN_IDS.ROBINHOOD_L2, // 46630
name: "Robinhood Testnet",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: { default: { http: [process.env.ROBINHOOD_RPC_URL!] } },
});
const publicClient = createPublicClient({
chain: robinhoodTestnet,
transport: http(process.env.ROBINHOOD_RPC_URL),
});
// 1. Read the vault
const info = await readVaultInfo(publicClient, "0xVaultAddress");
// 2. Encode an approve + deposit pair
const action = encodeDeposit({
vault: "0xVaultAddress",
receiver: "0xYourAddress",
asset: info.asset,
assetSymbol: info.assetSymbol,
assetDecimals: info.assetDecimals,
assets: 1_000_000_000_000_000_000n, // 1 WETH (18 decimals)
}, CHAIN_IDS.ROBINHOOD_L2);
// 3. Sign + broadcast each tx in order
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
chain: robinhoodTestnet,
transport: http(process.env.ROBINHOOD_RPC_URL),
});
for (const tx of action.txs) {
const hash = await wallet.sendTransaction({
to: tx.to,
data: tx.data,
value: BigInt(tx.value),
});
await publicClient.waitForTransactionReceipt({ hash });
}