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

zebec-instant-card-sdk

v1.0.8

Published

An sdk for interacting with zebec instant card program in solana.

Downloads

75

Readme

Zebec Instant Card SDK

An sdk for interacting with zebec instant card program in solana.

Usage

To use this sdk, you are required to create a instance of ZebecCardService.

const connection = new Connection(process.env.RPC_URL || clusterApiUrl("mainnet-beta"));
const wallet = useWallet(); // Note: only in frontend. Use `Wallet` from anchor to create wallet instance for backends.
const provider = getAnchorProvider(connection, wallet);
const program = ZebecCardProgramFactory.getProgram(provider)
const instructions = new ZebecCardInstructions(program);
const service = new ZebecCardService(instructions, connection, wallet.signTranaction);

If you are using the service only for fetching pda data, then you don't need to pass third argument which signTransaction function. Also you can use ZebecConnectionProvider to create program instance for such case.

const provider = getZebecConnectionProvider(connection);
const program = ZebecCardProgramFactory.getProgram(provider);
const instructions = new ZebecCardInstructions(program);
const service = new ZebecCardService(instructions, connection);

Initialize Card Config

Card config can be initialize only one time in the program.

const params: InitCardConfigParams = {
  revenueFee: 2.5,
  solFee: 5,
  tokenFee: 10,
  zicOwnerAddress: provider.publicKey.toString(),
  cardVaultAddress: "<public key>",
  revenueVaultAddress: "<public key>",
}

const payload = await service.initCardConfig(params);
const signature = await payload.execute({ commitment: "finalized" });

If you need to update card config use setCardConfig method.

Update Card Config

const params: SetCardConfigParams = {
  revenueFee: 2.5,
  solFee: 5,
  tokenFee: 10,
  zicOwnerAddress: provider.publicKey.toString(),
  cardVaultAddress: "<public key>",
  revenueVaultAddress: "<public key>",
}

const payload = await service.setCardConfig(params);
const signature = await payload.execute({ commitment: "finalized" });

Deposit USDC

While depositing usdc, a unique pda for each deposit is generated from buyers address, a seed phrase and a counter and is initialized. This pda holds data such as amount deposited, type of card requested, etc. The counter is validated in program such that it should be index in card pda plus one. The service instance provides a method for getting next counter.

const buyerCounter = await service.getNextBuyerCounter();

const params: DepositParams = {
  buyerAddress: provider.publicKey.toString(),
  buyerCounter,
  cardType: "master card",
  amount: 100,
  tokenType: "stable",
};

const payload = await service.deposit(params);
const signature = await payload.execute({ commitment: "finalized" });

Swap and deposit

The swap and deposit method swaps the given input mint to USDC. The swap mode is ExactOut means you specify how much USDC you want to swap and in this case slippage is on the input amount.

const buyerCounter = await service.getNextBuyerCounter();
const params: SwapAndDepositParams = {
  buyerAddress: "<pubkey>",
  buyerCounter,
  cardType: "master card",
  inputAmount: 100,
  inputMintAddress: "zebeczgi5fSEtbpfQKVZKCJ3WgYXxjkMUkNNx7fLKAF",
  slippagePercent: 0.5,
  tokenType: "volatile",
};

const payload = await service.swapAndDeposit(params);
const signature = await payload.execute({ commitment: "finalized" });

Fetch config data

const configData = await service.getCardConfigInfo();
console.log("configData", configData);

Fetch buyer deposit info

const buyerAddress = "<pubkey>";
  const buyerCounter = "1";

  const buyerPda = ZebecCardService.deriveBuyerPda(
    buyerAddress,
    ZEBEC_CARD_PROGRAM.mainnet,
    buyerCounter,
  );
  const info = await service.getBuyerPdaInfo(buyerPda);

  console.log("info", info);

Fetch swap quote info

const params: GetQuoteInfoParams = {
    inputAmount: "0.1",
    inputMintAddress: "So11111111111111111111111111111111111111112",
    slippagePercent: "1",
  };
const info = await service.getQuoteInfo(params);

console.log("info", info);