SDK for Mantle OFT Solana program, providing sendWithdraw functionality
npm install mantlexyz-oft-solana-sdkSDK for Mantle OFT Solana program, providing sendWithdraw functionality to handle pending message withdrawals.
``bash`
npm install mantlexyz-oft-solana-sdkor
pnpm add mantlexyz-oft-solana-sdk
`typescript
import { sendWithdraw, findPendingMessagePda, fetchPendingMessage } from "mantlexyz-oft-solana-sdk";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { createSignerFromKeypair, signerIdentity } from "@metaplex-foundation/umi";
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
import { Keypair } from "@solana/web3.js";
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { transactionBuilder, publicKey } from "@metaplex-foundation/umi";
const umi = createUmi("https://api.mainnet-beta.solana.com");
// Setup signer
const keypair = Keypair.fromSecretKey(/ your keypair /);
const umiKeypair = fromWeb3JsKeypair(keypair);
const signer = createSignerFromKeypair(umi, umiKeypair);
umi.use(signerIdentity(signer));
// Define program IDs
const oftProgramId = publicKey("YOUR_OFT_PROGRAM_ID");
const tokenProgramId = publicKey(TOKEN_PROGRAM_ID.toBase58());
// Define accounts
const oftStore = publicKey("YOUR_OFT_STORE_PDA");
const tokenMint = publicKey("YOUR_TOKEN_MINT");
const tokenEscrow = publicKey("YOUR_TOKEN_ESCROW");
const guid = new Uint8Array(32); // GUID from pending message
// Find pending message PDA
const [pendingMessagePda] = findPendingMessagePda(
oftStore,
guid,
oftProgramId
);
// Fetch pending message to get creator
const pendingMessage = await fetchPendingMessage(
umi,
pendingMessagePda,
oftProgramId
);
if (!pendingMessage) {
throw new Error("Pending message not found");
}
// Build sendWithdraw instruction
const sendWithdrawIx = await sendWithdraw(
umi.rpc,
{
payer: signer.publicKey,
tokenMint,
tokenEscrow,
oftStore,
pendingMessage: pendingMessagePda,
creator: publicKey(pendingMessage.creator.toBase58()),
},
{
guid,
dstEid: 30110, // Destination EID
to: new Uint8Array(32), // Recipient address (32 bytes)
amountLd: 1000000n,
minAmountLd: 950000n,
options: new Uint8Array(),
composeMsg: undefined,
nativeFee: 1000000n,
lzTokenFee: 0n,
},
{
oft: oftProgramId,
token: tokenProgramId,
}
);
// Build and send transaction
const txBuilder = transactionBuilder()
.add(sendWithdrawIx);
const result = await txBuilder.sendAndConfirm(umi, {
confirm: { commitment: "confirmed" },
});
`
Builds a sendWithdraw instruction for the Mantle OFT program.
#### Parameters
- rpc: RPC connectionaccounts
- : Account informationpayer
- : The payer/signertokenMint
- : Token mint addresstokenEscrow
- : Token escrow addressoftStore
- : OFT store PDApendingMessage
- : Pending message PDAcreator
- : Creator of the pending message (executor from lz_receive)params
- : Send withdraw parametersguid
- : The GUID of the pending message (32 bytes)dstEid
- : Destination endpoint IDto
- : Recipient address (32 bytes)amountLd
- : Amount in local decimalsminAmountLd
- : Minimum amount to receiveoptions
- : LayerZero optionscomposeMsg
- : Optional compose messagenativeFee
- : Native feelzTokenFee
- : LZ token feeprogramIds
- : Program IDsoft
- : OFT program IDtoken
- : Token program ID
#### Returns
A UMI instruction that can be added to a transaction builder.
Finds the PDA for a pending message account.
#### Parameters
- oftStore: OFT store PDAguid
- : GUID of the pending message (32 bytes)programId
- : OFT program ID
#### Returns
[pda, bump] tuple
Fetches a pending message account from the blockchain.
#### Parameters
- umi: UMI instancependingMessagePda
- : Pending message PDAprogramId
- : OFT program ID
#### Returns
Pending message account data or null` if not found
ISC