-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve solana transaction sign flow
- Loading branch information
Showing
12 changed files
with
456 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
# @rango-dev/signer-solana | ||
|
||
Signer for Solana Transacations generated by Rango API | ||
## Summary | ||
|
||
Signer for Rango Solana Transactions | ||
|
||
Currecntly all Rango Solana transactions are Versioned (and serialized), only Solana Wrapper is already using the legacy format. (which is used only for SOL <-> WSol routes) | ||
|
||
## Versioned Transaction Sign Flow Overview: | ||
|
||
1. Get connection and recent blockhash | ||
|
||
```ts | ||
const connection = new Connection(SOLANA_RPC_URL, { | ||
commitment: 'confirmed', | ||
disableRetryOnRateLimit: false, | ||
}); | ||
const latestBlock = await connection.getLatestBlockhash('confirmed'); | ||
``` | ||
|
||
2. Prepare the transaction | ||
|
||
```ts | ||
const transaction = VersionedTransaction.deserialize( | ||
new Uint8Array(tx.serializedMessage) | ||
); | ||
transaction.message.recentBlockhash = recentBlockhash; | ||
``` | ||
|
||
3. Simulate the transaction | ||
|
||
```ts | ||
const { value } = await connection.simulateTransaction(transaction, { | ||
replaceRecentBlockhash: true, | ||
commitment: 'processed', | ||
}); | ||
``` | ||
|
||
4. Sign the transaction | ||
|
||
```ts | ||
const signedTransaction = await solanaProvider.signTransaction( | ||
solanaWeb3Transaction | ||
); | ||
const serializedTransaction = Buffer.from(signedTransaction.serialize()); | ||
``` | ||
|
||
5. Send and confirm the transaction (similar to [jupiter suggested code](https://github.com/jup-ag/jupiter-quote-api-node/blob/main/example/utils/transactionSender.ts)) | ||
|
||
````ts | ||
const { txId, txResponse } = await transactionSenderAndConfirmationWaiter({ | ||
connection, | ||
serializedTransaction, | ||
blockhashWithExpiryBlockHeight: { | ||
blockhash: latestBlock.blockhash, | ||
lastValidBlockHeight: latestBlock.lastValidBlockHeight, | ||
}, | ||
}); ``` | ||
```` |
This file was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
export { DefaultSolanaSigner } from './signer'; | ||
export { generalSolanaTransactionExecutor } from './helpers'; | ||
export type { SolanaWeb3Signer } from './helpers'; | ||
export { generalSolanaTransactionExecutor } from './utils'; | ||
export type { SolanaWeb3Signer } from './utils'; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Connection } from '@solana/web3.js'; | ||
|
||
const IS_DEV = !process.env.NODE_ENV || process.env.NODE_ENV === 'development'; | ||
const SOLANA_RPC_URL = !IS_DEV | ||
? 'https://icy-crimson-wind.solana-mainnet.quiknode.pro/c83f94ebeb39a6d6a9d2ab03d4cba2c2af83c5c0/' | ||
: 'https://fluent-still-scion.solana-mainnet.discover.quiknode.pro/fc8be9b8ac7aea382ec591359628e16d8c52ef6a/'; | ||
|
||
export function getSolanaConnection(): Connection { | ||
return new Connection(SOLANA_RPC_URL, { | ||
commitment: 'confirmed', | ||
disableRetryOnRateLimit: false, | ||
}); | ||
} | ||
|
||
export const wait = async (time: number) => | ||
new Promise((resolve) => setTimeout(resolve, time)); |
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,2 @@ | ||
export type { SolanaWeb3Signer, SolanaExternalProvider } from './types'; | ||
export { generalSolanaTransactionExecutor } from './main'; |
Oops, something went wrong.