-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwithdraw_remaining_quote.ts
More file actions
60 lines (51 loc) · 1.7 KB
/
withdraw_remaining_quote.ts
File metadata and controls
60 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { clusterApiUrl, Connection, Keypair, PublicKey } from "@solana/web3.js";
import { BN } from "bn.js";
import fs from "fs";
import os from "os";
import { PRESALE_PROGRAM_ID } from "../src";
import Presale from "../src/presale";
const connection = new Connection(clusterApiUrl("devnet"));
async function withdrawRemainingQuote(
connection: Connection,
presaleAddress: PublicKey,
user: Keypair
) {
const presaleInstance = await Presale.create(
connection,
presaleAddress,
PRESALE_PROGRAM_ID
);
const escrows = await presaleInstance.getPresaleEscrowByOwner(user.publicKey);
const withdrawTxs = await Promise.all(
escrows.map(async (escrow) => {
const escrowAccount = escrow.getEscrowAccount();
return presaleInstance.withdrawRemainingQuote({
owner: escrowAccount.owner,
registryIndex: new BN(escrowAccount.registryIndex),
});
})
);
await Promise.all(
withdrawTxs.map(async (withdrawTx) => {
withdrawTx.sign(user);
const txSig = await connection.sendRawTransaction(withdrawTx.serialize());
console.log("Withdraw remaining quote transaction sent:", txSig);
await connection.confirmTransaction(
{
signature: txSig,
lastValidBlockHeight: withdrawTx.lastValidBlockHeight,
blockhash: withdrawTx.recentBlockhash,
},
"finalized"
);
})
);
}
const keypairFilepath = `${os.homedir()}/.config/solana/id.json`;
const keypair = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync(keypairFilepath, "utf-8")))
);
const presaleAddress = new PublicKey(
"2Hw4PgTbU6kp2zmfqgJpdjts4ojap1ob7D2gUzpfzzR1"
);
withdrawRemainingQuote(connection, presaleAddress, keypair);