solmash-whitelist-sdk
Advanced tools
Comparing version 1.0.0-dev.4 to 1.0.0-dev.5
@@ -5,6 +5,7 @@ import { ConfirmOptions, Connection, Signer, Transaction, TransactionSignature, VersionedTransaction } from "@solana/web3.js"; | ||
private readonly _signTransaction; | ||
private readonly _errors; | ||
readonly transaction: Transaction; | ||
readonly signers: Signer[]; | ||
constructor(_connection: Connection, _signTransaction: <T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>, transaction: Transaction, signers: Signer[]); | ||
constructor(_connection: Connection, _signTransaction: <T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>, _errors: Map<number, string>, transaction: Transaction, signers: Signer[]); | ||
execute(options?: ConfirmOptions): Promise<TransactionSignature>; | ||
} |
@@ -8,6 +8,8 @@ "use strict"; | ||
const assert_1 = __importDefault(require("assert")); | ||
const anchor_1 = require("@project-serum/anchor"); | ||
class SolmashWhitelistPayload { | ||
constructor(_connection, _signTransaction, transaction, signers) { | ||
constructor(_connection, _signTransaction, _errors, transaction, signers) { | ||
this._connection = _connection; | ||
this._signTransaction = _signTransaction; | ||
this._errors = _errors; | ||
this.transaction = transaction; | ||
@@ -24,14 +26,25 @@ this.signers = signers; | ||
} | ||
const signed = await this._signTransaction(this.transaction); | ||
const signature = await this._connection.sendRawTransaction(signed.serialize(), options); | ||
console.debug("signature:", signature); | ||
const response = await this._connection.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, options?.commitment); | ||
if (response.value.err) { | ||
throw new Error("Failed to confirm transaction: " + response.value.err.toString()); | ||
try { | ||
const signed = await this._signTransaction(this.transaction); | ||
const signature = await this._connection.sendRawTransaction(signed.serialize(), options); | ||
console.debug("signatue: %s", signature); | ||
const response = await this._connection.confirmTransaction({ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, options?.commitment); | ||
if (response.value.err) { | ||
throw new Error("Failed to confirm transaction: " + response.value.err.toString()); | ||
} | ||
return signature; | ||
} | ||
return signature; | ||
catch (err) { | ||
const translatedError = (0, anchor_1.translateError)(err, this._errors); | ||
if (translatedError) { | ||
(0, assert_1.default)(translatedError instanceof Error, "Translated error is not instanceof Error."); | ||
throw translatedError; | ||
} | ||
console.debug("Throwing error as it is."); | ||
throw err; | ||
} | ||
} | ||
@@ -38,0 +51,0 @@ } |
@@ -45,3 +45,5 @@ "use strict"; | ||
_createPayload(tx, signers) { | ||
return new payload_1.SolmashWhitelistPayload(this._connection, this._signTransaction, tx, signers); | ||
const errorMap = new Map(); | ||
this.instructions.program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg)); | ||
return new payload_1.SolmashWhitelistPayload(this._connection, this._signTransaction, errorMap, tx, signers); | ||
} | ||
@@ -108,2 +110,3 @@ async initAuction(params) { | ||
const creatorBidTokenAccountInfo = await this._connection.getAccountInfo(creatorBidTokenAccount, "confirmed"); | ||
const auctionVaultTokenAccountInfo = await this._connection.getAccountInfo(auctionVaultTokenAccount, "confirmed"); | ||
const ix = await this.instructions.getWithdrawFundsInstruction(auction, auctionBidTokenAccount, auctionToken, auctionVault, auctionVaultTokenAccount, bidToken, creator, createAuctionTokenAccount, creatorBidTokenAccount); | ||
@@ -116,2 +119,5 @@ const { blockhash, lastValidBlockHeight } = await this._connection.getLatestBlockhash(); | ||
}); | ||
if (!auctionVaultTokenAccountInfo) { | ||
tx.add((0, spl_token_1.createAssociatedTokenAccountInstruction)(creator, auctionVaultTokenAccount, auctionVault, auctionToken)); | ||
} | ||
if (!creatorBidTokenAccountInfo) { | ||
@@ -118,0 +124,0 @@ console.info("Creator doesn't have bid token account"); |
{ | ||
"name": "solmash-whitelist-sdk", | ||
"version": "1.0.0-dev.4", | ||
"version": "1.0.0-dev.5", | ||
"description": "A sdk for interacting Solmash Whitelist program", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import assert from "assert"; | ||
import { translateError } from "@project-serum/anchor"; | ||
import { | ||
@@ -18,2 +19,3 @@ ConfirmOptions, | ||
) => Promise<T>, | ||
private readonly _errors: Map<number, string>, | ||
readonly transaction: Transaction, | ||
@@ -37,21 +39,33 @@ readonly signers: Signer[], | ||
const signed = await this._signTransaction(this.transaction); | ||
const signature = await this._connection.sendRawTransaction(signed.serialize(), options); | ||
console.debug("signature:", signature); | ||
try { | ||
const signed = await this._signTransaction(this.transaction); | ||
const signature = await this._connection.sendRawTransaction(signed.serialize(), options); | ||
console.debug("signatue: %s", signature); | ||
const response = await this._connection.confirmTransaction( | ||
{ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, | ||
options?.commitment, | ||
); | ||
const response = await this._connection.confirmTransaction( | ||
{ | ||
signature, | ||
blockhash, | ||
lastValidBlockHeight, | ||
}, | ||
options?.commitment, | ||
); | ||
if (response.value.err) { | ||
throw new Error("Failed to confirm transaction: " + response.value.err.toString()); | ||
if (response.value.err) { | ||
throw new Error("Failed to confirm transaction: " + response.value.err.toString()); | ||
} | ||
return signature; | ||
} catch (err: any) { | ||
const translatedError = translateError(err, this._errors); | ||
if (translatedError) { | ||
assert(translatedError instanceof Error, "Translated error is not instanceof Error."); | ||
throw translatedError; | ||
} | ||
console.debug("Throwing error as it is."); | ||
throw err; | ||
} | ||
return signature; | ||
} | ||
} |
@@ -79,3 +79,12 @@ import assert from "assert"; | ||
private _createPayload(tx: Transaction, signers: Signer[]) { | ||
return new SolmashWhitelistPayload(this._connection, this._signTransaction, tx, signers); | ||
const errorMap: Map<number, string> = new Map(); | ||
this.instructions.program.idl.errors.forEach((error) => errorMap.set(error.code, error.msg)); | ||
return new SolmashWhitelistPayload( | ||
this._connection, | ||
this._signTransaction, | ||
errorMap, | ||
tx, | ||
signers, | ||
); | ||
} | ||
@@ -205,2 +214,7 @@ | ||
const auctionVaultTokenAccountInfo = await this._connection.getAccountInfo( | ||
auctionVaultTokenAccount, | ||
"confirmed", | ||
); | ||
const ix = await this.instructions.getWithdrawFundsInstruction( | ||
@@ -226,2 +240,13 @@ auction, | ||
if (!auctionVaultTokenAccountInfo) { | ||
tx.add( | ||
createAssociatedTokenAccountInstruction( | ||
creator, | ||
auctionVaultTokenAccount, | ||
auctionVault, | ||
auctionToken, | ||
), | ||
); | ||
} | ||
if (!creatorBidTokenAccountInfo) { | ||
@@ -228,0 +253,0 @@ console.info("Creator doesn't have bid token account"); |
import { describe, it } from "mocha"; | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { | ||
@@ -22,3 +20,3 @@ SolmashWhitelistInstructions, | ||
it("fetch auction info", async () => { | ||
const auctionAddress = "5hfr8b9DsqZAQqkzYuvrhwXmRAy2nnCxx429wLWpYwMc"; | ||
const auctionAddress = "74XQPo9bxgX1jEeXWoipBMv1JRJRAZgX8BQbjHyMNfuT"; | ||
const info = await service.getAuctionInfo(auctionAddress); | ||
@@ -28,13 +26,13 @@ console.log({ info }); | ||
it("fetch auction info", async () => { | ||
const auctionAddress = "HMvie46aDzWrXzC5jF7UGRnREiaw7dipnkNsWmxn7kNj"; | ||
const buyerAddress = "Am4Wcw9jiVGe4NHKDbBbgXVKK5WGWsP4688GkSnBuELs"; | ||
const buyerPda = SolmashWhitelistService.deriveBuyerPdaAddress( | ||
new PublicKey(auctionAddress), | ||
new PublicKey(buyerAddress), | ||
program.programId, | ||
); | ||
// it("fetch auction info", async () => { | ||
// const auctionAddress = "HMvie46aDzWrXzC5jF7UGRnREiaw7dipnkNsWmxn7kNj"; | ||
// const buyerAddress = "Am4Wcw9jiVGe4NHKDbBbgXVKK5WGWsP4688GkSnBuELs"; | ||
// const buyerPda = SolmashWhitelistService.deriveBuyerPdaAddress( | ||
// new PublicKey(auctionAddress), | ||
// new PublicKey(buyerAddress), | ||
// program.programId, | ||
// ); | ||
console.log("buyerPda", buyerPda.toString()); | ||
}); | ||
// console.log("buyerPda", buyerPda.toString()); | ||
// }); | ||
}); |
@@ -28,7 +28,7 @@ import { describe } from "mocha"; | ||
const preSaleStartTime = now + 60 * 1; | ||
const preSaleEndTime = preSaleStartTime + 60 * 10; // 1 hour | ||
const preSaleEndTime = preSaleStartTime + 60 * 15; | ||
console.log({ preSaleStartTime }, { preSaleEndTime }); | ||
const auctionTokenAddress = "8CSvK7xceqUeqRaPr91r5kgteXGcWmBL48aoUQCtdizq"; | ||
const bidTokenAddress = "5XZMYTj7vPijMGdRWaYwBVnbrhtpoui2sD4xgbdGNXnB"; | ||
const bidTokenAddress = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc"; | ||
const ownerAddress = provider.publicKey.toString(); | ||
@@ -40,10 +40,10 @@ | ||
auctionTokenAddress, | ||
name: "test_auction_102", | ||
name: "test wl auction 003", | ||
enabled: true, | ||
preSaleEndTime, | ||
preSaleStartTime, | ||
ticketPriceInSobb: "3000", | ||
ticketPriceInSobb: "30", | ||
ticketPriceInSol: "1", | ||
ticketsInPool: "3000", | ||
tokenQuantityPerTicket: "10", | ||
ticketsInPool: "30", | ||
tokenQuantityPerTicket: "100", | ||
}; | ||
@@ -96,5 +96,5 @@ | ||
console.log({ payload }); | ||
// const signature = await payload.execute(); | ||
// console.log({ signature }); | ||
// console.log({ payload }); | ||
const signature = await payload.execute(); | ||
console.log({ signature }); | ||
@@ -101,0 +101,0 @@ const { value: ownerAtaBalAfter } = await connection.getTokenAccountBalance( |
@@ -20,9 +20,10 @@ import { describe } from "mocha"; | ||
it("whitelist user", async () => { | ||
const auctionAddress = "7swu4gk8Fq6M5864F9BmeuwCRmiRfSnun6DHo2VAcEGT"; | ||
const auctionAddress = "74XQPo9bxgX1jEeXWoipBMv1JRJRAZgX8BQbjHyMNfuT"; | ||
const whitelistUserAddressList = [ | ||
getProviders(connection)[1].publicKey.toString(), | ||
getProviders(connection)[2].publicKey.toString(), | ||
"Am4Wcw9jiVGe4NHKDbBbgXVKK5WGWsP4688GkSnBuELs", | ||
"2BZa4yiNfhtSWBPVGKymMq4NtEp86tNjPGbVeVtBtySu", | ||
"CYLyHDqphWVKbgyW87EZYYzZqbmeA8a6RUj5sCPzdYP8", | ||
"2vt1TN4rUHwmDf1XTYTikMFZcNntjkPT28afMwpQcwXk", | ||
"EMHJbXbLd5whgBHsAGJm6m15ZaAS7eq7Xmc2tkaY6KF8", | ||
]; | ||
@@ -29,0 +30,0 @@ |
import { describe } from "mocha"; | ||
import { getAssociatedTokenAddressSync } from "@solana/spl-token"; | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { | ||
@@ -14,3 +11,3 @@ SolmashWhitelistInstructions, | ||
describe("withdrawFunds()", () => { | ||
const connection = getConnection("devnet"); | ||
const connection = getConnection("mainnet-beta"); | ||
const provider = getProviders(connection)[0]; | ||
@@ -25,29 +22,8 @@ const signTransaction = getSignTransaction(provider); | ||
const creatorAddress = provider.publicKey.toString(); | ||
const auctionAddress = "7swu4gk8Fq6M5864F9BmeuwCRmiRfSnun6DHo2VAcEGT"; | ||
const auctionTokenAddress = "8CSvK7xceqUeqRaPr91r5kgteXGcWmBL48aoUQCtdizq"; | ||
const bidTokenAddress = "5XZMYTj7vPijMGdRWaYwBVnbrhtpoui2sD4xgbdGNXnB"; | ||
console.log({ creatorAddress }); | ||
const auctionVault = SolmashWhitelistService.deriveAuctionVaultAddress( | ||
new PublicKey(auctionAddress), | ||
program.programId, | ||
); | ||
const auctionVaultTokenAccount = getAssociatedTokenAddressSync( | ||
new PublicKey(auctionTokenAddress), | ||
auctionVault, | ||
true, | ||
); | ||
const auctionVaultBidTokenAccount = getAssociatedTokenAddressSync( | ||
new PublicKey(bidTokenAddress), | ||
auctionVault, | ||
true, | ||
); | ||
const { value: auctionVaultAtaBal } = | ||
await connection.getTokenAccountBalance(auctionVaultTokenAccount); | ||
const auctionAddress = "HXK6GzgArqSthZdWSnvsAYeWm2Rkv1htQCzxwhXCagvi"; | ||
const auctionTokenAddress = "A1AaPuUirJaCkidfntEPBSgYzg91mPBFeKjrrx342Yux"; | ||
const bidTokenAddress = "KDriegomzHbJDmGkVWFuXrZWfpiruauhMSTg7N6WZvD"; | ||
const { value: auctionVaultBidAtaBal } = await connection.getTokenAccountBalance( | ||
auctionVaultBidTokenAccount, | ||
); | ||
console.log({ auctionVaultAtaBal }, { auctionVaultBidAtaBal }); | ||
const payload = await service.withdrawFunds({ | ||
@@ -54,0 +30,0 @@ creatorAddress, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
179913
69
4724