diff --git a/.github/workflows/auto-approve.yml b/.github/workflows/auto-approve.yml new file mode 100644 index 00000000..dc76b4f3 --- /dev/null +++ b/.github/workflows/auto-approve.yml @@ -0,0 +1,12 @@ +name: Auto approve + +on: pull_request_target + +jobs: + auto-approve: + runs-on: ubuntu-latest + permissions: + pull-requests: write + if: github.actor == 'dependabot[bot]' + steps: + - uses: hmarr/auto-approve-action@v4 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d274435..cb2e4686 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* - uses: actions/setup-node@v4 with: - node-version: 20.12.0 + node-version-file: '.nvmrc' - name: Install dependencies run: npm ci - name: Run build diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ae00c812..fb9945b3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -42,7 +42,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -53,7 +53,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -67,4 +67,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 621c46c7..2804a11a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,7 +8,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: oleksiyrudenko/gha-git-credentials@v2-latest + - uses: oleksiyrudenko/gha-git-credentials@v2.1.2 with: global: true name: 'Github CI' @@ -19,7 +19,7 @@ jobs: fetch-depth: '0' - uses: actions/setup-node@v4 with: - node-version: 20.12.0 + node-version-file: '.nvmrc' - name: Install dependencies run: npm ci - name: Run build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9fdc423b..8d6802bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 20.12.0 + node-version-file: '.nvmrc' - run: npm ci - run: npx semantic-release env: diff --git a/.nvmrc b/.nvmrc index 2b9cabc0..f203ab89 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20.12.0 +20.13.1 diff --git a/package-lock.json b/package-lock.json index 49ec67a8..79ef8d5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@staratlas/factory", - "version": "0.6.0", + "version": "0.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@staratlas/factory", - "version": "0.6.0", + "version": "0.7.0", "license": "ISC", "dependencies": { "@coral-xyz/anchor": "^0.29.0", diff --git a/package.json b/package.json index 8bdaf269..6a58c8db 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "mobx-utils": "^6.0.8" }, "devDependencies": { + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/git": "^10.0.1", "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", "@types/big.js": "^6.2.2", diff --git a/src/atlas-staking/instruction_builders/registerStake.ts b/src/atlas-staking/instruction_builders/registerStake.ts index c7c52c5c..9d7180f0 100644 --- a/src/atlas-staking/instruction_builders/registerStake.ts +++ b/src/atlas-staking/instruction_builders/registerStake.ts @@ -36,12 +36,13 @@ export async function registerStakeInstruction({ signers: [], }; - const [registeredStake] = await getRegisteredStake( + const [registeredStake] = getRegisteredStake( programId, authority, stakeMint, rewardMint, ); + const rewardAta = await associatedAddress({ owner: registeredStake, mint: rewardMint, diff --git a/src/atlas-staking/pda_getters/pda_getters.ts b/src/atlas-staking/pda_getters/pda_getters.ts index a7bbfd58..f1439ec5 100644 --- a/src/atlas-staking/pda_getters/pda_getters.ts +++ b/src/atlas-staking/pda_getters/pda_getters.ts @@ -14,13 +14,13 @@ import { /** * Returns the public key and bump seed for a registered stake account * */ -export async function getRegisteredStake( +export function getRegisteredStake( programId: PublicKey, authority: PublicKey, stakeToken: PublicKey, rewardToken: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [ REGISTERED_STAKE, authority.toBuffer(), @@ -34,12 +34,12 @@ export async function getRegisteredStake( /** * Returns the public key and bump seed for a staking account * */ -export async function getStakingAccount( +export function getStakingAccount( programId: PublicKey, user: PublicKey, registeredStake: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [STAKING_ACCOUNT, user.toBuffer(), registeredStake.toBuffer()], programId, ); @@ -74,21 +74,21 @@ export async function getStakingAccountsForRegisteredStake( * * @param programId - Deployed program ID for the Staking Program */ -export async function getStakingVarsAccount( +export function getStakingVarsAccount( programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress([STAKING_VARS], programId); +): [PublicKey, number] { + return PublicKey.findProgramAddressSync([STAKING_VARS], programId); } /** * Returns the public key and bump seed for a user's token escrow * */ -export async function getTokenEscrow( +export function getTokenEscrow( programId: PublicKey, user: PublicKey, registeredStake: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [STAKING_ESCROW, user.toBuffer(), registeredStake.toBuffer()], programId, ); @@ -97,11 +97,11 @@ export async function getTokenEscrow( /** * Returns the public key and bump seed for a registered stake's reward vault authority * */ -export async function getRewardAuth( +export function getRewardAuth( programId: PublicKey, registeredStake: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [REWARD_AUTH, registeredStake.toBuffer()], programId, ); diff --git a/src/atlas-staking/pda_getters/pda_info_getters.ts b/src/atlas-staking/pda_getters/pda_info_getters.ts index bf79558a..122fd2e3 100644 --- a/src/atlas-staking/pda_getters/pda_info_getters.ts +++ b/src/atlas-staking/pda_getters/pda_info_getters.ts @@ -58,7 +58,7 @@ export async function getStakingVarsAccountInfo( programId: programId, }); - const [stakingVarsAccount] = await getStakingVarsAccount(programId); + const [stakingVarsAccount] = getStakingVarsAccount(programId); const stakingVarsInfo = await program.account.stakingVars.fetch(stakingVarsAccount); return stakingVarsInfo as StakingVarsAccountInfo; diff --git a/src/factions.ts b/src/factions.ts index b26fd87f..cb22c50d 100644 --- a/src/factions.ts +++ b/src/factions.ts @@ -185,11 +185,11 @@ export function getIDL(programId: web3.PublicKey): unknown { return _tmp; } -export async function getPlayerFactionPDA( +export function getPlayerFactionPDA( playerPublicKey: web3.PublicKey, programId: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [Buffer.from(FACTION_PREFIX, 'utf8'), playerPublicKey.toBuffer()], programId, ); @@ -204,7 +204,7 @@ export async function enlistToFaction( playerPublicKey: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [playerFactionPda, bump] = await getPlayerFactionPDA( + const [playerFactionPda, bump] = getPlayerFactionPDA( playerPublicKey, programId, ); @@ -241,9 +241,7 @@ export async function getPlayer( const idl = getIDL(programId); const program = new Program(idl, programId, provider); - const [playerFactionPDA] = await getPlayerFactionPDA( - playerPublicKey, - programId, + const [playerFactionPDA] = getPlayerFactionPDA(playerPublicKey, programId, ); const obj = await program.account.playerFactionData.fetch(playerFactionPDA); return obj as PlayerFaction; diff --git a/src/marketplace/instruction_builders/cancelOrder.ts b/src/marketplace/instruction_builders/cancelOrder.ts index 679c4980..709738c1 100644 --- a/src/marketplace/instruction_builders/cancelOrder.ts +++ b/src/marketplace/instruction_builders/cancelOrder.ts @@ -70,7 +70,7 @@ export async function createCancelOrderInstruction({ } // Derive the open orders counter, initializing if necessary - const [counterAddress] = await getOpenOrdersCounter( + const [counterAddress] = getOpenOrdersCounter( orderInitializer, depositMint, programId, diff --git a/src/marketplace/instruction_builders/createOrder.ts b/src/marketplace/instruction_builders/createOrder.ts index 11047250..8b6ed974 100644 --- a/src/marketplace/instruction_builders/createOrder.ts +++ b/src/marketplace/instruction_builders/createOrder.ts @@ -73,7 +73,7 @@ export async function createInitializeBuyOrderInstruction({ initializerReceiveTokenAccount = tokenAccount; } // Derive the open orders counter, initializing if necessary - const [counterAddress] = await getOpenOrdersCounter( + const [counterAddress] = getOpenOrdersCounter( initializerMainAccount, depositMint, programId, @@ -174,7 +174,7 @@ export async function createInitializeSellOrderInstruction({ } // Derive the open orders counter, initializing if necessary - const [counterAddress] = await getOpenOrdersCounter( + const [counterAddress] = getOpenOrdersCounter( initializerMainAccount, depositMint, programId, diff --git a/src/marketplace/instruction_builders/exchangeOrder.ts b/src/marketplace/instruction_builders/exchangeOrder.ts index 06b19fae..e758cfac 100644 --- a/src/marketplace/instruction_builders/exchangeOrder.ts +++ b/src/marketplace/instruction_builders/exchangeOrder.ts @@ -124,12 +124,12 @@ export async function createExchangeInstruction({ initializerReceiveTokenAccount = response.tokenAccount; } - const [orderVaultAccount] = await getOrderVault( + const [orderVaultAccount] = getOrderVault( orderInitializer, initializerDepositMint, programId, ); - const [openOrdersCounter] = await getOpenOrdersCounter( + const [openOrdersCounter] = getOpenOrdersCounter( orderInitializer, initializerDepositMint, programId, @@ -156,7 +156,7 @@ export async function createExchangeInstruction({ const seller = orderType === OrderSide.Buy ? orderTaker : orderInitializer; - const [feeReduction] = await getFeeExemptAccount(seller, programId); + const [feeReduction] = getFeeExemptAccount(seller, programId); const exchangeIx = await program.methods .processExchange(new BN(purchaseQty), expectedPrice, seller) diff --git a/src/marketplace/instruction_builders/feeExempt.ts b/src/marketplace/instruction_builders/feeExempt.ts index e0e35944..b82d0d14 100644 --- a/src/marketplace/instruction_builders/feeExempt.ts +++ b/src/marketplace/instruction_builders/feeExempt.ts @@ -34,11 +34,8 @@ export async function createAddFeeExemptionInstruction({ }; const FEE_EXEMPTION = 1_000_000; - const [feeExemptAccount] = await getFeeExemptAccount( - feeExemptTarget, - programId, - ); - const [marketVarsAccount] = await getMarketVarsAccount(programId); + const [feeExemptAccount] = getFeeExemptAccount(feeExemptTarget, programId); + const [marketVarsAccount] = getMarketVarsAccount(programId); const instruction = [ await program.methods .addFeeExemption(new BN(FEE_EXEMPTION)) @@ -77,11 +74,8 @@ export async function createRemoveFeeExemptionInstruction({ instructions: [], }; - const [feeExemptAccount] = await getFeeExemptAccount( - feeExemptTarget, - programId, - ); - const [marketVarsAccount] = await getMarketVarsAccount(programId); + const [feeExemptAccount] = getFeeExemptAccount(feeExemptTarget, programId); + const [marketVarsAccount] = getMarketVarsAccount(programId); const instruction = [ await program.methods .removeFeeExemption() diff --git a/src/marketplace/pda_getters/pda_getters.ts b/src/marketplace/pda_getters/pda_getters.ts index 548af238..6df0397a 100644 --- a/src/marketplace/pda_getters/pda_getters.ts +++ b/src/marketplace/pda_getters/pda_getters.ts @@ -9,10 +9,10 @@ import { getGmIDL } from './../utils/getMarketplaceProgram'; * * @param programId - Deployed program ID for Galactic Marketplace */ -export async function getMarketVarsAccount( +export function getMarketVarsAccount( programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress([Seeds.MARKET_VARS_SEED], programId); +): [PublicKey, number] { + return PublicKey.findProgramAddressSync([Seeds.MARKET_VARS_SEED], programId); } /** @@ -20,12 +20,12 @@ export async function getMarketVarsAccount( * * @param programId - Deployed program ID for Galactic Marketplace */ -export async function getOrderVault( +export function getOrderVault( orderInitializer: PublicKey, tokenMint: PublicKey, programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [Seeds.ORDER_VAULT_SEED, orderInitializer.toBuffer(), tokenMint.toBuffer()], programId, ); @@ -37,11 +37,11 @@ export async function getOrderVault( * @param playerPubkey - Pubkey of order initializer * @param programId - Deployed program ID for Galactic Marketplace */ -export async function getOrderVaultAuth( +export function getOrderVaultAuth( playerPubkey: PublicKey, programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [Seeds.ORDER_VAULT_AUTH_SEED, playerPubkey.toBuffer()], programId, ); @@ -53,11 +53,11 @@ export async function getOrderVaultAuth( * @param programId - Deployed program ID for Galactic Marketplace * @param currencyMint - Mint address for registered currency */ -export async function getRegisteredCurrencyAccount( +export function getRegisteredCurrencyAccount( programId: PublicKey, currencyMint: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [Seeds.REGISTERED_CURRENCY_SEED, currencyMint.toBuffer()], programId, ); @@ -92,12 +92,12 @@ export async function getAllRegisteredCurrencies( return currencyInfo as RegisteredCurrencyItem[]; } -export async function getOpenOrdersCounter( +export function getOpenOrdersCounter( playerPubkey: PublicKey, depositMint: PublicKey, programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [ Seeds.OPEN_ORDERS_COUNTER, playerPubkey.toBuffer(), @@ -107,11 +107,11 @@ export async function getOpenOrdersCounter( ); } -export async function getFeeExemptAccount( +export function getFeeExemptAccount( targetAccount: PublicKey, programId: PublicKey, -): Promise<[PublicKey, number]> { - return PublicKey.findProgramAddress( +): [PublicKey, number] { + return PublicKey.findProgramAddressSync( [Seeds.FEE_EXEMPT_SEED, targetAccount.toBuffer()], programId, ); diff --git a/src/marketplace/pda_getters/pda_info_getters.ts b/src/marketplace/pda_getters/pda_info_getters.ts index 5811ee33..b811726b 100644 --- a/src/marketplace/pda_getters/pda_info_getters.ts +++ b/src/marketplace/pda_getters/pda_info_getters.ts @@ -28,7 +28,7 @@ export async function getMarketVarsAccountInfo( programId: programId, }); - const [marketVarsAccount] = await getMarketVarsAccount(programId); + const [marketVarsAccount] = getMarketVarsAccount(programId); const marketVarsInfo = await program.account.marketVars.fetch(marketVarsAccount); return marketVarsInfo as MarketVarsAccountInfo; @@ -44,9 +44,7 @@ export async function getFeeExemptAccountInfo( programId: programId, }); - const [feeExemptAccount] = await getFeeExemptAccount( - targetAccount, - programId, + const [feeExemptAccount] = getFeeExemptAccount(targetAccount, programId, ); const feeExemptInfo = await program.account.feeExempt.fetch(feeExemptAccount); return feeExemptInfo as FeeExemptInfo; @@ -69,7 +67,7 @@ export async function getRegisteredCurrencyAccountInfo( programId: programId, }); - const [registeredCurrencyAccount] = await getRegisteredCurrencyAccount( + const [registeredCurrencyAccount] = getRegisteredCurrencyAccount( programId, currencyMint, ); @@ -119,7 +117,7 @@ export async function getRoyaltyReductionForUserAndMint( ); // Find user's staking account - const [stakingAccount] = await getStakingAccount( + const [stakingAccount] = getStakingAccount( stakingProgramId, playerPubkey, registeredStake, diff --git a/src/marketplace/services/GmClientService.ts b/src/marketplace/services/GmClientService.ts index 7f31d6a0..db292f31 100644 --- a/src/marketplace/services/GmClientService.ts +++ b/src/marketplace/services/GmClientService.ts @@ -433,7 +433,7 @@ export class GmClientService { (curr) => curr.mint === order.currencyMint, ); - const [stakingAccount] = await getStakingAccount( + const [stakingAccount] = getStakingAccount( stakingProgramId, seller, registeredStake, diff --git a/src/score.ts b/src/score.ts index 20fe13ad..cb32f637 100644 --- a/src/score.ts +++ b/src/score.ts @@ -1,12 +1,12 @@ import { AnchorProvider, BN, Idl, Program, web3 } from '@coral-xyz/anchor'; -import type { AnchorTypes } from './anchor/types'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; import { SystemProgram } from '@solana/web3.js'; import { FactoryReturn, getPlayerFactionPDA } from '.'; -import { baseIdl } from './util/scoreIdl'; -import { scoreLogBaseIdl } from './util/scoreLogIdl'; +import type { AnchorTypes } from './anchor/types'; import { getTokenAccount } from './util'; import * as SCORE_TYPES from './util/scoreIdl'; +import { baseIdl } from './util/scoreIdl'; +import { scoreLogBaseIdl } from './util/scoreLogIdl'; export type SCORE_PROGRAM = SCORE_TYPES.Score; export type ScoreTypes = AnchorTypes; @@ -34,10 +34,10 @@ export function getScoreIDL(programId: web3.PublicKey): unknown { * @param programId - Deployed program ID for the SCORE program * @returns - [Public key, bump seed] */ -export async function getScoreVarsAccount( +export function getScoreVarsAccount( programId: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [Buffer.from('SCOREVARS')], programId, ); @@ -50,11 +50,11 @@ export async function getScoreVarsAccount( * @param shipMint - Ship mint address * @returns - [Ship account public key, bump seed] */ -export async function getScoreVarsShipAccount( +export function getScoreVarsShipAccount( programId: web3.PublicKey, shipMint: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [Buffer.from('SCOREVARS_SHIP'), shipMint.toBuffer()], programId, ); @@ -69,12 +69,12 @@ export async function getScoreVarsShipAccount( * @param playerPublicKey - Player's public key * @returns - [Escrow account public key, bump seed] */ -export async function getScoreEscrowAccount( +export function getScoreEscrowAccount( programId: web3.PublicKey, shipMint: web3.PublicKey, resourceMint: web3.PublicKey, playerPublicKey: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { +): [web3.PublicKey, number] { const seeds = [ Buffer.from('SCORE_ESCROW'), playerPublicKey.toBuffer(), @@ -83,7 +83,7 @@ export async function getScoreEscrowAccount( if (resourceMint !== null) { seeds.push(resourceMint.toBuffer()); } - return web3.PublicKey.findProgramAddress(seeds, programId); + return web3.PublicKey.findProgramAddressSync(seeds, programId); } /** @@ -94,12 +94,12 @@ export async function getScoreEscrowAccount( * @param playerPublicKey - Player's public key * @returns - [Authority account public key, bump seed] */ -export async function getScoreEscrowAuthAccount( +export function getScoreEscrowAuthAccount( programId: web3.PublicKey, shipMint: web3.PublicKey, playerPublicKey: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [ Buffer.from('SCORE_ESCROW_AUTHORITY'), playerPublicKey.toBuffer(), @@ -117,12 +117,12 @@ export async function getScoreEscrowAuthAccount( * @param playerPublicKey - Player's public key * @returns - [Staking account public key, bump seed] */ -export async function getShipStakingAccount( +export function getShipStakingAccount( programId: web3.PublicKey, assetMint: web3.PublicKey, playerPublicKey: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [ Buffer.from('SCORE_INFO'), playerPublicKey.toBuffer(), @@ -146,7 +146,7 @@ export async function getScoreVarsInfo( const idl = getScoreIDL(programId); const program = new Program(idl, programId, provider); - const [scoreVarsAccount] = await getScoreVarsAccount(programId); + const [scoreVarsAccount] = getScoreVarsAccount(programId); const obj = await program.account.scoreVars.fetch(scoreVarsAccount); return obj; } @@ -169,7 +169,7 @@ export async function getShipStakingAccountInfo( const idl = getScoreIDL(programId); const program = new Program(idl, programId, provider); - const [shipStakingAccount] = await getShipStakingAccount( + const [shipStakingAccount] = getShipStakingAccount( programId, shipMint, playerPublicKey, @@ -211,10 +211,7 @@ export async function getScoreVarsShipInfo( const idl = getScoreIDL(programId); const program = new Program(idl, programId, provider); - const [scoreVarsShipAccount] = await getScoreVarsShipAccount( - programId, - shipMint, - ); + const [scoreVarsShipAccount] = getScoreVarsShipAccount(programId, shipMint); const obj = await program.account.scoreVarsShip.fetch(scoreVarsShipAccount); return obj; } @@ -225,10 +222,10 @@ export async function getScoreVarsShipInfo( * @param programId - Deployed program ID for the SCORE program * @returns - [Treasury's Public key, bump seed] */ -export async function getScoreTreasuryTokenAccount( +export function getScoreTreasuryTokenAccount( programId: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [Buffer.from('SCORE_TREASURY')], programId, ); @@ -240,10 +237,10 @@ export async function getScoreTreasuryTokenAccount( * @param programId - Deployed program ID for the SCORE program * @returns - [Authority account public key, bump seed] */ -export async function getScoreTreasuryAuthAccount( +export function getScoreTreasuryAuthAccount( programId: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [Buffer.from('SCORE_TREASURY_AUTHORITY')], programId, ); @@ -316,7 +313,7 @@ export async function getAllFleetsForUserPublicKey( const playerShipStakingAccounts = []; for (const ship of shipsRegistered) { - const [playerShipStakingAccount] = await getShipStakingAccount( + const [playerShipStakingAccount] = getShipStakingAccount( programId, ship.account.shipMint as web3.PublicKey, playerPublicKey, @@ -327,11 +324,9 @@ export async function getAllFleetsForUserPublicKey( const _playerFleets = await program.account.shipStaking.fetchMultiple( playerShipStakingAccounts, ); - const playerFleets: ShipStakingInfo[] = _playerFleets + return _playerFleets .filter((fleet) => fleet !== null) .map((fleet) => fleet); - - return playerFleets; } /** @@ -361,13 +356,12 @@ export async function createScoreVarsInitializeInstruction( const program = new Program(idl, programId, provider); const [treasuryTokenAccount, treasuryBump] = - await getScoreTreasuryTokenAccount(programId); + getScoreTreasuryTokenAccount(programId); const [treasuryAuthorityAccount, treasuryAuthBump] = - await getScoreTreasuryAuthAccount(programId); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + getScoreTreasuryAuthAccount(programId); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); - const ix = await program.instruction.processInitialize( + return await program.instruction.processInitialize( scoreVarsBump, treasuryBump, treasuryAuthBump, @@ -389,7 +383,6 @@ export async function createScoreVarsInitializeInstruction( signers: [], }, ); - return ix; } /** @@ -428,12 +421,13 @@ export async function createRegisterShipInstruction( const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); - const ix = await program.instruction.processRegisterShip( + return await program.instruction.processRegisterShip( scoreVarsBump, scoreVarsShipBump, new BN(rewardRatePerSecond), @@ -456,7 +450,6 @@ export async function createRegisterShipInstruction( signers: [], }, ); - return ix; } /** @@ -478,12 +471,13 @@ export async function createDeregisterShipInstruction( const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); - const ix = await program.instruction.processDeregisterShip( + return await program.instruction.processDeregisterShip( scoreVarsBump, scoreVarsShipBump, { @@ -496,7 +490,6 @@ export async function createDeregisterShipInstruction( signers: [], }, ); - return ix; } /** @@ -519,12 +512,13 @@ export async function createUpdateRewardRateInstruction( const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); - const ix = await program.instruction.processUpdateRewardRate( + return await program.instruction.processUpdateRewardRate( scoreVarsBump, scoreVarsShipBump, new BN(newRewardRatePerSecond), @@ -538,7 +532,6 @@ export async function createUpdateRewardRateInstruction( signers: [], }, ); - return ix; } /** @@ -550,6 +543,7 @@ export async function createUpdateRewardRateInstruction( * @param shipMint - Ship mint address * @param shipTokenAccount - Token account for the ship resource being deposited * @param programId - Deployed program ID for the SCORE program + * @param factionEnlistmentProgramId */ export async function createInitialDepositInstruction( connection: web3.Connection, @@ -562,25 +556,27 @@ export async function createInitialDepositInstruction( 'FACTNmq2FhA2QNTnGM2aWJH3i7zT3cND5CgvjYTjyVYe', ), ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [shipEscrow, escrowBump] = await getScoreEscrowAccount( + const [shipEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, null, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [playerFactionPDA] = await getPlayerFactionPDA( + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [playerFactionPDA] = getPlayerFactionPDA( playerPublicKey, factionEnlistmentProgramId, ); @@ -588,7 +584,7 @@ export async function createInitialDepositInstruction( const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processInitialDeposit( + return await program.instruction.processInitialDeposit( stakingBump, scoreVarsShipBump, escrowAuthBump, @@ -611,7 +607,6 @@ export async function createInitialDepositInstruction( }, }, ); - return ix; } /** @@ -632,29 +627,31 @@ export async function createPartialDepositInstruction( shipTokenAccount: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [shipEscrow, escrowBump] = await getScoreEscrowAccount( + const [shipEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, null, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processPartialDeposit( + return await program.instruction.processPartialDeposit( stakingBump, scoreVarsShipBump, escrowAuthBump, @@ -675,7 +672,6 @@ export async function createPartialDepositInstruction( }, }, ); - return ix; } /** @@ -700,31 +696,32 @@ export async function createRearmInstruction( armsTokenAccount: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [armsEscrow, escrowBump] = await getScoreEscrowAccount( + const [armsEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, armsMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processRearm( + return await program.instruction.processRearm( stakingBump, scoreVarsBump, scoreVarsShipBump, @@ -750,8 +747,6 @@ export async function createRearmInstruction( }, }, ); - - return ix; } /** @@ -776,31 +771,32 @@ export async function createRefeedInstruction( foodTokenAccount: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [foodEscrow, escrowBump] = await getScoreEscrowAccount( + const [foodEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, foodMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processRefeed( + return await program.instruction.processRefeed( stakingBump, scoreVarsBump, scoreVarsShipBump, @@ -826,8 +822,6 @@ export async function createRefeedInstruction( }, }, ); - - return ix; } /** @@ -852,31 +846,32 @@ export async function createRefuelInstruction( fuelTokenAccount: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [fuelEscrow, escrowBump] = await getScoreEscrowAccount( + const [fuelEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, fuelMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processRefuel( + return await program.instruction.processRefuel( stakingBump, scoreVarsBump, scoreVarsShipBump, @@ -902,8 +897,6 @@ export async function createRefuelInstruction( }, }, ); - - return ix; } /** @@ -928,20 +921,21 @@ export async function createRepairInstruction( toolkitTokenAccount: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processRepair( + return await program.instruction.processRepair( stakingBump, scoreVarsBump, scoreVarsShipBump, @@ -963,8 +957,6 @@ export async function createRepairInstruction( }, }, ); - - return ix; } /** @@ -983,20 +975,21 @@ export async function createSettleInstruction( shipMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processSettle( + return await program.instruction.processSettle( stakingBump, scoreVarsBump, scoreVarsShipBump, @@ -1012,7 +1005,6 @@ export async function createSettleInstruction( }, }, ); - return ix; } /** @@ -1030,17 +1022,19 @@ export async function createHarvestInstruction( shipMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); const [treasuryTokenAccount, treasuryBump] = - await getScoreTreasuryTokenAccount(programId); + getScoreTreasuryTokenAccount(programId); const [treasuryAuthorityAccount, treasuryAuthBump] = - await getScoreTreasuryAuthAccount(programId); + getScoreTreasuryAuthAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); @@ -1109,26 +1103,27 @@ export async function createWithdrawFuelInstruction( shipMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [fuelEscrow, escrowBump] = await getScoreEscrowAccount( + const [fuelEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, fuelMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); @@ -1196,26 +1191,27 @@ export async function createWithdrawFoodInstruction( shipMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [foodEscrow, escrowBump] = await getScoreEscrowAccount( + const [foodEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, foodMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); @@ -1283,26 +1279,27 @@ export async function createWithdrawArmsInstruction( shipMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [armsEscrow, escrowBump] = await getScoreEscrowAccount( + const [armsEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, armsMint, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); @@ -1372,30 +1369,31 @@ export async function createWithdrawShipsInstruction( toolkitMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [shipEscrow, escrowBump] = await getScoreEscrowAccount( + const [shipEscrow, escrowBump] = getScoreEscrowAccount( programId, shipMint, null, playerPublicKey, ); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, ); - const [scoreVarsShipAccount, scoreVarsShipBump] = - await getScoreVarsShipAccount(programId, shipMint); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); + const [scoreVarsShipAccount, scoreVarsShipBump] = getScoreVarsShipAccount( + programId, + shipMint, + ); + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); const [treasuryTokenAccount, treasuryBump] = - await getScoreTreasuryTokenAccount(programId); + getScoreTreasuryTokenAccount(programId); const [treasuryAuthorityAccount, treasuryAuthBump] = - await getScoreTreasuryAuthAccount(programId); + getScoreTreasuryAuthAccount(programId); const ixSet: FactoryReturn = { signers: [], @@ -1519,38 +1517,37 @@ export async function closeAccountsInstruction( armsMint: web3.PublicKey, programId: web3.PublicKey, ): Promise { - const [escrowAuthority, escrowAuthBump] = await getScoreEscrowAuthAccount( + const [escrowAuthority, escrowAuthBump] = getScoreEscrowAuthAccount( programId, shipMint, playerPublicKey, ); - const [shipEscrow, shipBump] = await getScoreEscrowAccount( + const [shipEscrow, shipBump] = getScoreEscrowAccount( programId, shipMint, null, playerPublicKey, ); - const [fuelEscrow, fuelBump] = await getScoreEscrowAccount( + const [fuelEscrow, fuelBump] = getScoreEscrowAccount( programId, shipMint, fuelMint, playerPublicKey, ); - const [foodEscrow, foodBump] = await getScoreEscrowAccount( + const [foodEscrow, foodBump] = getScoreEscrowAccount( programId, shipMint, foodMint, playerPublicKey, ); - const [armsEscrow, armsBump] = await getScoreEscrowAccount( + const [armsEscrow, armsBump] = getScoreEscrowAccount( programId, shipMint, armsMint, playerPublicKey, ); - const [scoreVarsAccount, scoreVarsBump] = - await getScoreVarsAccount(programId); - const [shipStakingAccount, stakingBump] = await getShipStakingAccount( + const [scoreVarsAccount, scoreVarsBump] = getScoreVarsAccount(programId); + const [shipStakingAccount, stakingBump] = getShipStakingAccount( programId, shipMint, playerPublicKey, @@ -1559,7 +1556,7 @@ export async function closeAccountsInstruction( const idl = getScoreIDL(programId); const provider = new AnchorProvider(connection, null, null); const program = new Program(idl, programId, provider); - const ix = await program.instruction.processCloseAccounts( + return await program.instruction.processCloseAccounts( stakingBump, scoreVarsBump, shipBump, @@ -1587,5 +1584,4 @@ export async function closeAccountsInstruction( }, }, ); - return ix; } diff --git a/src/util/helpers.ts b/src/util/helpers.ts index bab588f4..f1ae781e 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -88,11 +88,11 @@ export async function convertFactionStringToNum( * @param mint - the mint * @returns a promise of the associated token address */ -export async function getAssociatedTokenAddress( +export function getAssociatedTokenAddress( owner: PublicKey, mint: PublicKey, -): Promise { - const [address] = await PublicKey.findProgramAddress( +): PublicKey { + const [address] = PublicKey.findProgramAddressSync( [owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID, ); diff --git a/src/util/scoreHelpers.ts b/src/util/scoreHelpers.ts index 405a4c63..3121545c 100644 --- a/src/util/scoreHelpers.ts +++ b/src/util/scoreHelpers.ts @@ -17,11 +17,11 @@ import { AccountMeta } from '@solana/web3.js'; * @param mint - Asset mint * @param buyer */ -export async function getAtaForMint( +export function getAtaForMint( mint: web3.PublicKey, buyer: web3.PublicKey, -): Promise<[web3.PublicKey, number]> { - return web3.PublicKey.findProgramAddress( +): [web3.PublicKey, number] { + return web3.PublicKey.findProgramAddressSync( [buyer.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID, ); @@ -44,7 +44,7 @@ export async function createATokenAccount( payer = payer || provider.wallet.publicKey; owner = owner || provider.wallet.publicKey; - const [associatedTokenAccount] = await getAtaForMint(mint, owner); + const [associatedTokenAccount] = getAtaForMint(mint, owner); const tx = new web3.Transaction(); const ix = await createAssociatedTokenAccountInstruction( associatedTokenAccount,