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

@qingyang-id/zkbnb-l1-sdk

v0.0.14

Published

### Interface ```typescript export abstract class AbstractWallet {

Downloads

1

Readme

ZkBNB L1 Client

Interface

export abstract class AbstractWallet {

  abstract ethSigner(): ethers.Signer;

  abstract ethMessageSigner(): EthMessageSigner;

  address(): Address;

  // *************
  // L1 operations

  async approveBEP20TokenDeposits(
    tokenAddress: TokenAddress, 
    maxErc20ApproveAmount: BigNumberish): 
    Promise<ContractTransaction>;
  
  async deposit(deposit: {
    to: Address;
    tokenAddress: TokenAddress;
    amount: BigNumberish;
    ethTxOptions?: ethers.providers.TransactionRequest;
    approveDepositAmountForBEP20?: boolean;
  }): Promise<ETHOperation>;

  async depositNFT(deposit: {
    to: Address;
    tokenAddress: TokenAddress;
    tokenId: BigNumberish;
    ethTxOptions?: ethers.providers.TransactionRequest;
    approveDepositAllNFT?: boolean;
  }): Promise<ETHOperation>;

  async requestFullExit(fullExit: {
    tokenAddress: TokenAddress;
    accountIndex: number;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async requestFullExitNft(fullExitNFT: {
    tokenId: number;
    accountIndex: number;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async withdrawPendingBalance(withdrawal: {
    owner: string;
    tokenAddress: string;
    amount: BigNumberish;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async withdrawPendingNFTBalance(withdrawalNFT: {
    tokenId: number;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async registerNFTFactory(registerNFTFactory: {
    collectionId: BigNumberish;
    factoryAddress: Address;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async deployAndRegisterNFTFactory(deployAndRegisterNFTFactory: {
    collectionId: BigNumberish;
    name: string;
    symbol: string;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  // AssetGovernance part
  async addAsset(addAsset: {
    tokenAddress: Address;
    ethTxOptions?: ethers.providers.TransactionRequest;
  }): Promise<ETHOperation>;

  async isTokenLister(address: Address): Promise<boolean>;

  // **********
  // L1 getters
  async isBEP20DepositsApproved(tokenAddress: TokenAddress, erc20ApproveThreshold: BigNumber): Promise<boolean>;

  async isERC721DepositsApprovedForAll(tokenAddress: TokenAddress): Promise<boolean>;
  
  // zkBNB part
  async getPendingBalance(address: Address, tokenAddress: TokenAddress): Promise<BigNumber>;

  // governance part
  async resolveTokenId(token: TokenAddress): Promise<number>;

  async resolveTokenAddress(tokenId: number): Promise<Address>;

  async validateAssetAddress(address: string): Promise<number>;

  async getNFTFactory(creatorAddress: string, collectionId: number): Promise<string>;

  async getNftTokenURI(nftContentType: number, nftContentHash: string): Promise<string>;

}

Install

Using npm:

> npm install @bnb-chain/zkbnb-l1-sdk

Using yarn:

> yarn add @bnb-chain/zkbnb-l1-sdk

Using pnpm:

> pnpm add @bnb-chain/zkbnb-l1-sdk

Usage

Init

const testEndpoint = 'https://testapi.zkbnbchain.org'; // bsc testnest
const rpcEndpoint = 'https://data-seed-prebsc-2-s1.binance.org:8545'; // bsc testnest rpc
const ethWallet = new ethers.Wallet(
  'your private key',
  new ethers.providers.JsonRpcProvider(rpcEndpoint)
);
const provider = await Provider.newHttpProvider(testEndpoint);
const wallet = await Wallet.fromZkBNBSigner(ethWallet, provider);

Governance

Get AssetAddress By AssetId

const assetAddress = await wallet.resolveTokenAddress(1);

Get AssetId By AssetAddress

// Please use a legal address according to the actual situation
const assetId = await wallet.resolveTokenId('0x0000000000000000000000000000000000000000');

Validate Asset Address

const addressToken = await wallet.resolveTokenAddress(1);

// If it is a valid address, then return the corresponding assetId value, otherwise return 0
const assetId = await wallet.validateAssetAddress(addressToken);

Get NFTFactory

const creatorAddress = '0xXXXXXXXXXXXXXX';
const collectionId = 1;
// If the factory address has not been updated, the default address is returned, 
// otherwise the updated address is returned
const nftFactory = await wallet.getNFTFactory(creatorAddress, collectionId);

Get Nft TokenURI

const nftContentType = 0;
const nftContentHash = 'hash value';
const tokenUri = await wallet.getNftTokenURI(nftContentType, nftContentHash);

AssetGovernance

Add Asset

const canAdd = await wallet.isTokenLister(ZERO_ADDRESS);
const tokenAddress = '0xXXXXXXXXXXXXXX'; // change to the token address
let isAdded;
try {
    await wallet.resolveTokenId(tokenAddress);
    isAdded = true;
} catch (e) {
    isAdded = false;
}
// Before adding, it is recommended to check whether the corresponding 
// asset exists and whether it can be added.
if (canAdd && !isAdded) {
  await wallet.addAsset({ tokenAddress });
}

ZkBNB

Get Pending Balance

// Please change the value of the parameter according to the actual situation
const address = '0xXXXXXXXXXXXXXX';
const assetAddress = '0xXXXXXXXXXXXXXX';

const pendingBalance = await wallet.getPendingBalance(address, assetAddress);

L1 Getter

Is BEP20 Deposits Approved

// The following addresse can be changed according to the actual situation
const address = await wallet.resolveTokenAddress(1);
const isApproved = await wallet.isBEP20DepositsApproved(address);

Is ERC721 Deposits ApprovedForAll

// The following addresse can be changed according to the actual situation
const address = wallet.provider.contractAddress.defaultNftFactoryContract;
await wallet.isERC721DepositsApprovedForAll(address);

Get ethMessageSigner

const result = await client.ethMessageSigner();

Get address

const address = client.address();

L1 operations

Approve BEP20 Token Deposits

const address = await wallet.resolveTokenAddress(1);
const result = await wallet.approveBEP20TokenDeposits(address);
// You can determine if it is successful by using the following method
const isApproved = await wallet.isBEP20DepositsApproved(address);

Deposit BNB

const tokenAddress = await wallet.resolveTokenAddress(0);
const result = await wallet.deposit({
  to: wallet.address(),
  tokenAddress,
  amount: ethers.utils.parseEther('0.001'),
});

Deposit BEP20

const tokenAddress = await wallet.resolveTokenAddress(1);
// transfer asset from governor to this test wallet
const governorPrivatekey = 'governor private key';
const testEndpoint = 'https://testapi.zkbnbchain.org'; // bsc testnest
const rpcEndpoint = 'https://data-seed-prebsc-2-s1.binance.org:8545'; // bsc testnest rpc

const ethWallet = new ethers.Wallet(
  governorPrivatekey,
  new ethers.providers.JsonRpcProvider(rpcEndpoint)
);
const provider = await Provider.newHttpProvider(testEndpoint);
const governorWallet = await Wallet.fromZkBNBSigner(ethWallet, provider);

const erc20contract = new Contract(tokenAddress, BEP20Interface, governorWallet.ethSigner());
const amount = ethers.utils.parseEther('0.001');
const transferResult = await erc20contract.transfer(wallet.address(), amount);
await transferResult.wait();

// approveDepositAmountForBEP20 If this option is true, the approval operation will be
// executed during the recharge process, otherwise it will not be executed
const result = await wallet.deposit({
  to: wallet.address(),
  tokenAddress,
  amount,
  approveDepositAmountForBEP20: true,
});

Deposit NFT

const tokenAddress = wallet.provider.contractAddress.defaultNftFactoryContract;
const tokenId = 1;
const depositResult = await wallet.depositNFT({
    to: wallet.address(), // zkbnb contract address
    tokenAddress,
    tokenId,
    approveDepositAllNFT: true,
});

Request FullExit

const tokenAddress = await wallet.resolveTokenAddress(1);
const result = await wallet.requestFullExit({
    tokenAddress,
    accountIndex: 0,
});

Request FullExit Nft

const requestResult = await wallet.requestFullExitNft({
    tokenId: 1,
    accountIndex: 0,
});

Withdraw Pending Balance

// It will not come soon

Withdraw Pending NFTBalance

// It will not come soon

Deploy And Register NFTFactory

const name = 'collection name';
const symbol = 'collection symbol';
let collectionId = xxx;
await wallet.deployAndRegisterNFTFactory({
    collectionId,
    name,
    symbol,
});