Skip to content

Commit

Permalink
add ata derivation to solana package
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarshanbhag committed Dec 11, 2024
1 parent 0af04b4 commit 2ba1bbe
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 15 deletions.
Empty file.
3 changes: 2 additions & 1 deletion examples/with-solana/src/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function main() {
const turnkeyWarchest = new PublicKey(TURNKEY_WAR_CHEST);
const organizationId = process.env.ORGANIZATION_ID!;
const connection = solanaNetwork.connect();

const turnkeyClient = new Turnkey({
apiBaseUrl: process.env.BASE_URL!,
apiPublicKey: process.env.API_PUBLIC_KEY!,
Expand All @@ -38,6 +38,7 @@ async function main() {
client: turnkeyClient.apiClient(),
});


let solAddress = process.env.SOLANA_ADDRESS!;
if (!solAddress) {
solAddress = await createNewSolanaWallet(turnkeyClient.apiClient());
Expand Down
14 changes: 0 additions & 14 deletions examples/with-solana/src/utils/deriveAta.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"typecheck": "tsc -p tsconfig.typecheck.json"
},
"dependencies": {
"@solana/spl-token": "^0.4.8",
"@solana/web3.js": "^1.88.1",
"@turnkey/http": "workspace:*",
"@turnkey/sdk-browser": "workspace:*",
Expand Down
19 changes: 19 additions & 0 deletions packages/solana/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import {
assertNonNull,
assertActivityCompleted,
Expand Down Expand Up @@ -131,6 +132,24 @@ export class TurnkeySigner {
return recoveredTransaction;
}

/**
* This function derives a Solana associated token address for a given Solana wallet address, related to a particular token mint address
*
* @param walletAddress string representation of the Solana wallet address (base58 encoded)
* @param mintAddress string representation of the token mint address (base58 encoded)
*/
public getAssociatedTokenAddress(mintAddress: string, walletAddress:string) {
const mintPublicKey = new PublicKey(mintAddress);
const walletPublicKey = new PublicKey(walletAddress);

const associatedTokenAddress = getAssociatedTokenAddressSync(
mintPublicKey,
walletPublicKey
);

return associatedTokenAddress.toString();
}

private async signTransactionImpl(
unsignedTransaction: string,
signWith: string,
Expand Down
50 changes: 50 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2ba1bbe

Please sign in to comment.