UNPKG

frakt-client

Version:

Client library for interacting with FRAKT solana program

787 lines 70.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Creator = exports.Data = exports.createSee = exports.unstakeBulkFraktsNoHarvest = exports.updateMintAuthority = exports.harvestBulkStakes = exports.topupStakingPool = exports.createAndMintSomeTokens = exports.updatePoolConfig = exports.initializePoolConfig = exports.updateStakeBulkFrakts = exports.getAllProgramAccounts = exports.getStakes = exports.unstakeBulkFrakts = exports.stakeBulkFrakts = exports.getCreatorsMetadataTokens = exports.createInsertNewTokenInstructions = exports.migrateArtsToNewTokens = exports.findAssociatedTokenAddress = exports.createTokenMetadata = exports.decodedTokenBuffersToUI = exports.decodedCounterBuffersToUI = exports.decodedArtBuffersToUI = exports.getLargestTokenAccountOwnerByMint = exports.readKeypairFromPath = exports.getTokenAddressFromMintAndUser = exports.getArtTokensFromTokens = exports.getCounter = exports.mintArt = exports.buyArt = exports.getAllUserTokens = exports.getArts = void 0; const web3_js_1 = require("@solana/web3.js"); const spl_token_1 = require("@solana/spl-token"); // import urlExist from "url-exist" const url_exists_1 = __importDefault(require("url-exists")); function urlExist(uri) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { url_exists_1.default(uri, (err, exists) => { if (err) return reject(err); resolve(exists); }); }); }); } const fetch = require('node-fetch'); const metadata2_1 = require("./metadata2"); Object.defineProperty(exports, "Data", { enumerable: true, get: function () { return metadata2_1.Data; } }); Object.defineProperty(exports, "Creator", { enumerable: true, get: function () { return metadata2_1.Creator; } }); const metadata2_2 = require("./metadata2"); const fs_1 = require("fs"); const bs58 = require('bs58'); const BufferLayout = __importStar(require("buffer-layout")); // import BN from "bn.js"; const BN = require('bn.js'); // /** * Layout for a public key */ const publicKey = (property = 'publicKey') => { return BufferLayout.blob(32, property); }; /** * Layout for a 64bit unsigned value */ const fixed_sized_string = (property = 'fixed_sized_string', length) => { return BufferLayout.blob(length, property); }; const uint64 = (property = 'uint64') => { return BufferLayout.blob(8, property); }; function readKeypairFromPath(path) { const data = JSON.parse(fs_1.readFileSync(path, 'utf-8')); return web3_js_1.Keypair.fromSecretKey(Buffer.from(data)); } exports.readKeypairFromPath = readKeypairFromPath; const URL_MAX_LEN = 128; const COUNTER_ACCOUNT_DATA_LAYOUT = BufferLayout.struct([BufferLayout.u8('isInitialized'), uint64('count')]); const ART_ACCOUNT_DATA_LAYOUT = BufferLayout.struct([ BufferLayout.u8('is_old_version'), uint64('id'), publicKey('first_owner_pubkey'), publicKey('minted_token_pubkey'), uint64('shape'), uint64('color'), BufferLayout.u8('is_minted'), uint64('art_hash'), uint64('circles_amount'), uint64('fractial_iterations'), uint64('min_rad_low_limit'), uint64('min_rad_high_limit'), uint64('max_rad_low_limit'), uint64('max_rad_high_limit'), uint64('shape_rarity'), uint64('color_rarity'), uint64('created_at'), fixed_sized_string('image_url', URL_MAX_LEN), ]); // pub stake_owner: Pubkey, // pub art_pubkey: Pubkey, // pub mint_pubkey: Pubkey, // pub points: u64, // pub color: u64, // pub shape: u64, // pub staked_at: u64, // pub stake_end_at: u64, // pub version: u64, // pub is_initialized: bool, // pub token_vault_pubkey: Pubkey, // pub is_staked: bool, const STAKE_ACCOUNT_DATA_LAYOUT = BufferLayout.struct([ publicKey('stake_owner'), publicKey('art_pubkey'), publicKey('mint_pubkey'), uint64('points'), uint64('color'), uint64('shape'), uint64('staked_at'), uint64('stake_end_at'), uint64('version'), BufferLayout.u8('bool'), publicKey('token_vault_pubkey'), BufferLayout.u8('is_staked'), uint64('last_harvested_at'), ]); // is_initialized, // farming_vault_owner_pda, // farming_token_mint, // farming_vault_token_account, // farming_pool_vault_balance, // farming_tokens_per_second_per_point, // version, const POOL_CONFIG_ACCOUNT_DATA_LAYOUT = BufferLayout.struct([ BufferLayout.u8('is_initialized'), publicKey('farming_vault_owner_pda'), publicKey('farming_token_mint'), publicKey('farming_vault_token_account'), uint64('farming_pool_vault_balance'), uint64('farming_tokens_per_second_per_point'), uint64('version'), uint64('harvest_unlock_at'), ]); function createTokenMetadata(data, updateAuthority, mintKey, mintAuthorityKey, payer, sendTxn) { return __awaiter(this, void 0, void 0, function* () { const instructions = []; const metadataAccount = yield metadata2_1.createMetadata(data, updateAuthority, mintKey, mintAuthorityKey, instructions, payer); const txMeta = new web3_js_1.Transaction().add(instructions[0]); void (yield sendTxn(txMeta)); }); } exports.createTokenMetadata = createTokenMetadata; function updateMintAuthority(mintPubkey, newAuthority, oldAuthority, sendTxn) { return __awaiter(this, void 0, void 0, function* () { const updateMintAuthority = spl_token_1.Token.createSetAuthorityInstruction(spl_token_1.TOKEN_PROGRAM_ID, mintPubkey, newAuthority, 'MintTokens', oldAuthority, []); const transaction = new web3_js_1.Transaction().add(updateMintAuthority); void (yield sendTxn(transaction)); }); } exports.updateMintAuthority = updateMintAuthority; function createAndMintSomeTokens(amountToMint, decimals, userPublicKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const mintSeed = makeid(8); const mintAddress = yield web3_js_1.PublicKey.createWithSeed(userPublicKey, mintSeed, spl_token_1.TOKEN_PROGRAM_ID); const createMintAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: userPublicKey, basePubkey: userPublicKey, seed: mintSeed, newAccountPubkey: mintAddress, space: spl_token_1.MintLayout.span, lamports: yield connection.getMinimumBalanceForRentExemption(spl_token_1.AccountLayout.span), programId: spl_token_1.TOKEN_PROGRAM_ID, }); // const associatedTokenAddress = await Token.getAssociatedTokenAddress(ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mintAddress, // userPublicKey) const initializeMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, mintAddress, decimals, userPublicKey, null); const tokenAccAddress = yield findAssociatedTokenAddress(userPublicKey, mintAddress); const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintAddress, tokenAccAddress, userPublicKey, userPublicKey); const mintToIx = spl_token_1.Token.createMintToInstruction(spl_token_1.TOKEN_PROGRAM_ID, mintAddress, tokenAccAddress, userPublicKey, [], amountToMint); const transaction = new web3_js_1.Transaction().add(createMintAccountIx, initializeMintIx, createAssociatedTokenAccountIx, mintToIx); void (yield sendTxn(transaction)); return { mintAddress: mintAddress.toBase58(), tokenAccAddress: tokenAccAddress.toBase58(), mintSeed }; }); } exports.createAndMintSomeTokens = createAndMintSomeTokens; function mintArt({ shape, color, art_hash, // Hash of figure+color combination in ranges circles_amount, fractial_iterations, min_rad_low_limit, min_rad_high_limit, max_rad_low_limit, max_rad_high_limit, shape_rarity, color_rarity, image_url, }, adminPubKey, userPublicKey, artPubKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const image_url_formatted = image_url.length > URL_MAX_LEN ? image_url.slice(0, URL_MAX_LEN) : image_url + new Array(URL_MAX_LEN - image_url.length + 1).join(' '); // console.log('image_url_formatted: ', image_url_formatted.length) const mintSeed = makeid(10); const mintAddress = yield web3_js_1.PublicKey.createWithSeed(adminPubKey, mintSeed, spl_token_1.TOKEN_PROGRAM_ID); const createMintAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: adminPubKey, basePubkey: adminPubKey, seed: mintSeed, newAccountPubkey: mintAddress, space: spl_token_1.MintLayout.span, lamports: yield connection.getMinimumBalanceForRentExemption(spl_token_1.AccountLayout.span), programId: spl_token_1.TOKEN_PROGRAM_ID, }); // const associatedTokenAddress = await Token.getAssociatedTokenAddress(ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mintAddress, // userPublicKey) const initializeMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, mintAddress, 0, adminPubKey, null); const tokenAccAddress = yield findAssociatedTokenAddress(userPublicKey, mintAddress); const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintAddress, tokenAccAddress, userPublicKey, adminPubKey); // console.log("create associated token account for", wallet.publicKey.toBase58()) // return await tokenClient.createAssociatedTokenAccount(wallet.publicKey) const MintArtIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: adminPubKey, isSigner: true, isWritable: true }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintAddress, isSigner: false, isWritable: true }, { pubkey: userPublicKey, isSigner: false, isWritable: true }, { pubkey: tokenAccAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(1, ...new BN(shape).toArray('le', 8), ...new BN(color).toArray('le', 8), ...new BN(art_hash).toArray('le', 8), ...new BN(circles_amount).toArray('le', 8), ...new BN(fractial_iterations).toArray('le', 8), ...new BN(min_rad_low_limit).toArray('le', 8), ...new BN(min_rad_high_limit).toArray('le', 8), ...new BN(max_rad_low_limit).toArray('le', 8), ...new BN(max_rad_high_limit).toArray('le', 8), ...new BN(shape_rarity).toArray('le', 8), ...new BN(color_rarity).toArray('le', 8), ...Array.from(Buffer.from(image_url_formatted)))), }); const txMint = new web3_js_1.Transaction().add(createMintAccountIx, initializeMintIx, createAssociatedTokenAccountIx, MintArtIx); void (yield sendTxn(txMint)); }); } exports.mintArt = mintArt; function getLargestTokenAccountOwnerByMint(mintPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { const largestAccounts = (yield connection.getTokenLargestAccounts(mintPubKey, 'processed')).value; const largestTokenAccountPubkey = largestAccounts[0].address; const largestTokenAccountInfo = yield connection.getAccountInfo(largestTokenAccountPubkey, 'processed'); const decoded = decodedTokenBuffersToUI(spl_token_1.AccountLayout.decode(largestTokenAccountInfo.data), largestTokenAccountPubkey); return decoded.owner; }); } exports.getLargestTokenAccountOwnerByMint = getLargestTokenAccountOwnerByMint; function migrateArtsToNewTokens(frakts, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const allInstructions = []; for (let frakt of frakts) { const [createBurnTokenAccountIx, migrateTokenIx] = yield createMigrationToNewTokenInstructions(frakt, userPublicKey, programPubKey); allInstructions.push(createBurnTokenAccountIx); allInstructions.push(migrateTokenIx); } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); }); } exports.migrateArtsToNewTokens = migrateArtsToNewTokens; function createInsertNewTokenInstructions(frakt, adminPubKey, programPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { const artPubKey = new web3_js_1.PublicKey(frakt.metadata.artAccountPubkey); const userPublicKey = new web3_js_1.PublicKey(frakt.metadata.first_owner_pubkey); const mintSeed = makeid(8); const mintPubKey = yield web3_js_1.PublicKey.createWithSeed(adminPubKey, mintSeed, spl_token_1.TOKEN_PROGRAM_ID); const createMintAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: adminPubKey, basePubkey: adminPubKey, seed: mintSeed, newAccountPubkey: mintPubKey, space: spl_token_1.MintLayout.span, lamports: yield connection.getMinimumBalanceForRentExemption(spl_token_1.AccountLayout.span), programId: spl_token_1.TOKEN_PROGRAM_ID, }); // const associatedTokenAddress = await Token.getAssociatedTokenAddress(ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, mintAddress, // userPublicKey) const initializeMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, 0, adminPubKey, null); const tokenAccAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, tokenAccAddress, userPublicKey, adminPubKey); // console.log("create associated token account for", wallet.publicKey.toBase58()) // return await tokenClient.createAssociatedTokenAccount(wallet.publicKey) const InsertNewVersionTokenIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: adminPubKey, isSigner: true, isWritable: true }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: userPublicKey, isSigner: false, isWritable: true }, { pubkey: tokenAccAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(3)), }); return { mintAddress: mintPubKey.toBase58(), instructions: [createMintAccountIx, initializeMintIx, createAssociatedTokenAccountIx, InsertNewVersionTokenIx], }; }); } exports.createInsertNewTokenInstructions = createInsertNewTokenInstructions; function createMigrationToNewTokenInstructions(frakt, userPublicKey, programPubKey) { return __awaiter(this, void 0, void 0, function* () { const TOKEN_BURN_PUBKEY = new web3_js_1.PublicKey('1nc1nerator11111111111111111111111111111111'); const artPubKey = new web3_js_1.PublicKey(frakt.metadata.artAccountPubkey); const mintPubKey = new web3_js_1.PublicKey(frakt.metadata.minted_token_pubkey); const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenBurnAddress = yield findAssociatedTokenAddress(TOKEN_BURN_PUBKEY, mintPubKey); const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, associatedTokenBurnAddress, TOKEN_BURN_PUBKEY, userPublicKey); const MigrationToNewTokenIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: associatedTokenBurnAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(2)), }); return [createAssociatedTokenAccountIx, MigrationToNewTokenIx]; }); } function buyArt(userPublicKey, programPubKey, adminPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [counterAddress, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('counter')], programPubKey); const artSeed = makeid(7); const artAddress = yield web3_js_1.PublicKey.createWithSeed(userPublicKey, artSeed, programPubKey); const createArtAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: userPublicKey, basePubkey: userPublicKey, seed: artSeed, newAccountPubkey: artAddress, space: ART_ACCOUNT_DATA_LAYOUT.span, lamports: yield connection.getMinimumBalanceForRentExemption(ART_ACCOUNT_DATA_LAYOUT.span), programId: programPubKey, }); const BuyArtIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: counterAddress, isSigner: false, isWritable: true }, { pubkey: artAddress, isSigner: false, isWritable: true }, { pubkey: adminPubKey, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(0)), }); const tx = new web3_js_1.Transaction().add(createArtAccountIx, BuyArtIx); void (yield sendTxn(tx)); return { artAddress, counterAddress }; }); } exports.buyArt = buyArt; function unstakeFrakt(frakt, stakePubkey, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [vault_owner_pubkey, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('vaultowner')], programPubKey); const artPubKey = new web3_js_1.PublicKey(frakt.metadata.artAccountPubkey); const mintPubKey = new web3_js_1.PublicKey(frakt.metadata.minted_token_pubkey); const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenVaultAddress = yield findAssociatedTokenAddress(vault_owner_pubkey, mintPubKey); const UnstakeIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakePubkey, isSigner: false, isWritable: true }, { pubkey: vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: associatedTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(5)), }); const tx = new web3_js_1.Transaction(); tx.add(UnstakeIx); void (yield sendTxn(tx)); }); } function stakeBulkFrakts(artsAndMints, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allInstructions = []; for (let artAndMint of artsAndMints) { const subinstructions = yield createStakeFraktInstructions(artAndMint, userPublicKey, programPubKey, { connection, }); allInstructions = [...allInstructions, ...subinstructions]; } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); // const instructions }); } exports.stakeBulkFrakts = stakeBulkFrakts; function unstakeBulkFraktsNoHarvest(fraktsAndStakes, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allInstructions = []; for (let [i, fraktAndStake] of fraktsAndStakes.entries()) { const subinstructions = yield createUnstakeFraktInstructions(fraktAndStake, userPublicKey, programPubKey, { connection, }); allInstructions = [...allInstructions, ...subinstructions]; } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); // const instructions }); } exports.unstakeBulkFraktsNoHarvest = unstakeBulkFraktsNoHarvest; function unstakeBulkFrakts(fraktsAndStakes, farmingMintPubKey, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allInstructions = []; for (let [i, fraktAndStake] of fraktsAndStakes.entries()) { let isAssociatedInitialized = i === 0 ? false : true; const harvestinstructions = yield createHarvestStakingInstructions(fraktAndStake.stakePubkey, farmingMintPubKey, userPublicKey, programPubKey, isAssociatedInitialized, { connection }); const subinstructions = yield createUnstakeFraktInstructions(fraktAndStake, userPublicKey, programPubKey, { connection, }); allInstructions = [...allInstructions, ...subinstructions]; } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); // const instructions }); } exports.unstakeBulkFrakts = unstakeBulkFrakts; function updateStakeBulkFrakts(fraktsAndStakes, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allInstructions = []; for (let fraktAndStake of fraktsAndStakes) { const subinstructions = yield createUpdateStakeFraktInstructions(fraktAndStake, userPublicKey, programPubKey, { connection, }); allInstructions = [...allInstructions, ...subinstructions]; } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); // const instructions }); } exports.updateStakeBulkFrakts = updateStakeBulkFrakts; function createUpdateStakeFraktInstructions({ stakePubkey, artPubKey, mintPubKey }, userPublicKey, programPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [vault_owner_pubkey, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('vaultowner')], programPubKey); const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenVaultAddress = yield findAssociatedTokenAddress(vault_owner_pubkey, mintPubKey); const UpdateStakeIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakePubkey, isSigner: false, isWritable: true }, { pubkey: vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: associatedTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(6)), }); return [UpdateStakeIx]; }); } function createUnstakeFraktInstructions({ stakePubkey, artPubKey, mintPubKey }, userPublicKey, programPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [vault_owner_pubkey, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('vaultowner')], programPubKey); const instructions = []; const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenVaultInfo = yield connection.getAccountInfo(associatedUserTokenAccountAddress, connection.commitment); if (!associatedTokenVaultInfo) { const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, associatedUserTokenAccountAddress, userPublicKey, userPublicKey); instructions.push(createAssociatedTokenAccountIx); } const associatedTokenVaultAddress = yield findAssociatedTokenAddress(vault_owner_pubkey, mintPubKey); instructions.push(new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakePubkey, isSigner: false, isWritable: true }, { pubkey: vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: associatedTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(5)), })); return instructions; }); } function harvestBulkStakes(stakesPubkeys, userPublicKey, farmingMintPubKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allInstructions = []; for (let [i, stakePubkey] of stakesPubkeys.entries()) { let isAssociatedInitialized = i === 0 ? false : true; const subinstructions = yield createHarvestStakingInstructions(stakePubkey, farmingMintPubKey, userPublicKey, programPubKey, isAssociatedInitialized, { connection }); allInstructions = [...allInstructions, ...subinstructions]; } const transaction = new web3_js_1.Transaction(); allInstructions.forEach((instruction) => transaction.add(instruction)); void (yield sendTxn(transaction)); // const instructions }); } exports.harvestBulkStakes = harvestBulkStakes; function createHarvestStakingInstructions(stakePubkey, farmingMintPubkey, userPublicKey, programPubKey, isAssociatedInitialized, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [farming_vault_owner_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('farmingvaultowner')], programPubKey); const [pool_config_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('poolconfig')], programPubKey); const associatedUserFarmingTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, farmingMintPubkey); const associatedFarmingVaultTokenAddress = yield findAssociatedTokenAddress(farming_vault_owner_pubkey, farmingMintPubkey); const HarvestIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: associatedUserFarmingTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakePubkey, isSigner: false, isWritable: true }, { pubkey: pool_config_pubkey, isSigner: false, isWritable: true }, { pubkey: farming_vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: farmingMintPubkey, isSigner: false, isWritable: true }, { pubkey: associatedFarmingVaultTokenAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(9)), }); const instructions = []; const associatedTokenVaultInfo = yield connection.getAccountInfo(associatedUserFarmingTokenAccountAddress, connection.commitment); if (!isAssociatedInitialized && associatedTokenVaultInfo === null) { const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, farmingMintPubkey, associatedUserFarmingTokenAccountAddress, userPublicKey, userPublicKey); instructions.push(createAssociatedTokenAccountIx); } instructions.push(HarvestIx); return instructions; }); } function createStakeFraktInstructions({ artPubKey, mintPubKey }, userPublicKey, programPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [vault_owner_pubkey, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('vaultowner')], programPubKey); const stakeSeed = makeid(10); const stakeAddress = yield web3_js_1.PublicKey.createWithSeed(userPublicKey, stakeSeed, programPubKey); const createStakeAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: userPublicKey, basePubkey: userPublicKey, seed: stakeSeed, newAccountPubkey: stakeAddress, space: STAKE_ACCOUNT_DATA_LAYOUT.span, lamports: yield connection.getMinimumBalanceForRentExemption(STAKE_ACCOUNT_DATA_LAYOUT.span), programId: programPubKey, }); const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenVaultAddress = yield findAssociatedTokenAddress(vault_owner_pubkey, mintPubKey); const associatedTokenVaultInfo = yield connection.getAccountInfo(associatedTokenVaultAddress, 'confirmed'); const StakeIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakeAddress, isSigner: false, isWritable: true }, { pubkey: vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: associatedTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(4)), }); const instructions = []; if (associatedTokenVaultInfo === null) { const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, associatedTokenVaultAddress, vault_owner_pubkey, userPublicKey); instructions.push(createAssociatedTokenAccountIx); } instructions.push(createStakeAccountIx); instructions.push(StakeIx); return instructions; }); } function topupStakingPool(topup_amount, adminPublicKey, farmingMintPubKey, programPubkey, sendTxn) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [farming_vault_owner_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('farmingvaultowner')], programPubkey); const [pool_config_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('poolconfig')], programPubkey); const associatedAdminTokenAccountAddress = yield findAssociatedTokenAddress(adminPublicKey, farmingMintPubKey); const associatedFarmingTokenVaultAddress = yield findAssociatedTokenAddress(farming_vault_owner_pubkey, farmingMintPubKey); const TopupStakingPoolIx = new web3_js_1.TransactionInstruction({ programId: programPubkey, keys: [ { pubkey: adminPublicKey, isSigner: true, isWritable: true }, { pubkey: associatedAdminTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: pool_config_pubkey, isSigner: false, isWritable: true }, { pubkey: farming_vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: farmingMintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedFarmingTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(8, ...new BN(topup_amount).toArray('le', 8))), }); const transaction = new web3_js_1.Transaction().add(TopupStakingPoolIx); void (yield sendTxn(transaction)); // instructions.push(StakeIx) // return instructions }); } exports.topupStakingPool = topupStakingPool; function initializePoolConfig(farmingTokensPerSecondPerPoint, harvest_unlock_at, farmingMintPubkey, adminPubkey, programPubkey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [farming_vault_owner_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('farmingvaultowner')], programPubkey); const [pool_config_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('poolconfig')], programPubkey); const associatedFarmingTokenVaultAddress = yield findAssociatedTokenAddress(farming_vault_owner_pubkey, farmingMintPubkey); const associatedTokenVaultInfo = yield connection.getAccountInfo(associatedFarmingTokenVaultAddress, 'confirmed'); const InitializePoolConfigIx = new web3_js_1.TransactionInstruction({ programId: programPubkey, keys: [ { pubkey: adminPubkey, isSigner: true, isWritable: true }, { pubkey: pool_config_pubkey, isSigner: false, isWritable: true }, { pubkey: farming_vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: farmingMintPubkey, isSigner: false, isWritable: true }, { pubkey: associatedFarmingTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(7, ...new BN(farmingTokensPerSecondPerPoint).toArray('le', 8), ...new BN(harvest_unlock_at).toArray('le', 8))), }); const transaction = new web3_js_1.Transaction(); if (associatedTokenVaultInfo === null) { const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, farmingMintPubkey, associatedFarmingTokenVaultAddress, farming_vault_owner_pubkey, adminPubkey); transaction.add(createAssociatedTokenAccountIx); } // instructions.push(createStakeAccountIx) transaction.add(InitializePoolConfigIx); void (yield sendTxn(transaction)); }); } exports.initializePoolConfig = initializePoolConfig; function updatePoolConfig(farmingTokensPerSecondPerPoint, harvest_unlock_at, adminPubkey, programPubkey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [farming_vault_owner_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('farmingvaultowner')], programPubkey); const [pool_config_pubkey] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('poolconfig')], programPubkey); // const associatedTokenVaultInfo = await connection.getAccountInfo(associatedFarmingTokenVaultAddress, 'confirmed') const UpdatePoolConfigIx = new web3_js_1.TransactionInstruction({ programId: programPubkey, keys: [ { pubkey: adminPubkey, isSigner: true, isWritable: true }, { pubkey: pool_config_pubkey, isSigner: false, isWritable: true }, // { pubkey: farming_vault_owner_pubkey, isSigner: false, isWritable: true }, // { pubkey: farmingMintPubkey, isSigner: false, isWritable: true }, // { pubkey: associatedFarmingTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(10, ...new BN(farmingTokensPerSecondPerPoint).toArray('le', 8), ...new BN(harvest_unlock_at).toArray('le', 8))), }); const transaction = new web3_js_1.Transaction(); // if(associatedTokenVaultInfo === null) { // const createAssociatedTokenAccountIx = Token.createAssociatedTokenAccountInstruction(ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, // farmingMintPubkey, associatedFarmingTokenVaultAddress, farming_vault_owner_pubkey, adminPubkey) // transaction.add(createAssociatedTokenAccountIx) // } // instructions.push(createStakeAccountIx) transaction.add(UpdatePoolConfigIx); void (yield sendTxn(transaction)); }); } exports.updatePoolConfig = updatePoolConfig; function stakeFrakt(frakt, userPublicKey, programPubKey, sendTxn, { connection }) { return __awaiter(this, void 0, void 0, function* () { const encoder = new TextEncoder(); const [vault_owner_pubkey, nonce] = yield web3_js_1.PublicKey.findProgramAddress([encoder.encode('vaultowner')], programPubKey); const stakeSeed = makeid(10); const stakeAddress = yield web3_js_1.PublicKey.createWithSeed(userPublicKey, stakeSeed, programPubKey); const createStakeAccountIx = web3_js_1.SystemProgram.createAccountWithSeed({ fromPubkey: userPublicKey, basePubkey: userPublicKey, seed: stakeSeed, newAccountPubkey: stakeAddress, space: STAKE_ACCOUNT_DATA_LAYOUT.span, lamports: yield connection.getMinimumBalanceForRentExemption(STAKE_ACCOUNT_DATA_LAYOUT.span), programId: programPubKey, }); const artPubKey = new web3_js_1.PublicKey(frakt.metadata.artAccountPubkey); const mintPubKey = new web3_js_1.PublicKey(frakt.metadata.minted_token_pubkey); const associatedUserTokenAccountAddress = yield findAssociatedTokenAddress(userPublicKey, mintPubKey); const associatedTokenVaultAddress = yield findAssociatedTokenAddress(vault_owner_pubkey, mintPubKey); const associatedTokenVaultInfo = yield connection.getAccountInfo(associatedTokenVaultAddress, 'confirmed'); const StakeIx = new web3_js_1.TransactionInstruction({ programId: programPubKey, keys: [ { pubkey: userPublicKey, isSigner: true, isWritable: false }, { pubkey: artPubKey, isSigner: false, isWritable: true }, { pubkey: mintPubKey, isSigner: false, isWritable: true }, { pubkey: associatedUserTokenAccountAddress, isSigner: false, isWritable: true }, { pubkey: stakeAddress, isSigner: false, isWritable: true }, { pubkey: vault_owner_pubkey, isSigner: false, isWritable: true }, { pubkey: associatedTokenVaultAddress, isSigner: false, isWritable: true }, { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ], data: Buffer.from(Uint8Array.of(4)), }); const tx = new web3_js_1.Transaction(); if (associatedTokenVaultInfo === null) { const createAssociatedTokenAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mintPubKey, associatedTokenVaultAddress, vault_owner_pubkey, userPublicKey); tx.add(createAssociatedTokenAccountIx); } tx.add(createStakeAccountIx); tx.add(StakeIx); void (yield sendTxn(tx)); }); } function getTokenAddressFromMintAndUser(userAddress, mintAddress) { return __awaiter(this, void 0, void 0, function* () { return findAssociatedTokenAddress(new web3_js_1.PublicKey(userAddress), new web3_js_1.PublicKey(mintAddress)); }); } exports.getTokenAddressFromMintAndUser = getTokenAddressFromMintAndUser; function getArtTokensFromTokens(arts, tokens) { return arts.filter((art) => tokens.find((token) => art.metadata.minted_token_pubkey == token.mint)); } exports.getArtTokensFromTokens = getArtTokensFromTokens; function getArts(fraktProgramId, { connection }) { return __awaiter(this, void 0, void 0, function* () { let rawArtAccounts = yield connection.getProgramAccounts(fraktProgramId, 'singleGossip'); rawArtAccounts = rawArtAccounts.filter((rawArt) => rawArt.account.data.length == ART_ACCOUNT_DATA_LAYOUT.span); const parsedAccounts = []; for (let rawArt of rawArtAccounts) { const decodedArtState = ART_ACCOUNT_DATA_LAYOUT.decode(rawArt.account.data); parsedAccounts.push(decodedArtBuffersToUI(decodedArtState, rawArt.pubkey)); } return parsedAccounts; }); } exports.getArts = getArts; function getAllProgramAccounts(launchpdProgramPubKey, { connection }) { return __awaiter(this, void 0, void 0, function* () { let allAccounts = yield connection.getProgramAccounts(launchpdProgramPubKey, 'singleGossip'); const rawCounterAccount = allAccounts.find((rawCounter) => rawCounter.account.data.length == COUNTER_ACCOUNT_DATA_LAYOUT.span); const counterAccount = rawCounter