No really a problem, just need to understand a few things :
With this piece of code, transaction is reverted when calling "getEstimatedTokenForBNB" function.
// Initialize Parameters
constructor () {
tokenAddress = 0xf63DB3cc676b71F8D38D27181d0AE9d7Aa4F1D48;
wbnbAddress = 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd;
pairAddress = 0xD280a7D55faa4a982616e8d5C6b2D68B5Ce366aF;
routerAddress = 0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3;
userManagementAddress = 0xa1eD4f05cE96241e75817765c78eFAA74a9c120C;
}
// Initialize Interfaces
IUserManagement USERMANAGEMENT = IUserManagement(tokenAddress);
IDEXRouter iROUTER = IDEXRouter(routerAddress);
IBEP20 TOKEN = IBEP20(tokenAddress);
IBEP20 LPTOKEN = IBEP20(pairAddress);
IBEP20 WBNB = IBEP20(wbnbAddress);
// Modifiers
modifier onlyToken() {
require(msg.sender == tokenAddress); _;
}
// View Functions
function getEstimatedTokenForBNB(uint buyAmountInWei) public view returns (uint[] memory) {
uint[] memory bnbQuote;
bnbQuote = iROUTER.getAmountsOut(buyAmountInWei, getPathForWBNBToToken());
return bnbQuote;
}
// Utility Functions
receive() external payable {}
function getPathForWBNBToToken() public view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = wbnbAddress;
path[1] = tokenAddress;
return path;
}
function checkAmountValidity (uint buyAmountInWei) public view returns(bool checkResult) {
try iROUTER.getAmountsOut(buyAmountInWei, getPathForWBNBToToken()) {
checkResult = true;
return checkResult;
}
catch {
checkResult = false;
return checkResult;
}
}
I found that if I set manually addresses in the // initialize Interfaces section, everything works as expected.. so I suppose that my constructor doesn't set the parameters at time.
Anyone can explain me the right way to proceed ? I don't understand why constructor doesn't work..