Skip to content

Commit

Permalink
(WIP) ZRC2->ERC20 fascias ; work in transit
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Jul 18, 2024
1 parent 457b22d commit d03c8ae
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 35 deletions.
20 changes: 10 additions & 10 deletions bridge-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ function App() {
const { data: fees } = useContractRead({
abi: tokenManagerAbi,
functionName: "getFees",
address: fromChainConfig.tokenManagerAddress,
enabled: !!fromChainConfig.tokenManagerAddress,
address: token.tokenManagerAddress,
enabled: !!token.tokenManagerAddress,
});
const { data: paused } = useContractRead({
abi: tokenManagerAbi,
functionName: "paused",
address: fromChainConfig.tokenManagerAddress,
enabled: !!fromChainConfig.tokenManagerAddress,
address: token.tokenManagerAddress,
enabled: !!token.tokenManagerAddress,
});
const { data: balance } = useContractRead({
abi: erc20ABI,
Expand All @@ -108,9 +108,9 @@ function App() {
abi: erc20ABI,
functionName: "allowance",
address: token.address,
args: [account!, fromChainConfig.tokenManagerAddress],
args: [account!, token.tokenManagerAddress],
enabled:
!!account && !!token.address && !!fromChainConfig.tokenManagerAddress,
!!account && !!token.address && !!token.tokenManagerAddress,
watch: true,
});

Expand All @@ -124,7 +124,7 @@ function App() {
: false;

const { config: transferConfig } = usePrepareContractWrite({
address: fromChainConfig.tokenManagerAddress,
address: token.tokenManagerAddress,
abi: tokenManagerAbi,
args: recipientEth && [
token.address,
Expand Down Expand Up @@ -154,7 +154,7 @@ function App() {
} = useContractWrite({
mode: "prepared",
request: {
address: fromChainConfig.tokenManagerAddress,
address: token.tokenManagerAddress,
chain: fromChainConfig.wagmiChain,
account: account!,
abi: tokenManagerAbi,
Expand All @@ -176,7 +176,7 @@ function App() {
address: token.address,
abi: erc20ABI,
args: [
fromChainConfig.tokenManagerAddress,
token.tokenManagerAddress,
amount ? parseUnits(amount, decimals ?? 0) : 0n,
],
functionName: "approve",
Expand Down Expand Up @@ -264,7 +264,7 @@ function App() {
toast.update(id, {
render: (
<div>
Bridge txn complete, funds arrived to {toChainConfig.name}{" "}
Bridge txn complete, funds arrived on {toChainConfig.name}{" "}
chain. View on{" "}
<a
className="link text-ellipsis w-10"
Expand Down
38 changes: 28 additions & 10 deletions bridge-web/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import hrse_token from "../assets/hrse_token.webp";
export enum TokenManagerType {
MintAndBurn,
LockAndRelease,
ZilBridge
}

export type Chains = "bsc-testnet" | "zq-testnet" | "bsc" | "zq";
Expand All @@ -27,9 +28,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
zq: {
chain: "zq",
name: "Zilliqa",
tokenManagerAddress: "0x6D61eFb60C17979816E4cE12CD5D29054E755948",
chainGatewayAddress: "0xbA44BC29371E19117DA666B729A1c6e1b35DDb40",
tokenManagerType: TokenManagerType.LockAndRelease,
wagmiChain: zilliqa,
tokens: [
{
Expand All @@ -38,13 +37,17 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
blockExplorer:
"https://otterscan.zilliqa.com/address/0x63B991C17010C21250a0eA58C6697F696a48cdf3",
logo: hrse_token,
tokenManagerAddress: "0x6D61eFb60C17979816E4cE12CD5D29054E755948",
tokenManagerType: TokenManagerType.LockAndRelease,
},
{
name: "FPS",
address: "0x241c677D9969419800402521ae87C411897A029f",
blockExplorer:
"https://otterscan.zilliqa.com/address/0x241c677D9969419800402521ae87C411897A029f",
logo: fps_token,
tokenManagerAddress: "0x6D61eFb60C17979816E4cE12CD5D29054E755948",
tokenManagerType: TokenManagerType.LockAndRelease,
},
],
chainId: 32769,
Expand All @@ -59,23 +62,25 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bsc,
`${import.meta.env.VITE_BSC_MAINNET_API}/${import.meta.env.VITE_BSC_MAINNET_KEY}`,
),
tokenManagerAddress: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23",
chainGatewayAddress: "0x3967f1a272Ed007e6B6471b942d655C802b42009",
tokenManagerType: TokenManagerType.MintAndBurn,
tokens: [
{
name: "HRSE",
address: "0x3BE0E5EDC58bd55AAa381Fa642688ADC289c05a3",
blockExplorer:
"https://bscscan.com/address/0x3BE0E5EDC58bd55AAa381Fa642688ADC289c05a3",
logo: hrse_token,
tokenManagerAddress: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23",
tokenManagerType: TokenManagerType.MintAndBurn,
},
{
name: "FPS",
address: "0x351dA1E7500aBA1d168b9435DCE73415718d212F",
blockExplorer:
"https://bscscan.com/address/0x351dA1E7500aBA1d168b9435DCE73415718d212F",
logo: fps_token,
tokenManagerAddress: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23",
tokenManagerType: TokenManagerType.MintAndBurn,
},
],
chainId: 56,
Expand All @@ -88,8 +93,6 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
"zq-testnet": {
chain: "zq-testnet",
name: "Zilliqa Testnet",
tokenManagerAddress: "0x1509988c41f02014aA59d455c6a0D67b5b50f129",
tokenManagerType: TokenManagerType.LockAndRelease,
chainGatewayAddress: "0x7370e69565BB2313C4dA12F9062C282513919230",
wagmiChain: zilliqaTestnet,
tokens: [
Expand All @@ -99,13 +102,17 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
blockExplorer:
"https://otterscan.testnet.zilliqa.com/address/0x8618d39a8276D931603c6Bc7306af6A53aD2F1F3",
logo: fps_token,
tokenManagerAddress: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23",
tokenManagerType: TokenManagerType.LockAndRelease,
},
{
name: "TSLM Z",
address: "0xE90Dd366D627aCc5feBEC126211191901A69f8a0",
blockExplorer:
"https://otterscan.testnet.zilliqa.com/address/0xE90Dd366D627aCc5feBEC126211191901A69f8a0",
logo: test_hrse_token,
tokenManagerAddress: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23",
tokenManagerType: TokenManagerType.LockAndRelease,
},
],
chainId: 33101,
Expand All @@ -120,8 +127,6 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bscTestnet,
`${import.meta.env.VITE_BSC_TESTNET_API}/${import.meta.env.VITE_BSC_TESTNET_KEY}`,
),
tokenManagerAddress: "0xA6D73210AF20a59832F264fbD991D2abf28401d0",
tokenManagerType: TokenManagerType.MintAndBurn,
chainGatewayAddress: "0xa9A14C90e53EdCD89dFd201A3bF94D867f8098fE",
tokens: [
{
Expand All @@ -130,13 +135,26 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
blockExplorer:
"https://testnet.bscscan.com/address/0x5190e8b4Bbe8C3a732BAdB600b57fD42ACbB9F4B",
logo: fps_token,
tokenManagerAddress: "0xA6D73210AF20a59832F264fbD991D2abf28401d0",
tokenManagerType: TokenManagerType.MintAndBurn,
},
{
name: "TSLM B",
address: "0x7Cc585de659E8938Aa7d5709BeaF34bD108bdC03",
blockExplorer:
"https://testnet.bscscan.com/address/0x7Cc585de659E8938Aa7d5709BeaF34bD108bdC03",
logo: test_hrse_token,
tokenManagerAddress: "0xA6D73210AF20a59832F264fbD991D2abf28401d0",
tokenManagerType: TokenManagerType.MintAndBurn,
},
{
name: "zbBSCERC20",
address: "0x59A23d0957B63BC6c5682F211eE731513EECBB98",
blockExplorer:
"https://testnet.bscscan.com/address/0x59A23d0957B63BC6c5682F211eE731513EECBB98",
logo: fps_token,
tokenManagerAddress: "0x36b8A9cd6Bf9bfA5984093005cf81CAfB1Bf06F7",
tokenManagerType: TokenManagerType.ZilBridge
},
],
chainId: 97,
Expand All @@ -150,9 +168,7 @@ export type ChainConfig = {
name: string;
chain: Chains;
wagmiChain: Chain;
tokenManagerAddress: `0x${string}`;
chainGatewayAddress: `0x${string}`;
tokenManagerType: TokenManagerType;
tokens: TokenConfig[];
chainId: number;
isZilliqa: boolean;
Expand All @@ -165,4 +181,6 @@ export type TokenConfig = {
address: `0x${string}`;
blockExplorer: string;
logo?: string;
tokenManagerAddress: `0x${string}`;
tokenManagerType: TokenManagerType;
};
6 changes: 6 additions & 0 deletions docs/zilbridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export TOKEN_MANAGER=(whatever address the deployNativeTokenManagerV3 script abo
npx hardhat run scripts/deploy.ts
```

And now we ship an ERC20 proxy for our ZRC2 and switcheo tokens.

```
```

And now we can set up routing for the tokens we just deployed. This is "just" calls, so

```
Expand Down
6 changes: 3 additions & 3 deletions scilla-contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ async function main() {
}
let tokenContract = await hre.deployScillaContract("SwitcheoTokenZRC2", "Bridged-XTST", "XTST",
account.address, 18, 0, zqTestnetTokenManager);
console.log(`TokenContract: ${tokenContract.address}`);
console.log(`zq_bridged_erc20 = ${tokenContract.address}`);

let nativeBridgedContract = await hre.deployScillaContract("SwitcheoTokenZRC2", "Bridged-BNB", "eBNB",
account.address, 18, 0, zqTestnetTokenManager);
console.log(`NativeBridgedContract: ${nativeBridgedContract.address}`);
console.log(`zq_bridged_bnb = ${nativeBridgedContract.address}`);

let local = await hre.deployScillaContract("FungibleToken", account.address, "zq_native Test", "ZTST", 18, 1_000_000);
console.log(`Locally generated fungible token: ${local.address}`);
console.log(`zq_zrc2 = ${local.address}`);
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
6 changes: 6 additions & 0 deletions smart-contracts/script/testnet_config.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ abstract contract TestnetConfig {
address public constant zq_chainGateway = 0x7370e69565BB2313C4dA12F9062C282513919230;
address public constant zq_lockAndReleaseOrNativeTokenManager = 0xBe90AB2cd65E207F097bEF733F8D239A59698b8A;

// Scilla contracts.
address public constant zq_bridged_erc20 = address(0x00839901f1e39De75301667C6bBbF7fB556Ea2510E);
address public constant zq_bridged_bnb = address(0x0006852e68A3c24917cfA4C2dbDaE4B308C69aDA5e);
address public constant zq_zrc2 = address(0x00155F0f76b660290F2F00Bb5674b80eDC208bF2e6);

// ERC20 fascias for Scilla contracts
address public constant zq_bridged_erc20_evm = address(0x0);
address public constant zq_bridged_bnb_evm = address(0x0);
address public constant zq_zrc2_evm = address(0x0);

}
32 changes: 32 additions & 0 deletions smart-contracts/script/zq-testnet/deployZRC2ERC20.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { ZRC2ProxyForZRC2 } from "test/zilbridge/zrc2erc20/ZRC2ProxyForZRC2.sol";
import { TestnetConfig } from "script/testnet_config.s.sol";
import "forge-std/console.sol";

/*** @title Deploy an ERC20 proxy for our ZRC2, so we can set routing with it.
*/
contract Deployment is Script, TestnetConfig {
function run() external {
uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET");
address validator = vm.addr(validatorPrivateKey);
console.log("Owner is %s", validator);
vm.startBroadcast(validatorPrivateKey);
{
ZRC2ProxyForZRC2 proxy = new ZRC2ProxyForZRC2(zq_bridged_erc20);
console.log("zq_bridged_erc20_evm = %s", address(proxy));
}
{
ZRC2ProxyForZRC2 proxy = new ZRC2ProxyForZRC2(zq_bridged_bnb);
console.log("zq_bridged_bnb_evm = %s", address(proxy));
}
{
ZRC2ProxyForZRC2 proxy = new ZRC2ProxyForZRC2(zq_zrc2);
console.log("zq_zrc2_evm = %s", address(proxy));
}
}
}
12 changes: 0 additions & 12 deletions smart-contracts/script/zq-testnet/registerZilBridgeTokens.s.sol

This file was deleted.

Loading

0 comments on commit d03c8ae

Please sign in to comment.