-
Notifications
You must be signed in to change notification settings - Fork 0
/
VndesCoin.js
109 lines (93 loc) · 2.93 KB
/
VndesCoin.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
const hre = require("hardhat");
const crypto = require("crypto");
const ethers = hre.ethers;
const {
AxelarQueryAPI,
Environment,
EvmChain,
GasToken,
} = require("@axelar-network/axelarjs-sdk");
const interchainTokenServiceContractABI = require("./utils/interchainTokenServiceABI");
const interchainTokenFactoryContractABI = require("./utils/interchainTokenFactoryABI");
const interchainTokenContractABI = require("./utils/interchainTokenABI");
const interchainTokenServiceContractAddress =
"0x8972f3CD9A3EFfD947398C4761e3Bd156C2F3d76";
const interchainTokenFactoryContractAddress = "0xd6ba705da1713f66925c46ebb9f6a9548c9e4213";
//const interchainTokenFactoryContractAddress = "0x6A91b9bC4D585c38cAa16962C3fCf27C0cDE828c";
async function getSigner() {
const [signer] = await ethers.getSigners();
return signer;
}
async function getContractInstance(contractAddress, contractABI, signer) {
return new ethers.Contract(contractAddress, contractABI, signer);
}
// Register and deploy a new interchain token to the Fantom testnet
async function registerAndDeploy() {
// Generate random salt
const salt = "0x" + crypto.randomBytes(32).toString("hex");
// Create a new token
const name = "VNDES";
const symbol = "VDE";
const decimals = 18;
// Intial token supply
const initialSupply = ethers.utils.parseEther("300000000");
// Get a signer to sign the transaction
const signer = await getSigner();
// Create contract instances
const interchainTokenFactoryContract = await getContractInstance(
interchainTokenFactoryContractAddress,
interchainTokenFactoryContractABI,
signer
);
const interchainTokenServiceContract = await getContractInstance(
interchainTokenServiceContractAddress,
interchainTokenServiceContractABI,
signer
);
// Generate a unique token ID using the signer's address and salt
const tokenId = await interchainTokenFactoryContract.interchainTokenId(
signer.address,
salt
);
// Retrieve new token address
const tokenAddress =
await interchainTokenServiceContract.interchainTokenAddress(tokenId);
// Retrieve token manager address
const expectedTokenManagerAddress =
await interchainTokenServiceContract.tokenManagerAddress(tokenId);
// Deploy new Interchain Token
const deployTxData =
await interchainTokenFactoryContract.deployInterchainToken(
salt,
name,
symbol,
decimals,
initialSupply,
signer.address
);
console.log(
`
Deployed Token ID: ${tokenId},
Token Address: ${tokenAddress},
Transaction Hash: ${deployTxData.hash},
salt: ${salt},
Expected Token Manager Address: ${expectedTokenManagerAddress},
`
);
}
async function main() {
const functionName = process.env.FUNCTION_NAME;
switch (functionName) {
case "registerAndDeploy":
await registerAndDeploy();
break;
default:
console.error(`Unknown function: ${functionName}`);
process.exitCode = 1;
return;
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});