Skip to content

Commit

Permalink
update: README
Browse files Browse the repository at this point in the history
  • Loading branch information
imfeng committed Jul 5, 2024
1 parent c1a1aa4 commit 86244f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
82 changes: 45 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 86244f9

Please sign in to comment.