Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request 1M compute units in transfer remote #2771

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion typescript/token/src/adapters/SealevelTokenAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@solana/spl-token';
import {
AccountMeta,
ComputeBudgetProgram,
Keypair,
PublicKey,
SystemProgram,
Expand Down Expand Up @@ -153,6 +154,14 @@ export class SealevelTokenAdapter
}
}

// The compute limit to set for the transfer remote instruction.
// This is typically around ~160k, but can be higher depending on
// the index in the merkle tree, which can result in more moderately
// more expensive merkle tree insertion.
// Because a higher compute limit doesn't increase the fee for a transaction,
// we generously request 1M units.
const TRANSFER_REMOTE_COMPUTE_LIMIT = 1_000_000;

export abstract class SealevelHypTokenAdapter
extends SealevelTokenAdapter
implements IHypTokenAdapter
Expand Down Expand Up @@ -271,15 +280,24 @@ export abstract class SealevelHypTokenAdapter
]),
});

const setComputeLimitInstruction = ComputeBudgetProgram.setComputeUnitLimit(
{
units: TRANSFER_REMOTE_COMPUTE_LIMIT,
},
);

const recentBlockhash = (
await this.getProvider().getLatestBlockhash('finalized')
).blockhash;

// @ts-ignore Workaround for bug in the web3 lib, sometimes uses recentBlockhash and sometimes uses blockhash
const tx = new Transaction({
feePayer: fromWalletPubKey,
blockhash: recentBlockhash,
recentBlockhash,
}).add(transferRemoteInstruction);
})
.add(setComputeLimitInstruction)
.add(transferRemoteInstruction);
tx.partialSign(randomWallet);
return tx;
}
Expand Down