-
Notifications
You must be signed in to change notification settings - Fork 10
/
borrow_asset.ts
35 lines (29 loc) · 973 Bytes
/
borrow_asset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as BIP39 from "bip39";
import { CarbonSDK } from "./_sdk";
import { BigNumber } from "bignumber.js";
import "./_setup";
(async () => {
const mnemonics = process.env.MNEMONICS ?? BIP39.generateMnemonic();
console.log("mnemonics", mnemonics);
const sdk = await CarbonSDK.instance({
network: CarbonSDK.Network.LocalHost,
config: {
tmRpcUrl: process.env.TRPC_ENDPOINT,
},
});
const connectedSDK = await sdk.connectWithMnemonic(mnemonics);
console.log("connected sdk");
const ethToken = sdk.token.tokenForDenom("eth");
if (!ethToken) return;
const amount = new BigNumber(0.01).shiftedBy(ethToken.decimals.toNumber());
await connectedSDK.cdp.supplyAssetAndLockCollateral({
denom: "eth",
supplyAmount: amount,
lockAmount: amount,
});
const result = await connectedSDK.cdp.borrowAsset({
denom: "eth",
amount: amount,
});
console.log(result);
})().catch(console.error).finally(() => process.exit(0));