Skip to content

Commit

Permalink
allow opts to be passed to sendWait on solana platform
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jan 2, 2024
1 parent bfb7a61 commit 6cc009c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
13 changes: 7 additions & 6 deletions platforms/solana/protocols/tokenBridge/src/tokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Platform,
Chain,
ChainAddress,
ChainId,
Expand Down Expand Up @@ -49,7 +50,6 @@ import {
TransactionInstruction,
} from '@solana/web3.js';

import { Platform } from '@wormhole-foundation/sdk-base/src';
import { TokenBridge as TokenBridgeContract } from './tokenBridgeType';
import {
createApproveAuthoritySignerInstruction,
Expand Down Expand Up @@ -210,6 +210,8 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
payer?: AnySolanaAddress,
): AsyncGenerator<SolanaUnsignedTransaction<N, C>> {
if (!payer) throw new Error('Payer required to create attestation');

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
const senderAddress = new SolanaAddress(payer).unwrap();
// TODO: createNonce().readUInt32LE(0);
const nonce = 0;
Expand All @@ -231,7 +233,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
);

const transaction = new Transaction().add(transferIx, attestIx);
const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
transaction.recentBlockhash = blockhash;
transaction.feePayer = senderAddress;
transaction.partialSign(messageKey);
Expand All @@ -244,9 +245,9 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
payer?: AnySolanaAddress,
): AsyncGenerator<SolanaUnsignedTransaction<N, C>> {
if (!payer) throw new Error('Payer required to create attestation');
const senderAddress = new SolanaAddress(payer).unwrap();

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
const senderAddress = new SolanaAddress(payer).unwrap();

// Yield transactions to verify sigs and post the VAA
yield* this.coreBridge.postVaa(senderAddress, vaa, blockhash);
Expand Down Expand Up @@ -275,7 +276,9 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
): Promise<SolanaUnsignedTransaction<N, C>> {
// https://github.com/wormhole-foundation/wormhole-connect/blob/development/sdk/src/contexts/solana/context.ts#L245

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
const senderAddress = new SolanaAddress(sender).unwrap();

// TODO: the payer can actually be different from the sender. We need to allow the user to pass in an optional payer
const payerPublicKey = senderAddress;

Expand Down Expand Up @@ -362,7 +365,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
payerPublicKey, //authority
);

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
const transaction = new Transaction();
transaction.recentBlockhash = blockhash;
transaction.feePayer = payerPublicKey;
Expand Down Expand Up @@ -393,8 +395,8 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
return;
}

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
const tokenAddress = new SolanaAddress(token).unwrap();

const senderAddress = new SolanaAddress(sender).unwrap();
const senderTokenAddress = await getAssociatedTokenAddress(
tokenAddress,
Expand Down Expand Up @@ -493,7 +495,6 @@ export class SolanaTokenBridge<N extends Network, C extends SolanaChains>
tokenBridgeTransferIx,
);

const { blockhash } = await SolanaPlatform.latestBlock(this.connection);
transaction.recentBlockhash = blockhash;
transaction.feePayer = senderAddress;
transaction.partialSign(message);
Expand Down
21 changes: 12 additions & 9 deletions platforms/solana/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { SolanaChain } from './chain';

import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import {
BlockheightBasedTransactionConfirmationStrategy,
Commitment,
Connection,
ParsedAccountData,
PublicKey,
SendOptions,
} from '@solana/web3.js';
import { SolanaAddress, SolanaZeroAddress } from './address';
import {
Expand Down Expand Up @@ -164,23 +164,26 @@ export class SolanaPlatform<N extends Network> extends PlatformContext<
chain: Chain,
rpc: Connection,
stxns: SignedTx[],
opts?: SendOptions,
): Promise<TxHash[]> {
const { blockhash, lastValidBlockHeight } = await this.latestBlock(rpc);

const txhashes = await Promise.all(
stxns.map((stxn) => {
return rpc.sendRawTransaction(stxn);
return rpc.sendRawTransaction(stxn, opts);
}),
);

await Promise.all(
txhashes.map((txid) => {
const bhs: BlockheightBasedTransactionConfirmationStrategy = {
signature: txid,
blockhash,
lastValidBlockHeight,
};
return rpc.confirmTransaction(bhs, rpc.commitment);
txhashes.map((signature) => {
return rpc.confirmTransaction(
{
signature,
blockhash,
lastValidBlockHeight,
},
rpc.commitment,
);
}),
);

Expand Down

0 comments on commit 6cc009c

Please sign in to comment.