Skip to content

Commit

Permalink
Fix ABI differences between SLV and GLD
Browse files Browse the repository at this point in the history
  • Loading branch information
RohanNero committed Jan 16, 2024
1 parent 33dd0f0 commit 52b38a1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
28 changes: 18 additions & 10 deletions packages/hardhat/contracts/EIPs/Token/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@ pragma solidity ^0.8.7;

contract Token {
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
mapping(address => uint) private _balanceOf;
mapping(address => mapping(address => uint)) public _allowance;
string public name = "Silver";
string public symbol = "SLV";
uint8 public decimals = 18;

event Transfer(address from, address to, uint amount);
event Approval(address owner, address spender, uint amount);

function balanceOf(address account) external view returns (uint) {
return _balanceOf[account];
}

function allowance(address owner, address spender) public view returns (uint256) {
return _allowance[owner][spender];
}

function transfer(address recipient, uint amount) external returns (bool) {
balanceOf[msg.sender] -= amount;
balanceOf[recipient] += amount;
_balanceOf[msg.sender] -= amount;
_balanceOf[recipient] += amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}

function approve(address spender, uint amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
_allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
Expand All @@ -30,21 +38,21 @@ contract Token {
address recipient,
uint amount
) external returns (bool) {
allowance[sender][msg.sender] -= amount;
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
_allowance[sender][msg.sender] -= amount;
_balanceOf[sender] -= amount;
_balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
return true;
}

function mint(uint amount) external {
balanceOf[msg.sender] += amount;
_balanceOf[msg.sender] += amount;
totalSupply += amount;
emit Transfer(address(0), msg.sender, amount);
}

function burn(uint amount) external {
balanceOf[msg.sender] -= amount;
_balanceOf[msg.sender] -= amount;
totalSupply -= amount;
emit Transfer(msg.sender, address(0), amount);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/abi/eips/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const tokenAbi = [
type: "function",
},
{
inputs: [{ internalType: "address", name: "", type: "address" }],
inputs: [{ internalType: "address", name: "account", type: "address" }],
name: "balanceOf",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/components/EIPs/Token/DataDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const DataDisplay: React.FC<DataDisplayProps> = ({ returnData, setReturnData, di
});
if (!silverBalance?.data || !goldBalance?.data) {
displayError("Silver or Gold balance is undefined!");
console.log("silverBalance:", silverBalance);
console.log("goldBalance:", goldBalance);
setReturnData({
...returnData,
silverBalance: 0,
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/components/book/chapters/EIPs/EIPList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const EIPData = [
// { href: "/book/EIPs/155_SimpleReplayAttackProtection", text: "EIP 155 - Simple Replay Attack Protection" },
// { href: "/book/EIPs/170_SpuriousDragon", text: "EIP 170 - Spurious Dragon" },
// { href: "/book/EIPs/173_Ownable", text: "EIP 173 - Ownable" },
{ href: "/book/EIPs/191_PersonalMessage", text: "EIP 191 - Personal Messages" }, // This
{ href: "/book/EIPs/712_StructuredMessage", text: "EIP 712 - Structured Messages" }, // And this
{ href: "/book/EIPs/721_NonFungibleToken", text: "EIP 721 - Non Fungible Token" }, // This too
// { href: "/book/EIPs/191_PersonalMessage", text: "EIP 191 - Personal Messages" }, // This
// { href: "/book/EIPs/712_StructuredMessage", text: "EIP 712 - Structured Messages" }, // And this
// { href: "/book/EIPs/721_NonFungibleToken", text: "EIP 721 - Non Fungible Token" }, // This too
// { href: "/book/EIPs/1167_Proxy", text: "EIP 1167 - Proxy" },
// { href: "/book/EIPs/1967_ProxyStorage", text: "EIP 1967 - Proxy Storage" },
// { href: "/book/EIPs/3156_FlashLoans", text: "EIP 3156 - Flash Loans" },
Expand Down
7 changes: 4 additions & 3 deletions packages/nextjs/components/book/chapters/Extras/ExtraList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import Link from "next/link";

/** Contains all the EIP list item data */
const ExtraData = [
{ href: "/blockexplorer", text: "ABI Encoding" },
{ href: "/blockexplorer", text: "ABI Decoding" },
{ href: "/blockexplorer", text: "Merkle Trees" },
// { href: "/blockexplorer", text: "ABI Encoding" },
// { href: "/blockexplorer", text: "ABI Decoding" },
// { href: "/blockexplorer", text: "Merkle Trees" },
{ href: "/", text: "Coming soon!" },
];

/** Handles rendering the EIP list items */
Expand Down
12 changes: 6 additions & 6 deletions packages/nextjs/utils/scaffold-eth/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const chainData: Record<string, ChainAttributes> = {
reset: "0x4a5E77782847Ed58d7f59753A52018d2f890C9e3",
},
token: {
main: "0x9B851840eEa4D455699D60Bf1aCdc9fA8C50187F",
swap: "0x92f44167d2AF0c96807713d3B08Cd6ddE4838Fe3",
main: "0xfB95837cfd28985206200D7d8F7Bc6ba2580F434",
swap: "0x2C898f978D600F13B3dF62Bce000c989c85F08Ad",
},
},
[chains.goerli.id]: {
Expand All @@ -72,8 +72,8 @@ export const chainData: Record<string, ChainAttributes> = {
reset: "0x4a5E77782847Ed58d7f59753A52018d2f890C9e3",
},
token: {
main: "0x92f44167d2AF0c96807713d3B08Cd6ddE4838Fe3",
swap: "0x949768B61234D4a9258143334B6bF07804D28f0e",
main: "0xA4415fddD1A2F72f3966944ADd9AD030E27D0c9D",
swap: "0x93b7e2F9E77124832ff4464CEaC2e224655E0B67",
},
},
[chains.polygonMumbai.id]: {
Expand All @@ -87,8 +87,8 @@ export const chainData: Record<string, ChainAttributes> = {
reset: "0x14cBf20165eF7853f772A36EE30BFc559a5Bd63e",
},
token: {
main: "0xD5D8484eE612D01f496F3156F63c03c0EAec6359",
swap: "0x0722BCB027F1F65767cb5bc3b343e42f035954D9",
main: "0x141560f7D0e641e6E360961F8112878858B86890",
swap: "0x1d83f96146C631250a2793Bfe4bc0DeD265E4E50",
},
},
[chains.optimismGoerli.id]: {
Expand Down

0 comments on commit 52b38a1

Please sign in to comment.