-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ts sdk existing fn use v2 endpoint
- Loading branch information
1 parent
b65bd20
commit 9217626
Showing
7 changed files
with
3,978 additions
and
2,226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
addExtraAccountMetasForExecute, | ||
createTransferCheckedInstruction, | ||
getTransferHook, | ||
TOKEN_PROGRAM_ID, | ||
unpackMint, | ||
} from "@solana/spl-token"; | ||
import { AccountInfo, Connection, PublicKey } from "@solana/web3.js"; | ||
|
||
export async function getExtraAccountMetasForTransferHook( | ||
connection: Connection, | ||
mintAddress: PublicKey, | ||
mintAccountInfo: AccountInfo<Buffer> | ||
) { | ||
const mintState = unpackMint( | ||
mintAddress, | ||
mintAccountInfo, | ||
mintAccountInfo.owner | ||
); | ||
|
||
if (mintAccountInfo.owner.equals(TOKEN_PROGRAM_ID)) { | ||
return []; | ||
} | ||
|
||
const transferHook = getTransferHook(mintState); | ||
|
||
if (!transferHook) { | ||
return []; | ||
} else { | ||
// We just need the instruction, therefore we do not need source and destination key | ||
const instruction = createTransferCheckedInstruction( | ||
PublicKey.default, | ||
mintAddress, | ||
PublicKey.default, | ||
PublicKey.default, | ||
BigInt(0), | ||
mintState.decimals, | ||
[], | ||
mintAccountInfo.owner | ||
); | ||
|
||
await addExtraAccountMetasForExecute( | ||
connection, | ||
instruction, | ||
transferHook.programId, | ||
PublicKey.default, | ||
mintAddress, | ||
PublicKey.default, | ||
PublicKey.default, | ||
BigInt(0) | ||
); | ||
|
||
// Only 4 keys needed if it's single signer. https://github.com/solana-labs/solana-program-library/blob/d72289c79a04411c69a8bf1054f7156b6196f9b3/token/js/src/extensions/transferFee/instructions.ts#L251 | ||
return instruction.keys.slice(4); | ||
} | ||
} |
Oops, something went wrong.