Передать переменные из JavaScript файла в Solidity файл

Есть у меня такой JS цикл для тестирования возможного арбитража на бирже в hardhat. Берутся адреса 3 токенов из файла и нужно передать эти адреса в FlashSwap.sol, чтобы развернуть контракт с соответствующими адресами.

const { expect, assert } = require("chai");
const { ethers } = require("hardhat");
const { impersonateFundErc20 } = require("../utils/utilities");

const {
  abi,
} = require("../artifacts/contracts/interfaces/IERC20.sol/IERC20.json");

const provider = waffle.provider;
const USDC_WHALE = "0xcffad3200574698b78f32232aa9d63eabd290703";
const DECIMALS = 6;

// Reading file 
function getFile(fPath) {
  const fs = require('fs')

  try {
    const data = fs.readFileSync(fPath, 'utf8')
    return data
  } catch (err) {
    return []
  }
}


// Get JSON Surface Rates
console.log("Reading surface rate information...")
let fileInfo = getFile("../UniswapV2/uniswap_surface_rates.json");
fileJsonArray = JSON.parse(fileInfo);
let limit = fileJsonArray.length
fileJsonArrayLimit = fileJsonArray.slice(0, limit);

 // Loop through each trade and get Price information
 for (let i = 0; i < fileJsonArrayLimit.length; i++) {
  
  // Extract the variables
  let swap1 = fileJsonArrayLimit[i].swap1
  let swap2 = fileJsonArrayLimit[i].swap2
  let swap3 = fileJsonArrayLimit[i].swap3
  let token1 = fileJsonArrayLimit[i].id1
  let token2 = fileJsonArrayLimit[i].id2
  let token3 = fileJsonArrayLimit[i].id3

  console.log(swap1,swap2,swap3)
  console.log(token1, token2, token3)
 
  describe("FlashSwap Contract", () => {
  let FLASHSWAP, BORROW_AMOUNT, FUND_AMOUNT, initialFundingHuman, txArbitrage;

  const BASE_TOKEN_ADDRESS = token1;

  const tokenBase = new ethers.Contract(BASE_TOKEN_ADDRESS, abi, provider);

  beforeEach(async () => {
    // Get owner as signer
    [owner] = await ethers.getSigners();

    // Ensure that the WHALE has a balance
    const whale_balance = await provider.getBalance(USDC_WHALE);
    expect(whale_balance).not.equal("0");

    // Deploy smart contract
    const FlashSwap = await ethers.getContractFactory("UniswapCrossFlash");
    FLASHSWAP = await FlashSwap.deploy();
    await FLASHSWAP.deployed();

    // Configure our Borrowing
    const borrowAmountHuman = "1000";
    BORROW_AMOUNT = ethers.utils.parseUnits(borrowAmountHuman, DECIMALS);

    // Configure Funding - FOR TESTING ONLY
    initialFundingHuman = "10000";
    FUND_AMOUNT = ethers.utils.parseUnits(initialFundingHuman, DECIMALS);

    // Fund our Contract - FOR TESTING ONLY
    await impersonateFundErc20(
      tokenBase,
      USDC_WHALE,
      FLASHSWAP.address,
      initialFundingHuman,
      DECIMALS
    );
  });

  describe("Arbitrage Execution", () => {
    it("ensures the contract is funded", async () => {
      const flashSwapBalance = await FLASHSWAP.getBalanceOfToken(
        BASE_TOKEN_ADDRESS
      );

      const flashSwapBalanceHuman = ethers.utils.formatUnits(
        flashSwapBalance,
        DECIMALS
      );

      expect(Number(flashSwapBalanceHuman)).equal(Number(initialFundingHuman));
    });

    it("executes the arbitrage", async () => {
      txArbitrage = await FLASHSWAP.startArbitrage(
        BASE_TOKEN_ADDRESS,
        BORROW_AMOUNT
      );

      assert(txArbitrage);

Сейчас в Flashswap все адреса заданы вручную, как передать значения token1,2,3 из JS файла в Flashswap.sol ? Везде пишут только об импорте из sol в sol. Спасибо.


Ответы (1 шт):

Автор решения: AdamSmith

В голову приходит только использование сущности Signer для записи данных из .js в .sol, но при этом вы в любом случае будете вносить данные в блокчейн, следовательно будете вынуждены платить за газ.

→ Ссылка