zebec-instant-card-sdk
v1.0.8
Published
An sdk for interacting with zebec instant card program in solana.
Downloads
75
Maintainers
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);