holaplex / wonka

GNU Affero General Public License v3.0
8 stars 1 forks source link

Dispense fanout funds #17

Closed echohtp closed 2 years ago

echohtp commented 2 years ago

Problem

Need a crank to dispense fanout funds to member wallets

Solution

Will need a mutation endpoint to dispense the funds in a fanout wallet

Example code (from hydra docs)

const member1.publicKey = "Member1.publicKey";
const distributionBot = new Keypair();
// This is the caller of the Distribute method, it can be a bot or a user,
// they just need enough funds to pay for the transaction fee. If you're using
// this code, airdrop a sol to distributionBot.

const mintPublicKey = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC

let distributeToMember1 = await fanoutSdk.distributeWalletMemberInstructions(
    {
        distributeForMint: true,
        member: member1.publicKey,
        fanout: builtFanout.fanout,
        payer: distributionBot.publicKey,
        fanoutMint: mintPublicKey
    },
);

const tx = await fanoutSdk.sendInstructions(
    [...distMember1.instructions],
    [distributionBot],
    distributionBot.publicKey
);
if (!!tx.RpcResponseAndContext.value.err) {
    const txdetails = await connection.getConfirmedTransaction(tx.TransactionSignature);
    console.log(txdetails, tx.RpcResponseAndContext.value.err);
}