-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adding Solana support #122
Conversation
async sendWithPriorityFees( | ||
transaction: Transaction, | ||
keyPair: Keypair, | ||
feeLevel: PriorityFeeLevels = 'medium' | ||
) { | ||
// eslint-disable-next-line prefer-const | ||
let [computeUnitPriceInstruction, units, recentBlockhash] = | ||
await Promise.all([ | ||
this.createDynamicPriorityFeeInstruction(feeLevel), | ||
this.getSimulationUnits( | ||
this.connection, | ||
transaction.instructions, | ||
keyPair.publicKey | ||
), | ||
this.connection.getLatestBlockhash(), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue is that your simulation did not include the priority fee instruction…so it’s returning too few compute units. If you fetch the priority fee before the simulation and pass it into your simulation transaction it works:
async sendWithPriorityFees( | |
transaction: Transaction, | |
keyPair: Keypair, | |
feeLevel: PriorityFeeLevels = 'medium' | |
) { | |
// eslint-disable-next-line prefer-const | |
let [computeUnitPriceInstruction, units, recentBlockhash] = | |
await Promise.all([ | |
this.createDynamicPriorityFeeInstruction(feeLevel), | |
this.getSimulationUnits( | |
this.connection, | |
transaction.instructions, | |
keyPair.publicKey | |
), | |
this.connection.getLatestBlockhash(), | |
]); | |
async sendWithPriorityFees( | |
transaction: Transaction, | |
keyPair: Keypair, | |
feeLevel: PriorityFeeLevels = 'medium' | |
) { | |
const computeUnitPriceInstruction = await this.createDynamicPriorityFeeInstruction(feeLevel); | |
const allInstructions = [...transaction.instructions, computeUnitPriceInstruction]; | |
// eslint-disable-next-line prefer-const | |
let [units, recentBlockhash] = | |
await Promise.all([ | |
this.getSimulationUnits( | |
this.connection, | |
allInstructions, | |
keyPair.publicKey | |
), | |
this.connection.getLatestBlockhash(), | |
]); |
if (units) { | ||
units = Math.ceil(units * 1.05); // margin of error | ||
transaction.add(ComputeBudgetProgram.setComputeUnitLimit({ units })); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnpmitsch I'm wondering if insteading of (or maybe in addition) this being a sendSmartTransaction
it's assembleSmartTransaction
(or something like that), where we return the new Transaction
object instead of sending it to the network.
the benefit here is that many circumstances, you're dealing w/ a wallet, not a keypair. In that case, I think it might be more useful to be able to pass in my instructions (or transaction) and return the smart transaction...then I can sign/send with my wallet adapter.
WDYT?
} from './types'; | ||
|
||
export class Solana { | ||
readonly endpointUrl: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason this shouldn't be private?
const computeUnitPriceInstruction = | ||
await this.createDynamicPriorityFeeInstruction(feeLevel); | ||
const testInstructions = [...instructions, computeUnitPriceInstruction]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need this since you pass allInstructionsn
const computeUnitPriceInstruction = | |
await this.createDynamicPriorityFeeInstruction(feeLevel); | |
const testInstructions = [...instructions, computeUnitPriceInstruction]; | |
const testInstructions = instructions, computeUnitPriceInstruction; |
*/ | ||
async prepareSmartTransaction(args: PrepareSmartTransactionArgs) { | ||
const { transaction, payerPublicKey, feeLevel = 'medium' } = args; | ||
const computeUnitPriceInstruction = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any risk that these values go stale while we process the rest of the function?
If the user doesn't have the add-on installed: