-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* solana signing * Fix code style issues with Prettier * chore: branch cut release for sdk v2.8.27-beta.0 (#345) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix code style issues with Prettier * chore: branch cut release for sdk v2.8.27-beta.1 (#349) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * skip failing test --------- Co-authored-by: Lint Action <lint-action@samuelmeuli.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: pilot <8565879+odcey@users.noreply.github.com> Co-authored-by: jmd3v <juan.villarraza@gmail.com>
- Loading branch information
1 parent
af31018
commit 994dd8a
Showing
8 changed files
with
496 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./evm"; | ||
export * from "./cosmos"; | ||
export * from "./solana"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Wallet, web3 } from "@project-serum/anchor"; | ||
import { Connection, VersionedTransaction } from "@solana/web3.js"; | ||
import { ExecuteRoute, OnChainExecutionData, SolanaSigner, SolanaTxResponse } from "types"; | ||
|
||
export class SolanaHandler { | ||
async executeRoute({ data }: { data: ExecuteRoute }): Promise<SolanaTxResponse> { | ||
const { route } = data; | ||
const signer = data.signer as SolanaSigner; | ||
|
||
const connection = new Connection(web3.clusterApiUrl("mainnet-beta"), "confirmed"); | ||
|
||
// currently we support signing only for Jupiter | ||
const swapRequest = (route.transactionRequest! as OnChainExecutionData).data; | ||
|
||
// build tx object | ||
const swapTransactionBuf = Buffer.from(swapRequest, "base64"); | ||
let transaction = VersionedTransaction.deserialize(swapTransactionBuf); | ||
|
||
let tx: string; | ||
|
||
// sign tx using provided signer | ||
if (signer instanceof Wallet || signer.constructor.name === "NodeWallet") { | ||
// offline signer | ||
const wallet = signer as Wallet; | ||
transaction.sign([wallet.payer]); | ||
|
||
// send tx onchain | ||
const rawTransaction = transaction.serialize(); | ||
const txid = await connection.sendRawTransaction(rawTransaction, { | ||
skipPreflight: true, | ||
maxRetries: 2, | ||
}); | ||
|
||
// verify tx was broadcasted | ||
const latestBlockHash = await connection.getLatestBlockhash(); | ||
await connection.confirmTransaction({ | ||
blockhash: latestBlockHash.blockhash, | ||
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight + 10, | ||
signature: txid, | ||
}); | ||
|
||
tx = txid; | ||
} else { | ||
// phantom wallet signer | ||
const { signature } = signer.signAndSendTransaction(transaction); | ||
await connection.getSignatureStatus(signature, { searchTransactionHistory: true }); | ||
|
||
tx = signature; | ||
} | ||
|
||
return { tx }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.