Created
January 4, 2023 11:43
-
-
Save 0xPratik/34ffa842c4299cb27f0ab8a02d7141e9 to your computer and use it in GitHub Desktop.
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
import {PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "./token-metadata/src/generated/index" | |
import * as anchor from "@project-serum/anchor"; | |
import { findEscrowPda, findTriflePda } from "./pdas"; | |
import { getAssociatedTokenAddress, TOKEN_PROGRAM_ID ,ASSOCIATED_TOKEN_PROGRAM_ID} from "@solana/spl-token"; | |
import { | |
createTransferOutInstruction, | |
TransferOutInstructionAccounts, | |
TransferOutInstructionArgs, | |
} from "./trifle/src/generated/index"; | |
export const transferOutIx = async( | |
wallet: anchor.Wallet, | |
constraintModel: anchor.web3.PublicKey, | |
babyMint: anchor.web3.PublicKey, | |
mint: anchor.web3.PublicKey, | |
name: string, | |
) => { | |
let [trifleAddress] = await findTriflePda(mint, wallet.publicKey); | |
let [escrowAddress] = await findEscrowPda(mint, 1, trifleAddress); | |
const [babymetadatakey] = await anchor.web3.PublicKey.findProgramAddress( | |
[ | |
Buffer.from("metadata"), | |
TOKEN_METADATA_PROGRAM_ID.toBuffer(), | |
babyMint.toBuffer(), | |
], | |
TOKEN_METADATA_PROGRAM_ID | |
); | |
const [babymasterKey] = await anchor.web3.PublicKey.findProgramAddress( | |
[ | |
Buffer.from("metadata"), | |
TOKEN_METADATA_PROGRAM_ID.toBuffer(), | |
babyMint.toBuffer(), | |
Buffer.from("edition"), | |
], | |
TOKEN_METADATA_PROGRAM_ID | |
); | |
let tokenAccount = await getAssociatedTokenAddress( | |
mint, // mint | |
wallet.publicKey // owner | |
); | |
let babysrc = await getAssociatedTokenAddress( | |
babyMint, | |
wallet.publicKey | |
) | |
console.log("Attribute in wallet",babysrc.toString()); | |
let babydst = await getAssociatedTokenAddress( | |
babyMint, | |
escrowAddress, | |
true | |
) | |
console.log("Attribute in Escrow",babydst.toString()); | |
const [masterKey] = await anchor.web3.PublicKey.findProgramAddress( | |
[ | |
Buffer.from("metadata"), | |
TOKEN_METADATA_PROGRAM_ID.toBuffer(), | |
mint.toBuffer(), | |
Buffer.from("edition"), | |
], | |
TOKEN_METADATA_PROGRAM_ID | |
); | |
const [metadatakey] = await anchor.web3.PublicKey.findProgramAddress( | |
[ | |
Buffer.from("metadata"), | |
TOKEN_METADATA_PROGRAM_ID.toBuffer(), | |
mint.toBuffer(), | |
], | |
TOKEN_METADATA_PROGRAM_ID | |
); | |
const accounts: TransferOutInstructionAccounts ={ | |
systemProgram:anchor.web3.SystemProgram.programId, | |
constraintModel:constraintModel, | |
splToken:TOKEN_PROGRAM_ID, | |
payer:wallet.publicKey, | |
trifleAuthority: wallet.publicKey, | |
trifleAccount:trifleAddress, | |
escrowAccount:escrowAddress, | |
tokenMetadataProgram:TOKEN_METADATA_PROGRAM_ID, | |
escrowMint:mint, | |
escrowTokenAccount:tokenAccount, | |
escrowMetadata:metadatakey, | |
escrowEdition:masterKey, | |
attributeMetadata:babymetadatakey, | |
attributeMint: babyMint, | |
attributeSrcTokenAccount:babydst, | |
attributeDstTokenAccount:babysrc, | |
splAssociatedTokenAccount:ASSOCIATED_TOKEN_PROGRAM_ID, | |
sysvarInstructions:anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY, | |
} | |
const args: TransferOutInstructionArgs = { | |
transferOutArgs:{ | |
amount:1, | |
slot: name | |
} | |
} | |
const ix = createTransferOutInstruction(accounts,args); | |
return ix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment