-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update browser wallet for Whirlpools SDK (#182)
# Pull Request Description ## Related Issue Fixes # (issue number) ## Changes Made This PR adds the following changes: - Created a custom Wallet class to support browser use of Orca tools ## Transaction executed by agent Example transaction: https://solscan.io/tx/GNmgxM4ZRHURDWcgmhLmBrSG5RgF9yw5B4jzEXzWX2jpNvCbUsQyaMdkkH77au7pisJ89hJdrcs8dv54U8H3J8V?cluster=devnet ## Prompt Used Using Devnet ``` i want to open a single sided position in pool 7MghXMotsf9CLr6Z9obV8g9Kt2y1Mqn6wXm2mdPhRnMe ``` then provide details ## Additional Notes ## Checklist - [x] I have tested these changes locally - [ ] I have updated the documentation - [x] I have added a transaction link - [x] I have added the prompt used to test it
- Loading branch information
Showing
7 changed files
with
175 additions
and
136 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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,7 +1,35 @@ | ||
import { Keypair } from "@solana/web3.js"; | ||
import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js"; | ||
import bs58 from "bs58"; | ||
|
||
export const keypair = Keypair.generate(); | ||
|
||
console.log(keypair.publicKey.toString()); | ||
console.log(bs58.encode(keypair.secretKey)); | ||
|
||
|
||
export class Wallet { | ||
private _signer: Keypair; | ||
|
||
constructor(signer: Keypair) { | ||
this._signer = signer; | ||
} | ||
|
||
async signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T> { | ||
if (tx instanceof Transaction) { | ||
tx.sign(this._signer); | ||
} else if (tx instanceof VersionedTransaction) { | ||
tx.sign([this._signer]); | ||
} else { | ||
throw new Error("Unsupported transaction type"); | ||
} | ||
return tx; | ||
} | ||
|
||
async signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]> { | ||
return Promise.all(txs.map((tx) => this.signTransaction(tx))); | ||
} | ||
|
||
get publicKey(): PublicKey { | ||
return this._signer.publicKey; | ||
} | ||
} |