@badger-dao/ebtc-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

eBTC logo

eBTC SDK

Documentation   •   Application   •   Discord   •   Twitter

Installation

To start using eBTC SDK run the following command:

yarn add @ebtc/sdk

Getting Started

Utilizing the SDK requires an RPC provider:

import eBTC from '@badger-dao/ebtc-sdk';

const sdk = new eBTC({
  provider: 'https://eth-archival.gateway.pokt.network/v1/lb/<APP_ID>',
});

const sdk = new eBTC({
  provider: uiBasedInjectedProvider,
});

// wagmi example workaround

const provider = useProvider();
const { data: signer, isError, isLoading } = useSigner();

useEffect(() => {
  if (!isLoading && !isError && signer) {
    const sdk = new eBTC({
      provider: provider as Web3Provider,
    });
  }
}, [signer]);

Example to open a CDP

/**
 * @param options Open transaction parameters
 * Note: value override must be provided to supply collateral for initial open
 * @returns Transaction status of submitted open operation
 */

await ebtc.cdp.openWithHelper({
  collateralAmount: 30, // stETH
  borrowAmount: 2, //eBTC
  maxFeePercentage: ethers.constants.WeiPerEther.div('1000').mul('5'),
  overrides: {
    gasLimit: 1000000,
  },
  onSubmitted: () => console.log('Submitted open position'),
  onSuccess: ({ transaction }) => {
    console.log('Opened CDP successfully');
  },
  onError: (e) => {
    console.error(e);
  },
  onRejection: () => console.log('User canceled the transaction'),
});

Example to run any GraphQL Query

const query = `
    query cdpUpdateds($_cdpId: String!) {
      cdpCreateds(where: { _cdpId: $_cdpId }, orderBy: blockNumber) {
        id
        _cdpId
        blockTimestamp
        blockNumber
      }
    }
  `;

const variables = {
  _cdpId: '0x31c57298578f7508b5982062cfec5ec8bd34624700f64c130000000000000000',
};

const res = await ebtc?.graph.graphClient?.request(query, variables);

Example to call multiple contract for multicall

Making multiple calls using Promise.all

// All three requests are aggregated into a single RPC call
const [gasCompensation, minimumCollateralRatio, minimumDebt] = await Promise.all([
  ebtc.cdp.borrowerOperations.EBTC_GAS_COMPENSATION(),
  ebtc.cdp.getMinimumCollateralRatio(),
  ebtc.cdp.borrowerOperations.MIN_NET_DEBT(),
]);

Methods can also be aggregated without using Promise.all, as long as there are no await in between calls.

const gasCompensationPromise = ebtc.cdp.borrowerOperations.EBTC_GAS_COMPENSATION();
const minimumCollateralRatioPromise = ebtc.cdp.getMinimumCollateralRatio();
const minimumDebtPromise = ebtc.cdp.borrowerOperations.MIN_NET_DEBT();

const gasCompensation = await gasCompensationPromise;
const minimumCollateralRatio = await minimumCollateralRatioPromise;
const minimumDebt = minimumDebtPromise;

Development

To get started, install the following dependencies:

  • Node
  • Yarn

Run the following command:

yarn install --frozen-lockfile
yarn test

Contributing

This repository only accepts verified commits. Commits can be signed using GPG keys. For more info, proceed to Managing Commit Signature Verification.

Package Sidebar

Install

npm i @badger-dao/ebtc-sdk

Weekly Downloads

26

Version

1.4.0

License

GPL-3.0-or-later

Unpacked Size

1.48 MB

Total Files

354

Last publish

Collaborators

  • badgerdao_dapp
  • badgerdao_mrbasado