-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Gateway functions to get Gateway address dynamically #201
Comments
It's also important to keep in mind that these functions are also used in localnet, which has a gateway address that changes, so it should be possible to pass the gateway address manually. |
@lukema95 for context, I think the way it works right now is a bit ugly: const tx = await client.evmDepositAndCall({
amount: args.amount,
erc20: args.erc20,
gatewayEvm: args.gatewayEvm,
receiver: args.receiver,
revertOptions: {
callOnRevert: args.callOnRevert,
onRevertGasLimit: args.onRevertGasLimit,
revertAddress: args.revertAddress,
revertMessage: args.revertMessage,
},
txOptions: {
gasLimit: args.gasLimit,
gasPrice: args.gasPrice,
},
types: ["address", "bytes", "bool"],
values: [args.target, args.recipient, JSON.stringify(args.withdraw)],
}); I want to get rid of the gateway param, for testnet and mainnet this value is read from protocol contracts, but for localnet that's not the case. I see two options:
When localnet starts, it creates a file {
"pid": 97125,
"addresses": [
{
"chain": "zetachain",
"type": "gatewayZEVM",
"address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
},
{
"chain": "zetachain",
"type": "systemContract",
"address": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
}, Maybe we do something like this: const jsonData = JSON.parse(fs.readFileSync("localnet.json", "utf8")); // if hre.network.name === localhost
const contracts = jsonData?.addresses;
const client = new ZetaChainClient({ signer, contracts }); If |
For functions, we can make the |
@lukema95 Eventually, I want to have contracts in the zetachain client constructor, but for now yes, let's start with what you suggested. |
Update both functions in
packages/client/src
and tasks inpackages/tasks/src
for:Remove gatewayEVM/gatewayZEVM from the argument list. Instead, import the JSON from protocol contract's npm and find gateway address. I don't think we can use
getAddress
, because the functions in theclient/src
don't have access to chain labels specified in hardhat config, so the idea is for a function to get chain ID from thesigner
and find the gateway address based on chain ID.Make
txOptions
optional.Extract common functionality like parsing value array in a separate file to be reused across functions.
Make these functions convenient to use both from Hardhat tasks as well as the frontend, because the next task is to update the UniversalKit with these functions.
The text was updated successfully, but these errors were encountered: