Skip to content

Commit b8b8bac

Browse files
committed
added transfer PDA
1 parent 8589522 commit b8b8bac

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

solana-library/spl_token.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ library SplToken {
8585
tokenProgramId.call{accounts: metas}(instr);
8686
}
8787

88+
/// Transfer @amount token from @from (PDA) to @to. The transaction will be signed by PDA account
89+
function transfer_pda(address pda_token_account, address to, address pda, uint64 amount, bytes bump) internal {
90+
bytes instr = new bytes(9);
91+
92+
instr[0] = uint8(TokenInstruction.Transfer);
93+
instr.writeUint64LE(amount, 1);
94+
95+
AccountMeta[3] metas = [
96+
AccountMeta({pubkey: pda_token_account, is_writable: true, is_signer: false}),
97+
AccountMeta({pubkey: to, is_writable: true, is_signer: false}),
98+
AccountMeta({pubkey: pda, is_writable: false, is_signer: true})
99+
];
100+
tokenProgramId.call{accounts: metas, seeds: [["msq", bump]]}(instr);
101+
}
102+
88103
/// Burn @amount tokens in account. This transaction should be signed by the owner.
89104
///
90105
/// @param account the acount for which tokens should be burned

0 commit comments

Comments
 (0)