-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclaim.ts
More file actions
63 lines (53 loc) · 1.61 KB
/
claim.ts
File metadata and controls
63 lines (53 loc) · 1.61 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
61
62
63
import { clusterApiUrl, Connection, Keypair, PublicKey } from "@solana/web3.js";
import fs from "fs";
import os from "os";
import { PRESALE_PROGRAM_ID } from "../src";
import Presale from "../src/presale";
import { BN } from "bn.js";
const connection = new Connection(clusterApiUrl("devnet"));
async function claim(
connection: Connection,
presaleAddress: PublicKey,
user: Keypair
) {
const presaleInstance = await Presale.create(
connection,
presaleAddress,
PRESALE_PROGRAM_ID
);
const escrows = await presaleInstance.getPresaleEscrowByOwner(
keypair.publicKey
);
const claimTxs = await Promise.all(
escrows.map((escrow) => {
const escrowState = escrow.getEscrowAccount();
return presaleInstance.claim({
owner: escrowState.owner,
registryIndex: new BN(escrowState.registryIndex),
});
})
);
await Promise.all(
claimTxs.map(async (claimTx) => {
claimTx.sign(user);
const txSig = await connection.sendRawTransaction(claimTx.serialize());
console.log("Claim transaction sent:", txSig);
await connection.confirmTransaction(
{
signature: txSig,
lastValidBlockHeight: claimTx.lastValidBlockHeight,
blockhash: claimTx.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(
"59Av19ft9HjpitcN2VoEXvMiA8nrTh7WvNHVtZRhdaoi"
);
claim(connection, presaleAddress, keypair);