forked from Zebec-protocol/zebec-program-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
59 lines (48 loc) · 2.45 KB
/
token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { PublicKey,Keypair } from '@solana/web3.js';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import { SlowBuffer } from 'buffer';
import { fromPairs } from 'lodash';
const crypto = require('crypto');
const SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID: PublicKey = new PublicKey(
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
);
async function findAssociatedTokenAddress(
walletAddress: PublicKey,
tokenMintAddress: PublicKey
): Promise<PublicKey> {
return (await PublicKey.findProgramAddress(
[
walletAddress.toBuffer(),
TOKEN_PROGRAM_ID.toBuffer(),
tokenMintAddress.toBuffer(),
],
SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
))[0];
}
async function main() {
const wallet: PublicKey = new PublicKey(
'BRywkBvwea9Szf41YY1rsRKeBVxjxe7aoFPX5d2bRiVD') // sender/recipient address
const wallet2: PublicKey = new PublicKey(
'7ZJvFw9M7kQh2evUyAGTdKVyucZjb51yLxPXExaBMERy'); //token address
console.log( await (await findAssociatedTokenAddress(wallet,wallet2)).toBase58()) //
}
async function pda_seed() {
const wallet: PublicKey = new PublicKey(
'ErAykG8kXqpAjGGWbZ9BuQMq7j5SEk9fhrXV8JRpysx4') // sender/recipient address
const wallet2: PublicKey = new PublicKey(
'2ibSirDWk5P68ZKmQQSxUMtiWQFRuanpPfMfaYzxgSRv'); //token address
let address = new PublicKey("J75jd3kjsABQSDrEdywcyhmbq8eHDowfW9xtEWsVALy9"); // sender address
console.log(address)
let recipient = new PublicKey("BvNbvbaE6NKdGXMYK3Vtrosq46vdxDwif4SJ9qLzEJ7b"); // sender address
let base58publicKey = new PublicKey('7FNWTfCo3AyRBFCvr49daqKHehdn2GjNgpjuTsqy5twk'); // program address
let base58publicKeyspl =new PublicKey ("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
let sender_recipientw = await PublicKey.findProgramAddress([wallet.toBuffer(),base58publicKeyspl.toBuffer(),wallet2.toBuffer()], SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID);
let validProgramAddress = await PublicKey.findProgramAddress([address.toBuffer()], base58publicKey);
let sender_recipient = await PublicKey.findProgramAddress([address.toBuffer(),recipient.toBuffer()], base58publicKey);
let stringofwithdraw = "withdraw_sol"
let withdraw_data = await PublicKey.findProgramAddress([Buffer.from(stringofwithdraw),address.toBuffer()], base58publicKey);
console.log(`Master PDA: `+validProgramAddress);
console.log(`withdraw_data `+withdraw_data);
}
main()
// pda_seed()