Skip to content

Commit

Permalink
(feat) Go back to the old lockProxyProxy on eth, because it is the on…
Browse files Browse the repository at this point in the history
…e Switcheo registered (and it's fine - same parameters, and now verified)

(feat) Separate legacy and overcommit - ethereum requires legacy = false, overcommit = true.
(fix) Fix odd result of duplicate contract addresses for OPUL and zETH
  • Loading branch information
rrw-zilliqa committed Jan 13, 2025
1 parent 05b8b5a commit dfd993a
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl<D: EthEvent> EventListener<D> {
let mut interval = interval(Duration::from_secs(3));
// Set this down 1 because we (almost) certainly haven't scanned this block
// yet...
self.current_block = self.chain_client.client.get_block_number().await? - 1;
self.current_block = self.get_block_number().await? - 1;

loop {
interval.tick().await;
Expand Down
2 changes: 1 addition & 1 deletion bridge-validators/src/bridge_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl BridgeNode {
};

if !self.validators.contains(&address) {
info!("Address not part of the validator set, {}", address);
info!("Address not part of the validator set, {:x}", address);
return Ok(());
}

Expand Down
6 changes: 4 additions & 2 deletions bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub struct ChainClient {
pub wallet: LocalWallet,
pub chain_gateway_block_deployed: u64,
pub block_instant_finality: bool,
pub legacy_gas_estimation_percent: Option<u64>,
pub gas_estimation_percent: Option<u64>,
pub use_legacy_transactions: bool,
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
Expand Down Expand Up @@ -103,7 +104,8 @@ impl ChainClient {
wallet,
chain_gateway_block_deployed: config.chain_gateway_block_deployed,
block_instant_finality: config.block_instant_finality.unwrap_or_default(),
legacy_gas_estimation_percent: config.legacy_gas_estimation_percent,
gas_estimation_percent: config.gas_estimation_percent,
use_legacy_transactions: config.use_legacy_transactions.unwrap_or(false),
scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(),
log_strategy: strategy,
to_block_number: config.to_block_number,
Expand Down
3 changes: 2 additions & 1 deletion bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub struct ChainConfig {
pub chain_gateway_address: Address,
pub chain_gateway_block_deployed: u64,
pub block_instant_finality: Option<bool>,
pub legacy_gas_estimation_percent: Option<u64>,
pub gas_estimation_percent: Option<u64>,
pub use_legacy_transactions: Option<bool>,
pub scan_behind_blocks: Option<u64>,
pub use_get_transactions: Option<bool>,
pub to_block_number: Option<u64>,
Expand Down
35 changes: 21 additions & 14 deletions bridge-validators/src/validator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl ValidatorNode {
event.target_chain_id, event.nonce
);

let function_call = if client.legacy_gas_estimation_percent.is_some() {
let function_call = if client.use_legacy_transactions {
function_call.legacy()
} else {
function_call
Expand All @@ -192,18 +192,10 @@ impl ValidatorNode {

// Get gas estimate
// TODO: refactor configs specifically for zilliqa
let _function_call = if let Some(percent) = client.legacy_gas_estimation_percent {
let gas_estimate = match function_call.estimate_gas().await {
Ok(estimate) => estimate,
Err(err) => {
warn!("Failed to estimate gas, {:?} - using built-in default", err);
U256::from(2_000_000)
// return Ok(());
}
};
info!("Legacy gas estimation: estimate {:?}", gas_estimate);
function_call.clone().gas(gas_estimate * percent / 100) // Apply multiplier
} else {
let gas_percent = client.gas_estimation_percent.unwrap_or(100);

// If we're not using legacy txns, try to simulate the txn.
if !client.use_legacy_transactions {
let function_call = function_call.clone();
// `eth_call` does not seem to work on ZQ so it had to be skipped
// Simulate call, if fails decode error and exit early
Expand All @@ -227,8 +219,23 @@ impl ValidatorNode {
}
}
}
function_call
}

// Now we need to estimate gas.
let gas_estimate = match function_call.estimate_gas().await {
Ok(estimate) => estimate,
Err(err) => {
warn!("Failed to estimate gas, {:?} - using built-in default", err);
U256::from(2_000_000)
// return Ok(());
}
};
let gas_to_use = (gas_estimate * U256::from(gas_percent)) / U256::from(100);
info!(
"Gas estimation: estimate {:?} calling with gas {:?}",
gas_estimate, gas_to_use
);
let _function_call = function_call.clone().gas(gas_to_use);

// Make the actual call
match _function_call.send().await {
Expand Down
39 changes: 22 additions & 17 deletions bridge-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ import AddToken from "./components/AddToken";
type TxnType = "approve" | "bridge";

function getAvailableTokens(fromChainConfig: ChainConfig, toChainConfig: ChainConfig) {
return fromChainConfig.tokens.filter((tok) =>
tok.bridgesTo.find((network) => network == toChainConfig.chain));
const avail = Array.from(fromChainConfig.tokens).filter((tok) =>
tok.bridgesTo.find((network) => network == toChainConfig.chain))
.sort((a,b) => a.name.localeCompare(b.name, 'en') );
let names = avail.map((x) => (x.name));
return avail;

}

function App() {
Expand Down Expand Up @@ -73,9 +77,9 @@ function App() {
const pendingFromChainConfig = chainConfigs[pendingChains[0]]!;
const pendingToChainConfig = chainConfigs[pendingChains[1]]!;
// Don't query whilst we're switching chains.
const pendingChainSwitch = chain != fromChainConfig.wagmiChain;
const pendingChainSwitch = chain?.id != fromChainConfig?.wagmiChain?.id;

// console.log(`pending ${JSON.stringify(pendingChains)} current ${JSON.stringify(currentChains)} chain ${JSON.stringify(chain)} pending ${pendingChainSwitch}`);
//console.log(`pending ${JSON.stringify(pendingChains)} current ${JSON.stringify(currentChains)} fromChainConfig.wagmiChain ${JSON.stringify(fromChainConfig.wagmiChain)} chain ${JSON.stringify(chain)} pending ${pendingChainSwitch}`);

const fromChainClient = usePublicClient({ chainId: fromChainConfig.chainId });
const toChainClient = usePublicClient({ chainId: toChainConfig.chainId });
Expand All @@ -85,7 +89,8 @@ function App() {
switchNetwork && switchNetwork(pendingFromChainConfig.chainId);
}, [pendingChains, switchNetwork]);

// This fires when switchNetwork() has completed and the chain has been changed in the wallet.
// This fires when switchNetwork() has completed and the chain has been changed in the wallet, or
// when we just change the to network.
useEffect(() => {
let goTo = pendingToChainConfig.chain;
let goFrom = pendingFromChainConfig.chain;
Expand All @@ -110,7 +115,7 @@ function App() {
if (toChainConfig.chain != goTo || fromChainConfig.chain != goFrom) {
setCurrentChains([goFrom, goTo]);
}
}, [chain]);
}, [chain,pendingToChainConfig]);


// Fires when currentChains is set - chooses a token.
Expand Down Expand Up @@ -165,6 +170,7 @@ function App() {
watch: true,
});

//console.log(`contractBalance ${contractBalance} account ${account} address ${token.address} pending ${pendingChainSwitch}`);
contractBalance = contractBalance ?? BigInt(0);
let nativeBalance =
nativeBalanceData && nativeBalanceData.value
Expand Down Expand Up @@ -470,7 +476,6 @@ function App() {

const selectTokenOnDropdown = (token: TokenConfig) => {
const elem = document.activeElement;

if (elem) {
elem && (elem as any).blur();
}
Expand Down Expand Up @@ -651,23 +656,23 @@ function App() {
tabIndex={0}
className="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52"
>
{getAvailableTokens(fromChainConfig, toChainConfig).map((token) => (
{getAvailableTokens(fromChainConfig, toChainConfig).filter((tok) => tok.name != token.name).map((tok) => (
<li
key={token.address}
onClick={() => selectTokenOnDropdown(token)}
key={tok.address}
onClick={() => selectTokenOnDropdown(tok)}
>
<div className="flex items-center gap-2">
{token.logo && (
{tok.logo && (
<img
src={token.logo}
className="h-8"
alt="Token Logo"
/>
src={tok.logo}
className="h-8"
alt="Token Logo"
/>
)}
<p>{token.name}</p>
<p>{tok.name}</p>
</div>
</li>
))}
))}
</ul>
</div>
</div>
Expand Down
46 changes: 23 additions & 23 deletions bridge-web/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "bsc" ]
},
{
name: "zMATIC",
name: "MATIC",
address: "0x4345472A0c6164F35808CDb7e7eCCd3d326CC50b",
blockExplorer: "https://otterscan.zilliqa.com/address/0x4345472A0c6164F35808CDb7e7eCCd3d326CC50b",
logo: test_hrse_token,
Expand All @@ -90,15 +90,6 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
tokenManagerType: TokenManagerType.LockAndRelease,
bridgesTo: [ "ethereum", "polygon", "arbitrum", "bsc" ]
},
{
name: "zETH",
address: "0x17D5af5658A24bd964984b36d28e879a8626adC3",
blockExplorer: "https://otterscan.zilliqa.com/address/0x17D5af5658A24bd964984b36d28e879a8626adC3",
logo: fps_token,
tokenManagerAddress: "0x4fa6148C9DAbC7A737422fb1b3AB9088c878d26C",
tokenManagerType: TokenManagerType.LockAndRelease,
bridgesTo: [ "ethereum" ]
},
{
name: "XCAD",
address: "0xCcF3Ea256d42Aeef0EE0e39Bfc94bAa9Fa14b0Ba",
Expand All @@ -108,17 +99,26 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
tokenManagerType: TokenManagerType.LockAndRelease,
bridgesTo: [ "ethereum" ]
},
{
name: "zOPUL",
address: "0x17D5af5658A24bd964984b36d28e879a8626adC3",
{
name: "ETH",
address: "0x17D5af5658A24bd964984b36d28e879a8626adC3",
blockExplorer: "https://otterscan.zilliqa.com/address/0x17D5af5658A24bd964984b36d28e879a8626adC3",
logo: fps_token,
tokenManagerAddress: "0x4fa6148C9DAbC7A737422fb1b3AB9088c878d26C",
tokenManagerType: TokenManagerType.LockAndRelease,
bridgesTo: [ "ethereum", "arbitrum" ]
},
{
name: "OPUL",
address: "0x8DEAdC20f7218994c86b59eE1D5c7979fFcAa893",
blockExplorer: "https://otterscan.zilliqa.com/address/0x17D5af5658A24bd964984b36d28e879a8626adC3",
logo: seed_token,
tokenManagerAddress: "0x4fa6148C9DAbC7A737422fb1b3AB9088c878d26C",
tokenManagerType: TokenManagerType.LockAndRelease,
bridgesTo: [ "ethereum" ]
},
{
name: "zBRKL",
name: "BRKL",
address: "0xD819257C964A78A493DF93D5643E9490b54C5af2",
blockExplorer: "https://otterscan.zilliqa.com/address/0xD819257C964A78A493DF93D5643E9490b54C5af2",
logo: seed_token,
Expand All @@ -127,7 +127,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "ethereum" ]
},
{
name: "zWBTC",
name: "WBTC",
address: "0x2938fF251Aecc1dfa768D7d0276eB6d073690317",
blockExplorer: "https://otterscan.zilliqa.com/address/0x2938fF251Aecc1dfa768D7d0276eB6d073690317",
logo: seed_token,
Expand All @@ -136,7 +136,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "ethereum" ]
},
{
name: "zUSDT",
name: "USDT",
address: "0x2274005778063684fbB1BfA96a2b725dC37D75f9",
blockExplorer: "https://otterscan.zilliqa.com/address/0x2274005778063684fbB1BfA96a2b725dC37D75f9",
logo: seed_token,
Expand All @@ -145,7 +145,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "ethereum" ]
},
{
name: "zTRAXX",
name: "TRAXX",
address: "0x9121A67cA79B6778eAb477c5F76dF6de7C79cC4b",
blockExplorer: "https://otterscan.zilliqa.com/address/0x9121A67cA79B6778eAb477c5F76dF6de7C79cC4b",
logo: seed_token,
Expand Down Expand Up @@ -209,7 +209,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
nativeTokenSymbol: "POL",
tokens: [
{
name: "eZIL",
name: "ZIL",
address: "0xCc88D28f7d4B0D5AFACCC77F6102d88EE630fA17",
blockExplorer: "https://polygonscan.com/token/0xCc88D28f7d4B0D5AFACCC77F6102d88EE630fA17",
logo: test_hrse_token,
Expand Down Expand Up @@ -242,7 +242,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
nativeTokenSymbol: "ARB",
tokens: [
{
name: "eZIL",
name: "ZIL",
address: "0x1816a0f20bc996f643b1af078e8d84a0aabd772a",
blockExplorer: "https://arbiscan.io/token/0x1816a0f20bc996f643b1af078e8d84a0aabd772a",
logo: test_hrse_token,
Expand Down Expand Up @@ -271,7 +271,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
chainGatewayAddress: "0x49EA20823c953dd00619E2090DFa3965C89269C3",
chainId: 1,
isZilliqa: false,
blockExplorer: "https://etherscan.io",
blockExplorer: "https://etherscan.io/tx/",
nativeTokenSymbol: "ETH",
tokens: [
{
Expand Down Expand Up @@ -363,7 +363,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "zq" ]
},
{
name: "zWBTC",
name: "WBTC",
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
logo: seed_token,
blockExplorer: "https://etherscan.io/token/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
Expand All @@ -372,7 +372,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "zq" ]
},
{
name: "zUSDT",
name: "USDT",
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
logo: seed_token,
blockExplorer: "https://etherscan.io/token/0xdAC17F958D2ee523a2206206994597C13D831ec7",
Expand All @@ -381,7 +381,7 @@ export const chainConfigs: Partial<Record<Chains, ChainConfig>> =
bridgesTo: [ "zq" ]
},
{
name: "zTRAXX",
name: "TRAXX",
address: "0xD43Be54C1aedf7Ee4099104f2DaE4eA88B18A249",
logo: seed_token,
blockExplorer: "https://etherscan.io/token/0xD43Be54C1aedf7Ee4099104f2DaE4eA88B18A249",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"transactions": [
{
"hash": null,
"transactionType": "CALL",
"contractName": null,
"contractAddress": "0x99bcb148bec418fc66ebf7aca3668ec1c6289695",
"function": "setLockProxyData(address,address)",
"arguments": [
"0x9a016Ce184a22DbF6c17daA59Eb7d3140DBd1c54",
"0x405e42de24Dc4894dB22595D041EBb170dC21D60"
],
"transaction": {
"from": "0xd89421cd5dd6d6269fbb9307535c386afe11a23e",
"to": "0x99bcb148bec418fc66ebf7aca3668ec1c6289695",
"gas": "0xd029",
"value": "0x0",
"input": "0x766a1b7b0000000000000000000000009a016ce184a22dbf6c17daa59eb7d3140dbd1c54000000000000000000000000405e42de24dc4894db22595d041ebb170dc21d60",
"nonce": "0x27",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
},
{
"hash": null,
"transactionType": "CALL",
"contractName": "LockProxyProxy",
"contractAddress": "0x405e42de24dc4894db22595d041ebb170dc21d60",
"function": "addCaller(address)",
"arguments": [
"0x99bCB148BEC418Fc66ebF7ACA3668ec1C6289695"
],
"transaction": {
"from": "0xd89421cd5dd6d6269fbb9307535c386afe11a23e",
"to": "0x405e42de24dc4894db22595d041ebb170dc21d60",
"gas": "0x1e9a3",
"value": "0x0",
"input": "0x747293fb00000000000000000000000099bcb148bec418fc66ebf7aca3668ec1c6289695",
"nonce": "0x28",
"chainId": "0x1"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1736760353,
"chain": 1,
"commit": "05b8b5a"
}
Loading

0 comments on commit dfd993a

Please sign in to comment.