i'm running my smart contract on a virtual fork when i execute the test scripts the transaction's goes through but somehow it's not updating the state of because after the succesfull execution of a write function when i query the contract storage it returns the default values of struct the address fields of a struct has been populated but it won't update the uint256 filelds.
why is it behaving like this i
m running polygon/bnb fork on the infura fork it was working fine but now it behaves in this way
**code
import {deployments, ethers} from 'hardhat';
import hre from 'hardhat';
import {ERC20_ABI, PROXY_ABI} from '../utils/constants';
import {SignerWithAddress} from '@nomicfoundation/hardhat-ethers/signers';
import {Crypoverse, IERC20} from '../typechain-types';
import {Trade, Route, computePoolAddress, FACTORY_ADDRESS, FeeAmount, SwapQuoter} from '@uniswap/v3-sdk';
import {Contract, ContractInterface, JsonRpcProvider, MaxUint256} from 'ethers';
import {abi} from '../deployments/vpolygon/Crypoverse.json';
const IUniswapV3PoolABI = require('../abi/IUniswapV3Pool.json');
const IQuoterABI = require('../abi/IQuoter.json');
let crypoverseContract: Crypoverse;
let admin: SignerWithAddress;
let treasury: SignerWithAddress;
let user1: SignerWithAddress;
let user2: SignerWithAddress;
let uniswapContract = '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45';
let usdtContract: IERC20;
let daiContract: IERC20;
let usdtAddress = '0xc2132D05D31c914a87C6611C10748AEb04B58e8F';
let daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063';
let daiWhale = '0xF977814e90dA44bFA03b6295A0616a897441aceC';
let usdtWhale = '0x8894E0a0c962CB723c1976a4421c95949bE2D4E3';
// const provider = new ethers.JsonRpcSigner(
// 'https://virtual.polygon.rpc.tenderly.co/7d1412a8-5f6e-47d5-aaea-7c78ea66f2aa'
// );
async function setup(crypoverseContract: Crypoverse) {
// await crypoverseContract.setTreasuryWallet(treasury.address);
// await crypoverseContract.addCurrency(usdtAddress);
// await crypoverseContract.addCurrency(daiAddress);
// await crypoverseContract.setRouterContract(uniswapContract);
await crypoverseContract.createMerchant(user1.address, daiAddress);
await crypoverseContract.createMerchant(user2.address, usdtAddress);
}
describe.only('Crypoverse: Slippage', () => {
before(async () => {
await deployments.fixture(['deploy_crypo_verse']); //tags from deployment script
crypoverseContract = (await ethers.getContractAt(
'Crypoverse',
'removed the contract address'
)) as any;
// contract = new ethers.Contract('0xa333B5651c2F0a991A9741E458f5D02980d11760', abi, provider);
usdtContract = (await ethers.getContractAt(ERC20_ABI, usdtAddress)) as any;
daiContract = (await ethers.getContractAt(ERC20_ABI, daiAddress)) as unknown as IERC20;
[admin, treasury, user1, user2] = await ethers.getSigners();
await setup(crypoverseContract);
});
it('should execute a USDT -> DAI swap with 1% slippage tolerance', async () => {
let amount = ethers.parseUnits('1000', 6); //1000 USDT
let slippage = 1; //3%
const quoterContract = new Contract('0x61fFE014bA17989E743c5F6cB21bF9697530B21e', IQuoterABI, ethers.provider);
const data = await quoterContract['quoteExactInputSingle'].staticCall({
tokenIn: usdtAddress,
tokenOut: daiAddress,
amountIn: amount,
fee: FeeAmount.LOW,
sqrtPriceLimitX96: 0,
});
console.log(data);
const amountOut = data[0];
const amountMinimum = amountOut - BigInt((amountOut * BigInt(slippage)) / BigInt(100));
let balanceBefore = await usdtContract.balanceOf(user1);
console.log('balance before is a :', balanceBefore.toString());
console.log('user1 ka address', user1.address);
console.log('user2 ka address is :', user2.address);
await usdtContract
.connect(user1)
.approve(await crypoverseContract.getAddress(), MaxUint256, {gasPrice: 0, gasLimit: 8000000});
let sending = await crypoverseContract
.connect(user1)
.createTransaction(0, amount, amountMinimum.toString(), usdtAddress, 100, {gasPrice: 0, gasLimit: 8000000});
sending.wait();
let balanceAfterr = await usdtContract.balanceOf('0xa333B5651c2F0a991A9741E458f5D02980d11760');
console.log();
console.log('balance after of contract is a :', balanceAfterr.toString());
});
it('should execute a DAI -> USDT swap with 1% slippage tolerance', async () => {
let amount = ethers.parseUnits('1000', 18); //1000 DAI
let slippage = 1; //3%
const quoterContract = new Contract('0x61fFE014bA17989E743c5F6cB21bF9697530B21e', IQuoterABI, ethers.provider);
const data = await quoterContract['quoteExactInputSingle'].staticCall({
tokenIn: daiAddress,
tokenOut: usdtAddress,
amountIn: amount,
fee: FeeAmount.LOW,
sqrtPriceLimitX96: 0,
});
console.log(data);
const amountOut = data[0];
const amountMinimum = amountOut - BigInt((amountOut * BigInt(slippage)) / BigInt(100));
console.log('amount after slippage is', amountMinimum.toString());
let balanceBeforeDai = await daiContract.balanceOf(user2);
console.log('balance before in a dai transaction is :', balanceBeforeDai.toString());
await daiContract
.connect(user2)
.approve(await crypoverseContract.getAddress(), MaxUint256, {gasPrice: 0, gasLimit: 8000000});
let sendingg = await crypoverseContract
.connect(user2)
.createTransaction(1, amount, amountMinimum.toString(), daiAddress, 100, {gasPrice: 0, gasLimit: 8000000});
sendingg.wait();
let balanceAfter = await daiContract.balanceOf('0xa333B5651c2F0a991A9741E458f5D02980d11760');
let contractBalance = await crypoverseContract.merchantBalance(1, usdtAddress);
console.log('after the trx the balance of a merchant is :', contractBalance);
console.log('balance after in a dai transaction of contract is :', balanceAfter);
});
});
belw this is a console statements
You can find the token at https://dashboard.tenderly.co/account/authorization
Result(4) [
148210502491278883900n,
30337611633231319057101135n,
31n,
1817503n
]
balance before is a : 10000000000
user1 ka address 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
user2 ka address is : 0x90F79bf6EB2c4f870365E785982E1f101E93b906
balance after of contract is a : 0
✔ should execute a USDT -> DAI swap with 1% slippage tolerance (9618ms)
Result(4) [ 228794917n, 228222018206543307333n, 32n, 1164528n ]
amount after slippage is 226506968
balance before in a dai transaction is : 10000000000000000000000
after the trx the balance of a merchant is : 0n
balance after in a dai transaction of contract is : 0n
✔ should execute a DAI -> USDT swap with 1% slippage tolerance (20215ms)
i'm running my smart contract on a virtual fork when i execute the test scripts the transaction's goes through but somehow it's not updating the state of because after the succesfull execution of a write function when i query the contract storage it returns the default values of struct the address fields of a struct has been populated but it won't update the uint256 filelds. why is it behaving like this i m running polygon/bnb fork on the infura fork it was working fine but now it behaves in this way
belw this is a console statements