-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathsyncNative.ts
More file actions
27 lines (22 loc) · 868 Bytes
/
syncNative.ts
File metadata and controls
27 lines (22 loc) · 868 Bytes
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
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { TokenInstruction } from "./instruction";
const BufferLayout = require("buffer-layout");
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]);
/**
* Construct a SyncNative instruction
*
* @param account Native account to sync lamports from
* @param programId SPL Token program account
*
* @return Instruction to add to a transaction
*/
export function syncNative(
account: PublicKey,
programId = TOKEN_PROGRAM_ID
): TransactionInstruction {
const keys = [{ pubkey: account, isSigner: false, isWritable: true }];
const data = Buffer.alloc(dataLayout.span);
dataLayout.encode({ instruction: TokenInstruction.SyncNative }, data);
return new TransactionInstruction({ keys, programId, data });
}