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 12, 2024
1 parent 0af04b4 commit 00100cc
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
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 00100cc

Please sign in to comment.