import {
encodeDeposit,
readVaultInfo,
CHAIN_IDS,
} from "@sherwoodagent/sdk";
import { createPublicClient, createWalletClient, defineChain, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
// Robinhood Chain mainnet (chain 4663) is Sherwood's deployment.
const robinhoodChain = defineChain({
id: CHAIN_IDS.ROBINHOOD, // 4663
name: "Robinhood Chain",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: { default: { http: [process.env.ROBINHOOD_RPC_URL ?? "https://rpc.mainnet.chain.robinhood.com"] } },
});
const publicClient = createPublicClient({
chain: robinhoodChain,
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_000n, // 1 USDG (6 decimals)
}, CHAIN_IDS.ROBINHOOD);
// 3. Sign + broadcast each tx in order
const wallet = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
chain: robinhoodChain,
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 });
}