-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path4.deployAirdropSepolia.ts
91 lines (79 loc) · 4.27 KB
/
4.deployAirdropSepolia.ts
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
// Declare/Deploy a demo of Airdrop contract
// Coded with Starknet.js v6.9.0
// launch with npx ts-node src/scripts/merkleTree/airdropSJS6Sepolia/4.deployAirdropSepolia.ts
import { Account, json, Contract, RpcProvider, RPC, Call, Calldata, CallData, shortString, constants } from "starknet";
import { account0OZSepoliaAddress, account0OZSepoliaPrivateKey } from "../../../A1priv/A1priv";
import { infuraKey, account1MainnetAddress, account1MainnetPrivateKey, blastKey } from "../../../A-MainPriv/mainPriv";
import * as dotenv from "dotenv";
import fs from "fs";
dotenv.config();
async function main() {
// initialize Provider. Adapt to your needs
// Starknet-devnet-rs
// const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });
// **** Sepolia Testnet :
const provider = new RpcProvider({ nodeUrl: "https://free-rpc.nethermind.io/sepolia-juno/v0_7" });
// Check that communication with provider is OK
const ch = await provider.getChainId();
console.log("chain Id =", shortString.decodeShortString(ch), ", rpc", await provider.getSpecVersion());
// initialize account. Adapt to your case
// *** Devnet-rs
// const privateKey0 = "0x71d7bb07b9a64f6f78ac4c816aff4da9";
// const accountAddress0: string = "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691";
// *** initialize existing Sepolia Testnet account
const privateKey0 = account0OZSepoliaPrivateKey;
const accountAddress0 = account0OZSepoliaAddress;
// *** initialize existing Argent X mainnet account
// const privateKey0 = account1MainnetPrivateKey;
// const accountAddress0 = account1MainnetAddress
// *** initialize existing Sepolia Integration account
// const privateKey0 = account1IntegrationOZprivateKey;
// const accountAddress0 = account1IntegrationOZaddress;
const account0 = new Account(provider, accountAddress0, privateKey0);
console.log('existing_ACCOUNT_ADDRESS=', accountAddress0);
console.log('existing account connected.\n');
// declare/deploy Airdrop test
const compiledSierraAirdrop = json.parse(fs.readFileSync("./compiledContracts/cairo240/airdropSJS6.sierra.json").toString("ascii"));
const compiledCasmAirdrop = json.parse(fs.readFileSync("./compiledContracts/cairo240/airdropSJS6.casm.json").toString("ascii"));
// 👇👇👇
// 🚨🚨🚨 Change addresses following execution of scripts src/scripts/merkleTree/airdropSJS6Sepolia/2.deployMerkleVerifySepolia.ts
const ERC20_ADDRESS = "0x998bec0c912e4257bf87719bf6af2575ccebcd00fd284b8044d1e14fc30ce9";
const MERKLE_VERIF_ADDRESS = "0x14877859e56be2beca0a332e169dc6bfbbfcf6bc3ab7fe33759794114efa2ff";
// 👆👆👆
console.log('In progress...');
const myCallAirdrop = new CallData(compiledSierraAirdrop.abi);
const myConstructorAirdrop: Calldata = myCallAirdrop.compile("constructor", {
erc20_address: ERC20_ADDRESS,
merkle_address: MERKLE_VERIF_ADDRESS,
erc20_owner: account0.address,
start_time: 0, // no date of airdrop start
consolation_remaining: 20_000,
});
const deployResponse = await account0.declareAndDeploy({
contract: compiledSierraAirdrop,
casm: compiledCasmAirdrop,
constructorCalldata: myConstructorAirdrop
});
const airdropAddress = deployResponse.deploy.contract_address;
const airdropClassHash = deployResponse.declare.class_hash;
console.log("Airdrop contract :");
console.log("class_hash =", airdropClassHash);
console.log("address =", airdropAddress);
// authorize the Airdrop contract to transfer some tokens
const compiledSierraERC20 = json.parse(fs.readFileSync("compiledContracts/cairo220/erc20OZ070.sierra.json").toString("ascii"));
const erc20Contract = new Contract(compiledSierraERC20.abi, ERC20_ADDRESS, account0);
const authorize: Call = erc20Contract.populate("approve", {
spender: airdropAddress,
amount: 40_000,
});
const tx = await account0.execute(authorize);
const txR = await provider.waitForTransaction(tx.transaction_hash);
console.log("Correctly deployed =",txR.isSuccess());
console.log("✅ test completed.");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});