config and dynamic generation of contracts

This commit is contained in:
emochka2007 2024-05-08 03:36:45 +03:00
parent 5d5443b8ac
commit 01371286d0
7 changed files with 79 additions and 29 deletions

View File

@ -14,6 +14,7 @@ const config = {
paths: { paths: {
sources: './src/hardhat/contracts', sources: './src/hardhat/contracts',
// tests: './src/hardhat/test', // tests: './src/hardhat/test',
ignition: './src/hardhat/ignition',
cache: './src/hardhat/cache', cache: './src/hardhat/cache',
artifacts: './src/hardhat/artifacts', artifacts: './src/hardhat/artifacts',
}, },

View File

@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@chainlink/contracts": "^1.1.0", "@chainlink/contracts": "^1.1.0",
"@nestjs/common": "^10.0.0", "@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "*", "@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0", "@nestjs/platform-express": "^10.0.0",
@ -3595,6 +3596,33 @@
} }
} }
}, },
"node_modules/@nestjs/config": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-3.2.2.tgz",
"integrity": "sha512-vGICPOui5vE6kPz1iwQ7oCnp3qWgqxldPmBQ9onkVoKlBtyc83KJCr7CjuVtf4OdovMAVcux1d8Q6jglU2ZphA==",
"dependencies": {
"dotenv": "16.4.5",
"dotenv-expand": "10.0.0",
"lodash": "4.17.21",
"uuid": "9.0.1"
},
"peerDependencies": {
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
"rxjs": "^7.1.0"
}
},
"node_modules/@nestjs/config/node_modules/uuid": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/@nestjs/core": { "node_modules/@nestjs/core": {
"version": "10.3.8", "version": "10.3.8",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.3.8.tgz", "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.3.8.tgz",
@ -7537,6 +7565,14 @@
"url": "https://dotenvx.com" "url": "https://dotenvx.com"
} }
}, },
"node_modules/dotenv-expand": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==",
"engines": {
"node": ">=12"
}
},
"node_modules/eastasianwidth": { "node_modules/eastasianwidth": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",

View File

@ -22,6 +22,7 @@
"dependencies": { "dependencies": {
"@chainlink/contracts": "^1.1.0", "@chainlink/contracts": "^1.1.0",
"@nestjs/common": "^10.0.0", "@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "*", "@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.0.0", "@nestjs/platform-express": "^10.0.0",

View File

@ -3,9 +3,16 @@ import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { ContractFactoryModule } from './contract-factory/contract-factory.module'; import { ContractFactoryModule } from './contract-factory/contract-factory.module';
import { ContractInteractModule } from './contract-interact/contract-interact.module'; import { ContractInteractModule } from './contract-interact/contract-interact.module';
import { ConfigModule } from '@nestjs/config';
@Module({ @Module({
imports: [ContractFactoryModule, ContractInteractModule], imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
ContractFactoryModule,
ContractInteractModule,
],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],
}) })

View File

@ -1,25 +1,17 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.7; pragma solidity ^0.8.7;
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol"; import {AggregatorV3Interface} from '@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol';
contract Salaries { contract Salaries {
AggregatorV3Interface internal dataFeed; AggregatorV3Interface internal dataFeed;
/**
* Network: Sepolia
* Aggregator: BTC/USD
* Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
*/
constructor() { constructor() {
dataFeed = AggregatorV3Interface( dataFeed = AggregatorV3Interface(
0xF0d50568e3A7e8259E16663972b11910F89BD8e7 0xF0d50568e3A7e8259E16663972b11910F89BD8e7
); );
} }
/**
* Returns the latest answer.
*/
function getChainlinkDataFeedLatestAnswer() public view returns (int) { function getChainlinkDataFeedLatestAnswer() public view returns (int) {
// prettier-ignore // prettier-ignore
( (

View File

@ -1,28 +1,39 @@
const hre = require('hardhat'); // const hre = require('hardhat');
// import hre from 'hardhat'; import * as hre from 'hardhat';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { ethers } from 'ethers';
import { ConfigService } from '@nestjs/config';
@Injectable() @Injectable()
export class HardhatService { export class HardhatService {
constructor(private readonly configService: ConfigService) {}
async deploySalaryContract() { async deploySalaryContract() {
// const { salaryAmount, userAddress } = req.body; const provider = new ethers.JsonRpcProvider(
'https://polygon-amoy.g.alchemy.com/v2/pEtFFy_Qr_NrM1vMnlzSXmYXkozVNzLy',
80002,
);
// // Read the Solidity contract template file const salary = await hre.artifacts.readArtifact('Salaries');
// const solidityCode = readSolidityTemplate(); // Implement this function to read the Solidity template file const abi = salary.abi;
console.log('🚀 ~ HardhatService ~ deploySalaryContract ~ abi:', abi);
const bytecode = salary.deployedBytecode;
console.log(
'🚀 ~ HardhatService ~ deploySalaryContract ~ bytecode:',
bytecode,
);
const signer = new ethers.Wallet(
this.configService.getOrThrow('POLYGON_PK'),
provider,
);
// // Replace placeholders in the Solidity contract template with provided values const salaryContract = new ethers.ContractFactory(
// const finalSolidityCode = replacePlaceholders(solidityCode, { abi,
// salaryAmount, salary.bytecode,
// userAddress, signer,
// }); );
// // Compile the Solidity contract const myContract = await salaryContract.deploy();
// const compiledContract = await compileSolidity(finalSolidityCode); await myContract.waitForDeployment();
// // Deploy the contract
// const deployedContract = await deployContract(compiledContract);
const salaryC = await hre.ethers.getContractFactory('Salaries');
const myContract = await salaryC.deploy();
console.log( console.log(
'🚀 ~ HardhatService ~ deploySalaryContract ~ myContract:', '🚀 ~ HardhatService ~ deploySalaryContract ~ myContract:',
myContract, myContract,

View File

@ -16,6 +16,8 @@
"noImplicitAny": false, "noImplicitAny": false,
"strictBindCallApply": false, "strictBindCallApply": false,
"forceConsistentCasingInFileNames": false, "forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false "noFallthroughCasesInSwitch": false,
} "resolveJsonModule": true
},
"include": ["src/**/*", "src/**/*.json"]
} }