-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairdrop.js
141 lines (124 loc) · 5.08 KB
/
airdrop.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const { calculateFee, GasPrice, StargateClient } = require("@cosmjs/stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const _ = require("fs");
const { rpcEndpoint, sender } = require("./common");
async function UploadAirdropContract() {
const airdropWasm = "./wasms/airdrop.wasm";
const gasPrice = GasPrice.fromString("0.05ubluechip");
// Upload contract
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const wasm = await _.readFileSync(airdropWasm);
const uploadFee = await calculateFee(2_500_0000, gasPrice);
const uploadVault = await sender_client.upload(sender.address, wasm, uploadFee, "Upload airdrop contract");
console.log("Upload succeeded. Receipt:", uploadVault);
return uploadVault.codeId;
}
async function InstantiateAirdropContract(codeId, total_whitelist_wallets, eligible_wallets, airdrop_amount) {
// // Instantiate
const gasPrice = GasPrice.fromString("0.05ubluechip");
const instantiateFee = calculateFee(500_000, gasPrice);
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const initMsg = {
"total_whitelist_wallets": total_whitelist_wallets,
"eligible_wallets": eligible_wallets,
"airdrop_amount": airdrop_amount,
};
const { contractAddress } = await sender_client.instantiate(
sender.address,
codeId,
initMsg,
"Airdrop contract",
instantiateFee,
{ memo: `Create a airdrop contract instance` },
);
console.info(`Contract instantiated at: `, contractAddress);
return contractAddress;
}
async function QueryConfig(contractAddress) {
// Upload contract
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const config = await sender_client.queryContractSmart(contractAddress,
{
config: {}
})
console.info(`Aidrop config: `, config);
return config;
}
async function QueryIsWhitelisted(contractAddress, address) {
// Upload contract
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const isWhitelisted = await sender_client.queryContractSmart(contractAddress,
{
is_whitelisted: { address: address }
})
console.info(`Aidrop isWhitelisted: `, isWhitelisted);
return isWhitelisted;
}
async function QueryIsClaimed(contractAddress, address) {
// Upload contract
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const isClaimed = await sender_client.queryContractSmart(contractAddress,
{
is_claimed: { address: address }
})
console.info(`Aidrop is claimed: `, isClaimed);
return isClaimed;
}
async function ExecuteStart(contractAddress) {
const gasPrice = GasPrice.fromString("0.05ubluechip");
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const executeFee = calculateFee(300_000, gasPrice);
const msg = {
start: {
},
};
const create_result = await sender_client.execute(
sender.address,
contractAddress,
msg,
executeFee,
"",
);
console.log("Airdrop started", create_result)
}
async function ExecuteClaim(contractAddress) {
const gasPrice = GasPrice.fromString("0.05ubluechip");
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(sender.mnemonic, { prefix: "bluechip" });
const sender_client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, sender_wallet);
const executeFee = calculateFee(300_000, gasPrice);
const msg = {
claim: {
},
};
const create_result = await sender_client.execute(
sender.address,
contractAddress,
msg,
executeFee,
"",
);
console.log("Airdrop claimed", create_result)
}
async function QueryBalance(address) {
const client = await StargateClient.connect(rpcEndpoint)
const balance = await client.getAllBalances(address)
console.info(`BCP balance: `, balance);
return balance;
}
module.exports = {
UploadAirdropContract,
InstantiateAirdropContract,
QueryConfig,
QueryIsWhitelisted,
QueryIsClaimed,
QueryBalance,
ExecuteStart,
ExecuteClaim,
};