npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

joy-dao

v0.0.7

Published

Nervos DAO transaction builder

Downloads

162

Readme

CKB DAO Transaction Builder

This package provides a set of functions to build Nervos DAO transactions that are compatible with joyID lock and omni-lock. It includes functions for depositing, withdrawing, and unlocking DAO cells.

Installation

To install this package, run the following command in your terminal:

npm install joy-dao

Usage

Creating a config file

Before using the package, you currently need to add a config.ts file to where joy-dao package is imported (commonly it is src/ folder), with the following default content:

export const ISMAINNET = false;

export const NODE_URL = ISMAINNET
  ? "https://mainnet.ckb.dev/"
  : "https://testnet.ckb.dev/";
export const INDEXER_URL = ISMAINNET
  ? "https://mainnet.ckb.dev/indexer"
  : "https://testnet.ckb.dev/indexer";

export const JOYID_CELLDEP = ISMAINNET
  ? {
      codeHash:
        "0xd00c84f0ec8fd441c38bc3f87a371f547190f2fcff88e642bc5bf54b9e318323",
      hashType: "type",
      outPoint: {
        txHash:
          "0xf05188e5f3a6767fc4687faf45ba5f1a6e25d3ada6129dae8722cb282f262493",
        index: "0x0",
      },
      depType: "depGroup",
    }
  : {
      codeHash:
        "0xd23761b364210735c19c60561d213fb3beae2fd6172743719eff6920e020baac",
      hashType: "type",
      outPoint: {
        txHash:
          "0x4dcf3f3b09efac8995d6cbee87c5345e812d310094651e0c3d9a730f32dc9263",
        index: "0x0",
      },
      depType: "depGroup",
    };

export const OMNILOCK_CELLDEP = ISMAINNET
  ? {
      codeHash:
        "0x9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26",
      hashType: "type",
      outPoint: {
        txHash:
          "0xdfdb40f5d229536915f2d5403c66047e162e25dedd70a79ef5164356e1facdc8",
        index: "0x0",
      },
      depType: "code",
    }
  : {
      codeHash:
        "0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb",
      hashType: "type",
      outPoint: {
        txHash:
          "0xec18bf0d857c981c3d1f4e17999b9b90c484b303378e94de1a57b0872f5d4602",
        index: "0x0",
      },
      depType: "code",
    };

export const NETWORK_CONFIG = ISMAINNET
  ? {
      PREFIX: "ckb",
      SCRIPTS: {
        SECP256K1_BLAKE160: {
          CODE_HASH:
            "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
          HASH_TYPE: "type",
          TX_HASH:
            "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
          INDEX: "0x0",
          DEP_TYPE: "depGroup",
        },
        SECP256K1_BLAKE160_MULTISIG: {
          CODE_HASH:
            "0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
          HASH_TYPE: "type",
          TX_HASH:
            "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
          INDEX: "0x1",
          DEP_TYPE: "depGroup",
        },
        DAO: {
          CODE_HASH:
            "0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
          HASH_TYPE: "type",
          TX_HASH:
            "0xe2fb199810d49a4d8beec56718ba2593b665db9d52299a0f9e6e75416d73ff5c",
          INDEX: "0x2",
          DEP_TYPE: "code",
        },
      },
    }
  : {
      PREFIX: "ckt",
      SCRIPTS: {
        SECP256K1_BLAKE160: {
          CODE_HASH:
            "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
          HASH_TYPE: "type",
          TX_HASH:
            "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
          INDEX: "0x0",
          DEP_TYPE: "depGroup",
          SHORT_ID: 0,
        },
        SECP256K1_BLAKE160_MULTISIG: {
          CODE_HASH:
            "0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
          HASH_TYPE: "type",
          TX_HASH:
            "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
          INDEX: "0x1",
          DEP_TYPE: "depGroup",
          SHORT_ID: 1,
        },
        DAO: {
          CODE_HASH:
            "0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
          HASH_TYPE: "type",
          TX_HASH:
            "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f",
          INDEX: "0x2",
          DEP_TYPE: "code",
        },
      },
    };

// shannon per KB
export const FEE_RATE = ISMAINNET ? 2000 : 1500;
export const MIN_FEE_RATE = 1000;
// 104CKB for joyidLock/moniLock + DAO cell
export const DAO_MINIMUM_CAPACITY = 104;
// 63CKB for joyidLock/moniLock cell
export const MINIMUM_CHANGE_CAPACITY = 63;
export const CKB_SHANNON_RATIO = 100_000_000;

// TODO because payFeeByFeeRate doesn't fully support joyID
export const JOYID_SIGNATURE_PLACEHOLDER_DEFAULT = "0x" + "0".repeat(1000);

export const EXPLORER_PREFIX = ISMAINNET
  ? "https://explorer.nervos.org/transaction/"
  : "https://pudge.explorer.nervos.org/transaction/";

export const COTA_AGGREGATOR_URL = ISMAINNET
  ? "https://cota.nervina.dev/mainnet-aggregator"
  : "https://cota.nervina.dev/aggregator";

You might want to just adjust ISMAINNET, FEE_RATE, MIN_FEE_RATE, DAO_MINIMUM_CAPACITY and MINIMUM_CHANGE_CAPACITY

Importing the Package

To use the package, you need to import it in your project. Here is an example of how to do this:

import { collectDeposits, collectWithdrawals, buildDepositTransaction, buildWithdrawTransaction, buildUnlockTransaction, batchDaoCells } from 'joy-dao';

Collecting Deposits and Withdrawals

You can use the collectDeposits and collectWithdrawals functions to fetch DAO deposits and withdrawals for a given CKB address.

const deposits = await collectDeposits('your-ckb-address');
const withdrawals = await collectWithdrawals('your-ckb-address');

Building Transactions

The package provides functions to build deposit, withdrawal, and unlock transactions. Here are some examples:

const depositTx = await buildDepositTransaction(ckbAddress, 1000000000n);
const withdrawalTx = await buildWithdrawTransaction(ckbAddress, depositCell);
const unlockTx = await buildUnlockTransaction(ckbAddress, withdrawalCell);

Batch Processing

You can also use the batchDaoCells function to batch deposit, withdrawal, and unlock transactions.

const cells = [...]; // An array of deposit cells or withdrawal cells
const batchTx = await batchDaoCells(ckbAddress, cells);

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Contributing

Contributions are welcome If you find any issues or have suggestions for improvement, please open an issue or submit a pull request.