diff --git a/README.md b/README.md index ee09cc9..3bb4243 100644 --- a/README.md +++ b/README.md @@ -19,41 +19,49 @@ npm install --save satoshi-sdk ### Example: Open trove ```typescript -import { parseUnits, parseEther } from 'viem'; -import { satoshiClient, getWalletClientByConfig, ProtocolConfigMap, DEBT_TOKEN_DECIMALS, wbtcABI, waitTxReceipt } from 'satoshi-sdk'; - -const account = privateKeyToAccount(process.env.PRIV as `0x${string}`); -const protocolConfig = ProtocolConfigMap.BEVM_MAINNET; -const walletClient = getWalletClientByConfig(protocolConfig, account); -const satoshiClient = new SatoshiClient(protocolConfig, walletClient); - -// Step 1: Parse the borrowing amount and collateral amount -const borrowingAmt = parseUnits('10', DEBT_TOKEN_DECIMALS); // Converts the string '10' into a BigNumber using the specified number of decimals -const totalCollAmt = parseEther('0.1'); // Converts the Ether string '0.1' to its Wei equivalent as a BigNumber - -// Step 2: Deposit collateral -const depositHash = await walletClient.writeContract({ - chain: protocolConfig.CHAIN, - account: walletClient.account, - address: collateral.ADDRESS, - abi: wbtcABI, - functionName: 'deposit', - args: [], - value: totalCollAmt, -}); -await waitTxReceipt({ publicClient }, depositHash); // Wait for the transaction to be confirmed - -// Step 3: Open a trove -const receipt = await satoshiClient.TroveManager.doOpenTrove({ - publicClient, - walletClient, - protocolConfig, - collateral, - borrowingAmt, - totalCollAmt, -}); - -console.log({ - receipt -}) +import { parseUnits, parseEther, defineChain, } from 'viem'; +import { privateKeyToAccount } from 'viem/accounts'; +import { SatoshiClient, getWalletClientByConfig, ProtocolConfigMap, DEBT_TOKEN_DECIMALS, wbtcABI, waitTxReceipt } from 'satoshi-sdk'; + +main() +async function main() { + const account = privateKeyToAccount(process.env.PRIV as `0x${string}`); + const walletClient = getWalletClientByConfig(protocolConfig, account); + + const protocolConfig = ProtocolConfigMap.BEVM_MAINNET; + const satoshiClient = new SatoshiClient(protocolConfig, walletClient); + const publicClient = satoshiClient.publicClient; + + // Step 1: Parse the borrowing amount and collateral amount + const borrowingAmt = parseUnits('10', DEBT_TOKEN_DECIMALS); // Converts the string '10' into a BigNumber using the specified number of decimals + const totalCollAmt = parseEther('0.1'); // Converts the Ether string '0.1' to its Wei equivalent as a BigNumber + + // Step 2: convert BEVM BTC to WBTC + const collateral = protocolConfig.COLLATERALS[0]; + const depositHash = await walletClient.writeContract({ + chain: protocolConfig.CHAIN, + account: walletClient.account, + address: collateral.ADDRESS, + abi: wbtcABI, + functionName: 'deposit', + args: [], + value: totalCollAmt, + }); + const wbtcReceipt = await waitTxReceipt({ publicClient, }, depositHash); // Wait for the transaction to be confirmed + console.log({ + wbtcReceipt, + }) + + // Step 3: Open a trove + const openTroveReceipt = await satoshiClient.TroveManager.doOpenTrove({ + collateral, + borrowingAmt, + totalCollAmt, + }); + + console.log({ + openTroveReceipt + }) +} + ``` \ No newline at end of file diff --git a/package.json b/package.json index a833aeb..3482f3e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "satoshi-sdk", - "version": "0.0.2", + "version": "0.0.4", "description": "Satoshi Protocol SDK", "main": "./lib/index.js", "files": [ - "lib/**/*" + "lib/**/*", + "README.md" ], "scripts": { "lint": "eslint ./src/ --fix",