Here itβs my code
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";
contract Wallet is Ownable {
using SafeMath for uint256;
struct Token {
bytes32 ticker;
address tokenAddress;
}
mapping (bytes32 => Token) public tokenMapping;
bytes32 [] public tokenList;
mapping (address => mapping(bytes32 => uint256)) public balances;
modifier tokenExist(bytes32 ticker){
require(tokenMapping[ticker].tokenAddress != address(0));
_;
}
function addToken(bytes32 ticker, address tokenAddress) onlyOwner external{
tokenMapping[ticker] = Token(ticker, tokenAddress);
tokenList.push(ticker);
}
function deposit(uint amount, bytes32 ticker) tokenExist(ticker) external {
IERC20(tokenMapping[ticker].tokenAddress).transferFrom(msg.sender, address(this), amount);
balances[msg.sender][ticker] = balances[msg.sender][ticker].add(amount);
}
function withdraw(uint amount, bytes32 ticker) tokenExist(ticker) external{
require (balances[msg.sender][ticker] >= amount, "Balance not sufficient");
balances[msg.sender][ticker] = balances[msg.sender][ticker].sub(amount);
IERC20(tokenMapping[ticker].tokenAddress).transfer(msg.sender, amount);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Link is ERC20{
constructor() ERC20("Chainlink", "LINK") {
_mint(msg.sender, 1000);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
pragma experimental ABIencoderV2;
import "../contracts/wallet.sol";
contract Dex is Wallet{
enum Side{
BUY,
SELL
}
struct Order{
uint id;
address trader;
bool buyOrder;
bytes32 ticker;
uint amount;
uint price;
}
mapping(bytes32 => mapping(uint=> Order[]))public orderBook;
function getOrderBook(bytes32 ticker, Side side)public view returns(Order[]memory){
return orderBook[ticker][uint(side)];
}
function createLimitOrder(type name ) {
}
}
const Wallet = artifacts.require("Wallet");
module.exports = function(deployer){
deployer.deploy(Wallet);
};
The following file already corrected as per your advice
const Link = artifacts.require("Link");
const Wallet = artifacts.require("Wallet");
module.exports = async function(deployer, network, accounts){
await deployer.deploy(Link);
await deployer.deploy(Wallet);
let wallet = await Wallet.deployed();
let link = await Link.deployed();
await link.approve(wallet.address, 500);
await wallet.addToken(web3.utils.fromUtf8("LINK"), link.address);
await wallet.deposit(100, web3.utils.fromUtf8("LINK"));
let balanceOfLink = await wallet.balances(accounts[0], web3.utils.fromUtf8("LINK"));
console.log(balanceOfLink);
};