Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow token transfer -- SPL token policy example #446

Merged
merged 23 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
omkarshanbhag marked this conversation as resolved.
Show resolved Hide resolved
"@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.

Loading