Skip to content

Commit

Permalink
Feat/legacy tokens (#14)
Browse files Browse the repository at this point in the history
* feat: add support for L2StandardERC20s

* ci: simplify workflow

* updated data folder for UNI and USDT

* chore: rm logos

---------

Co-authored-by: jbarber13 <jabot999@gmail.com>
  • Loading branch information
AlexBHarley and jbarber13 authored Apr 23, 2024
1 parent 99046d7 commit 4eff601
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
version: 8
run_install: true

- name: Get changes
run: git diff --name-only -r HEAD^1 HEAD

- name: Test
run: |
npx tsx ./src/verify.ts $(git diff --name-only -r HEAD^1 HEAD)
Binary file removed data/TSC/logo.png
Binary file not shown.
11 changes: 11 additions & 0 deletions data/UNI/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Uniswap",
"symbol": "UNI",
"decimals": 18,
"logoURI": "https://github.com/raw/ethereum-optimism/ethereum-optimism.github.io/cdf02065fa51dd7c934ba857f5a1746513fe8e7f/data/UNI/logo.png",
"opTokenId": "UNI",
"addresses": {
"1": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"8453": "0xc3De830EA07524a0761646a6a4e4be0e114a3C83"
}
}
11 changes: 11 additions & 0 deletions data/USDT/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Tether USD",
"symbol": "USDT",
"decimals": 6,
"logoURI": "https://github.com/raw/ethereum-optimism/ethereum-optimism.github.io/01d7d6bf2ff3735b412da924d1df746ddd8a77a8/data/USDT/logo.png",
"opTokenId": "USDT",
"addresses": {
"1": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"8453": "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"
}
}
225 changes: 225 additions & 0 deletions src/abis/L2StandardERC20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
export const L2StandardERC20Abi = [
{
inputs: [
{ internalType: "address", name: "_l2Bridge", type: "address" },
{ internalType: "address", name: "_l1Token", type: "address" },
],
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "owner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "spender",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256",
},
],
name: "Approval",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "_account",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "_amount",
type: "uint256",
},
],
name: "Burn",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "_account",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "_amount",
type: "uint256",
},
],
name: "Mint",
type: "event",
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "address", name: "from", type: "address" },
{ indexed: true, internalType: "address", name: "to", type: "address" },
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256",
},
],
name: "Transfer",
type: "event",
},
{
inputs: [
{ internalType: "address", name: "owner", type: "address" },
{ internalType: "address", name: "spender", type: "address" },
],
name: "allowance",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" },
],
name: "approve",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [{ internalType: "address", name: "account", type: "address" }],
name: "balanceOf",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "_from", type: "address" },
{ internalType: "uint256", name: "_amount", type: "uint256" },
],
name: "burn",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "decimals",
outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "subtractedValue", type: "uint256" },
],
name: "decreaseAllowance",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "addedValue", type: "uint256" },
],
name: "increaseAllowance",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "l1Token",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "l2Bridge",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "_to", type: "address" },
{ internalType: "uint256", name: "_amount", type: "uint256" },
],
name: "mint",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "name",
outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view",
type: "function",
},
{
inputs: [{ internalType: "bytes4", name: "_interfaceId", type: "bytes4" }],
name: "supportsInterface",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "pure",
type: "function",
},
{
inputs: [],
name: "symbol",
outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "totalSupply",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "recipient", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" },
],
name: "transfer",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "sender", type: "address" },
{ internalType: "address", name: "recipient", type: "address" },
{ internalType: "uint256", name: "amount", type: "uint256" },
],
name: "transferFrom",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
] as const;
28 changes: 23 additions & 5 deletions src/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isAddressEqual, isAddress } from "viem/utils";

import { OptimismMintableERC20Abi } from "./abis/OptimismMintableERC20";
import { StandardBridgeAbi } from "./abis/StandardBridge";
import { L2StandardERC20Abi } from "./abis/L2StandardERC20";
import { getViemChain, TokenData } from "./utils";

async function main() {
Expand Down Expand Up @@ -37,7 +38,7 @@ async function main() {
throw new Error(`Invalid address for chainId ${chainId}`);
}

const [BRIDGE, REMOTE_TOKEN] = await Promise.all([
const [BRIDGE, REMOTE_TOKEN, l2Bridge, l1Token] = await Promise.all([
client
.readContract({
abi: OptimismMintableERC20Abi,
Expand All @@ -52,17 +53,34 @@ async function main() {
address: address as Address,
})
.catch(() => null),
client
.readContract({
abi: L2StandardERC20Abi,
functionName: "l2Bridge",
address: address as Address,
})
.catch(() => null),
client
.readContract({
abi: L2StandardERC20Abi,
functionName: "l1Token",
address: address as Address,
})
.catch(() => null),
]);
console.log("BRIDGE", BRIDGE);
console.log("REMOTE_TOKEN", REMOTE_TOKEN);

const localBridge = BRIDGE || l2Bridge;
const remoteToken = REMOTE_TOKEN || l1Token;

// mintable
if (BRIDGE && REMOTE_TOKEN) {
if (localBridge && remoteToken) {
mintable = true;
console.log(chainId, "is mintable");

const baseChainId = Object.entries(data!.addresses).find(
([_, address]) => isAddressEqual(address as Address, REMOTE_TOKEN)
([_, address]) => isAddressEqual(address as Address, remoteToken)
);
if (!baseChainId) {
throw new Error(
Expand All @@ -81,7 +99,7 @@ async function main() {
.readContract({
abi: StandardBridgeAbi,
functionName: "OTHER_BRIDGE",
address: BRIDGE,
address: localBridge,
})
.catch(() => null);
if (!BASE_BRIDGE) {
Expand All @@ -101,7 +119,7 @@ async function main() {
if (!REMOTE_BRIDGE) {
throw new Error("REMOTE_BRIDGE not found");
}
if (!isAddressEqual(REMOTE_BRIDGE, BRIDGE)) {
if (!isAddressEqual(REMOTE_BRIDGE, localBridge)) {
throw new Error("Bridge addresses do not match");
}
} else {
Expand Down

0 comments on commit 4eff601

Please sign in to comment.