gemworks / gem-farm

Configurable staking for NFT Projects on Solana
https://gemfarm.gg/
MIT License
338 stars 252 forks source link

Regarding the Breaking changes introduced on v0.24.2 #85

Open AnderUstarroz opened 2 years ago

AnderUstarroz commented 2 years ago

Also regarding https://github.com/gemworks/gem-farm/issues/81 we are using our own frontend and the last changes broke compatibility. Just pulling the latest version won't work for us, because we have some merged transactions to simplify the flow (unstake, cooldown and withdraw gem within 1 step):

const unstakeTx = await this.farmProgram.rpc.unstake(
        farmAuthBump,
        farmTreasuryBump,
        farmerBump,
        skipRewards,
        {
          accounts: {
            farm,
            farmer,
            farmTreasury,
            identity: identityPk,
            bank: farmAcc.bank,
            vault,
            farmAuthority: farmAuth,
            gemBank: this.bankProgram.programId,
            systemProgram: SystemProgram.programId,
            feeAcc: feeAccount,
          },
          signers,
        }
      );

const cooldownTx = await this.farmProgram.rpc.unstake(
        farmAuthBump,
        farmTreasuryBump,
        farmerBump,
        skipRewards,
        {
          accounts: {
            farm,
            farmer,
            farmTreasury,
            identity: identityPk,
            bank: farmAcc.bank,
            vault,
            farmAuthority: farmAuth,
            gemBank: this.bankProgram.programId,
            systemProgram: SystemProgram.programId,
            feeAcc: feeAccount,
          },
          signers,
        }
      );

const withdrawGemTx = await gb.withdrawGemWallet(
        bank.value,
        vault.value,
        new BN(1),
        mint
      );

I have updated the transactions adding feeAcc same way as I saw on the updated gem-farm-client.ts file, but unstaking throws the following error:

Transaction simulation failed: Error processing Instruction 0: custom program error: 0xbbd 
    Program farmL4xeBFVXJqtfxCzU9b28QACM7E2W2ctT6epAjvE invoke [1]
    Program log: Instruction: Unstake
    Program log: AnchorError caused by account: system_program. Error Code: AccountNotEnoughKeys. Error Number: 3005. Error Message: Not enough account keys given to the instruction.
    Program farmL4xeBFVXJqtfxCzU9b28QACM7E2W2ctT6epAjvE consumed 21271 of 1400000 compute units
    Program farmL4xeBFVXJqtfxCzU9b28QACM7E2W2ctT6epAjvE failed: custom program error: 0xbbd

Could you give us any hint to know who to solve this error? as I said just pulling the latest master is not an option for us, as our code as diverged significantly.

dylie-eth commented 2 years ago

I do the following in my custom implementation. Had to change it up completely since the new update.

const endStakingIx = await this.farmProgram.methods
      .unstake(farmAuthBump, farmTreasuryBump, farmerBump, skipRewards)
      .accounts({
        farm,
        farmer,
        farmTreasury,
        identity: identityPk,
        bank: farmAcc.bank,
        vault,
        farmAuthority: farmAuth,
        gemBank: this.bankProgram.programId,
        systemProgram: SystemProgram.programId,
        feeAcc: feeAccount,
      })
      .signers(signers)
      .instruction();

    const endCooldownIx = await this.farmProgram.methods
      .unstake(farmAuthBump, farmTreasuryBump, farmerBump, skipRewards)
      .accounts({
        farm,
        farmer,
        farmTreasury,
        identity: identityPk,
        bank: farmAcc.bank,
        vault,
        farmAuthority: farmAuth,
        gemBank: this.bankProgram.programId,
        systemProgram: SystemProgram.programId,
        feeAcc: feeAccount,
      })
      .signers(signers)
      .instruction();

    const withdrawGemIx = await this.bankProgram.methods
      .withdrawGem(vaultAuthBump, gemBoxBump, GDRBump, gemRarityBump, gemAmount)
      .accounts({
        bank,
        vault,
        owner: isKp(farmerIdentity)
          ? (<Keypair>farmerIdentity).publicKey
          : farmerIdentity,
        authority: vaultAuth,
        gemBox,
        gemDepositReceipt: GDR,
        gemDestination,
        gemMint,
        gemRarity,
        receiver,
        tokenProgram: TOKEN_PROGRAM_ID,
        associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
        systemProgram: SystemProgram.programId,
        rent: SYSVAR_RENT_PUBKEY,
      })
      .signers(signers)
      .instruction();

    let tx = new Transaction({
      feePayer: this.wallet.publicKey,
      recentBlockhash: (await this.conn.getLatestBlockhash()).blockhash,
    });
    tx.add(endStakingIx);
    tx.add(endCooldownIx);
    tx.add(withdrawGemIx);

Then, I send the transaction as a bundle.

llomosol commented 2 years ago

@AnderUstarroz remember to update the IDL json files for both gem_bank and gem_farm

AnderUstarroz commented 2 years ago

@dylie-eth, @llomosol thanks, thanks and thanks to both. Knowing those two things were key to make it work again.

Fahad-pnw commented 2 years ago

@dylie-eth could you share the updated code as well, we're at a loss figuring how to combine the tx in the latest commit.

Fahad-pnw commented 2 years ago

@AnderUstarroz could you share the latest implementation, if you have it figured?