Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,31 @@ extract.zip
.env
yarn-error.log
polymath-developer-portal

node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts


contract-hardhat/node_modules
contract-hardhat/.env
contract-hardhat/coverage
contract-hardhat/coverage.json
contract-hardhat/typechain
contract-hardhat/typechain-types
contract-hardhat/generated
contract-hardhat/build
contract-hardhat/subgraph/build

# Hardhat files
contract-hardhat/cache
contract-hardhat/artifacts


1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.16.0
41 changes: 35 additions & 6 deletions CLI/commands/common/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ async function addModule (securityToken, polyToken, factoryAddress, moduleABI, g
moduleFactory.setProvider(web3.currentProvider);

const moduleName = web3.utils.hexToUtf8(await moduleFactory.methods.name().call());
const setupCostAction = await moduleFactory.methods.changeSetupCost(0)

await this.sendTransaction(setupCostAction, { factor: 2 });

const moduleFee = new web3.utils.BN(await moduleFactory.methods.setupCostInPoly().call());
let transferAmount = new web3.utils.BN(0);
if (moduleFee.gt(new web3.utils.BN(0))) {
Expand Down Expand Up @@ -40,7 +44,7 @@ async function addModule (securityToken, polyToken, factoryAddress, moduleABI, g
let transferEvent = this.getEventFromLogs(polyToken._jsonInterface, transferReceipt.logs, 'Transfer');
console.log(`Number of POLY sent: ${web3.utils.fromWei(new web3.utils.BN(transferEvent.value))}`);
}
let addModuleAction = securityToken.methods.addModuleWithLabel(factoryAddress, bytes, moduleFee, 0, moduleLabel, addModuleArchived);
let addModuleAction = securityToken.methods.addModuleWithLabel(factoryAddress, bytes, 0, 0, moduleLabel, addModuleArchived);
let receipt = await this.sendTransaction(addModuleAction);
let event = this.getEventFromLogs(securityToken._jsonInterface, receipt.logs, 'ModuleAdded');
console.log(`${moduleName} deployed at address: ${event._module}`);
Expand Down Expand Up @@ -158,10 +162,16 @@ function getFinalOptions(options) {
};

async function getGasLimit(options, action) {
let block = await web3.eth.getBlock('latest');
let networkGasLimit = block.gasLimit;
let gas = Math.round(options.factor * (await action.estimateGas({ from: options.from.address, value: options.value })));
return (gas > networkGasLimit) ? networkGasLimit : gas;
try {
let block = await web3.eth.getBlock('latest');
let networkGasLimit = block.gasLimit;
let gas = Math.round(options.factor * (await action.estimateGas({ from: options.from.address, value: options.value })));
return (gas > networkGasLimit) ? networkGasLimit : gas;
} catch (error) {
console.error('Error getting transaction count:', error);

return 7900000;
}
}

async function checkPermissions(action) {
Expand Down Expand Up @@ -224,15 +234,34 @@ async function selectToken(securityTokenRegistry, tokenSymbol) {
return securityToken;
}

let newNonce = 0;

async function getTransactionCount(address) {
try {
const count = await web3.eth.getTransactionCount(address);

newNonce = count

console.log(`Transaction count for ${address}: ${count}`);
return count;

} catch (error) {
console.error('Error getting transaction count:', error);

return newNonce + 1;
}
}

async function sendTransaction(action, options) {
await checkPermissions(action);

options = getFinalOptions(options);
let gasLimit = await getGasLimit(options, action);
// let gasLimit = 9900000;

console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gasLimit} ----`));

let nonce = await web3.eth.getTransactionCount(options.from.address);
let nonce = await getTransactionCount(options.from.address);
if (nonce < options.minNonce) {
nonce = minNonce;
}
Expand Down
11 changes: 10 additions & 1 deletion CLI/commands/common/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ function getGasPrice(networkId) {
case 15: //Ganache
gasPrice = 50000000000;
break;
case 1337: //Ganache CLI
gasPrice = 50000000000;
break;
case 42: //Kovan
gasPrice = 50000000000;
break;
case 56: // BSC Mainnet
gasPrice = 50000000000;
break;
case 97: // BSC Testnet
gasPrice = 50000000000;
break;
default:
throw new Error('Network ID not identified');
}
Expand Down Expand Up @@ -82,7 +91,7 @@ module.exports = {
Issuer = getAccount(`${__dirname}/../../../keyStore`);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
Issuer = getAccount(`${__dirname}/../../../keyStoreLocal`);
Issuer = getAccount(`${__dirname}/keyStoreLocal`);
}
defaultGasPrice = getGasPrice(await web3.eth.net.getId());
}
Expand Down
5 changes: 4 additions & 1 deletion CLI/commands/helpers/contract_addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ function getPolymathRegistryAddress(networkId) {
case 15: // GANACHE
result = JSON.parse(require('fs').readFileSync(`${__dirname}/../../../build/contracts/PolymathRegistry.json`).toString()).networks[networkId].address;
break;
case 1337: // GANACHE
result = JSON.parse(require('fs').readFileSync(`${__dirname}/../../../build/contracts/PolymathRegistry.json`).toString()).networks[networkId].address;
break;
case 42: // KOVAN
result = "0x5b215a7d39ee305ad28da29bf2f0425c6c2a00b3";
break;
break;
}

return result;
Expand Down
13 changes: 13 additions & 0 deletions contract-hardhat/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Deployment safety-net
# Required for contract deployment
CHAIN_ID=1337

# Required for contract deployment
PROVIDER_URL=http://ganache-cli:8545

# Deployer and initial owner()
# Required for contract deployment
OWNER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
OWNER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

ETHERSCAN_API_KEY=
1 change: 1 addition & 0 deletions contract-hardhat/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.11.1
13 changes: 13 additions & 0 deletions contract-hardhat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.ts
```
42 changes: 42 additions & 0 deletions contract-hardhat/VERIFY_TOKEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Token Contract Verification Guide

## Overview

This guide outlines the steps to verify a token contract using Hardhat.

## Steps

### 1. Set correct solc version

Make sure to use solc version 0.8.17+commit.8df45f5f.Linux.g++

sudo service postgresql stop

### 2. Prepare Arguments

Create a file named `arguments.js` and include the necessary details about the token from the SecurityTokenProxy constructor.

```javascript
module.exports = [
"Test", // _name
"TST", // _symbol
18, // _decimals
"1", // _granularity. Note: If the token divisibility is "true" then it is 1, else it will be 10000000000000000000
"-", // _tokenDetails
"0x81d2d5b63b24826930290362C7F5062DA55DFFD7" // _polymathRegistry. This is currently 0x81d2d5b63b24826930290362C7F5062DA55DFFD7
];
```

### 3. Verify Contract

Run the following command:

```bash
npx hardhat verify --network bscTestnet --constructor-args arguments.js TOKEN_CONTRACT_ADDRESS
```

Replace `TOKEN_CONTRACT_ADDRESS` with the address of the token contract you wish to verify.

## Conclusion

Following these steps will allow you to verify your token contract on the BSC Mainnet successfully.
57 changes: 57 additions & 0 deletions contract-hardhat/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3'
services:
graph-node:
image: graphprotocol/graph-node:v0.25.0
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
- ganache-cli
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'mainnet:http://ganache-cli:8545'
GRAPH_LOG: info
# LANG: C.UTF-8 # Setting the locale to C.UTF-8
ipfs:
image: ipfs/go-ipfs:v0.4.23
ports:
- '5001:5001'
postgres:
image: postgres
ports:
- '5432:5432'
command:
[
"postgres",
"-cshared_preload_libraries=pg_stat_statements"
]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
ganache-cli:
image: trufflesuite/ganache-cli:v6.12.2
ports:
- '8545:8545'
entrypoint:
- node
- /app/ganache-core.docker.cli.js
- --mnemonic
- 'test test test test test test test test test test test junk'
- --networkId
- '1337'
- --chainId
- '1337'
- --hostname
- '0.0.0.0'
- --gasLimit
- '8000000'
83 changes: 83 additions & 0 deletions contract-hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { HardhatUserConfig } from "hardhat/config";
import dotenv from 'dotenv';
import "@nomicfoundation/hardhat-toolbox";

const dotenvResult = dotenv.config();
if (dotenvResult.error) {
throw dotenvResult.error;
}

const {
PROVIDER_URL,
OWNER_PRIVATE_KEY,
ETHERSCAN_API_KEY,
} = process.env;

const accounts = [...(OWNER_PRIVATE_KEY ? [OWNER_PRIVATE_KEY] : [])];

const config: HardhatUserConfig = {
networks: {
local: {
url: PROVIDER_URL,
chainId: 31337,
},
hardhat: {
chainId: 1337,
},
localhost: {
chainId: 1337,
url: 'http://localhost:8545',
},
goerli: {
url: PROVIDER_URL,
accounts,
chainId: 5,
},
bscTestnet: {
url: PROVIDER_URL,
accounts,
chainId: 97,
timeout: 60 * 60 * 1000 // 1 hour
},
baseSepoliaTestnet: {
url: PROVIDER_URL,
accounts,
chainId: 84532,
timeout: 60 * 60 * 1000 // 1 hour
},
plume: {
url: "https://phoenix-rpc.plumenetwork.xyz",
chainId: 98866,
accounts,
}
},
solidity: {
version: '0.5.8',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
// etherscan: {
// apiKey: ETHERSCAN_API_KEY
// },
etherscan: {
apiKey: {
"plume": "test"
},
customChains: [
{
network: "plume",
chainId: 98866,
urls: {
apiURL: "https://phoenix-explorer.plumenetwork.xyz/api\?",
browserURL: "https://phoenix-explorer.plumenetwork.xyz"
}
}
]
}
};

export default config;
Loading