hadeswap-sdk
Version:
HadeSwap SDK for interacting with protocol
53 lines (52 loc) • 3.08 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.placeBid = void 0;
const anchor_1 = require("@project-serum/anchor");
const helpers_1 = require("../../helpers");
const constants_1 = require("../../constants");
const common_1 = require("../../../common");
const token_1 = require("@project-serum/anchor/dist/cjs/utils/token");
const placeBid = ({ programId, connection, args, accounts, sendTxn }) => __awaiter(void 0, void 0, void 0, function* () {
const program = (0, helpers_1.returnAnchorProgram)(programId, connection);
const instructions = [];
const [lot, lotSeed] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_1.LOT_PREFIX), accounts.auction.toBuffer(), accounts.nftMint.toBuffer()], program.programId);
const [hadesFundsVault] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_1.HADES_FUNDS_VAULT_PREFIX), accounts.auction.toBuffer()], program.programId);
const userTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.userPubkey, accounts.tokenMint);
const vaultTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(hadesFundsVault, accounts.tokenMint);
const currentWinnerTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.currentWinner, accounts.tokenMint);
instructions.push(yield program.methods
.placeBid(new anchor_1.BN(args.bid))
.accountsStrict({
auction: accounts.auction,
user: accounts.userPubkey,
fundsHadesVault: hadesFundsVault,
currentWinner: accounts.currentWinner,
lot: lot,
nftMint: accounts.nftMint,
tokenMint: accounts.tokenMint,
userTokenAccount: userTokenAccount,
vaultTokenAccount: vaultTokenAccount,
currentWinnerTokenAccount: currentWinnerTokenAccount,
tokenProgram: token_1.TOKEN_PROGRAM_ID,
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
systemProgram: anchor_1.web3.SystemProgram.programId,
rent: anchor_1.web3.SYSVAR_RENT_PUBKEY,
})
.instruction());
const transaction = new anchor_1.web3.Transaction();
for (let instruction of instructions)
transaction.add(instruction);
const signers = [];
yield sendTxn(transaction, signers);
return { instructions, signers };
});
exports.placeBid = placeBid;