Skip to content

Commit

Permalink
fix get gateway address
Browse files Browse the repository at this point in the history
  • Loading branch information
lukema95 committed Jan 7, 2025
1 parent b70a501 commit 51c699e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@zetachain/faucet-cli": "^4.1.1",
"@zetachain/networks": "v10.0.0",
"@zetachain/protocol-contracts": "11.0.0-rc3",
"@zetachain/protocol-contracts": "11.0.0-rc4",
"axios": "^1.4.0",
"bech32": "^2.0.0",
"bip39": "^3.1.0",
Expand Down
12 changes: 5 additions & 7 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class ZetaChainClient {
});
}

public getGatewayAddress(): string {
public async getGatewayAddress(): Promise<string> {
if (this.network === "localnet" || this.network === "localhost") {
const gateway = (this.contracts as LocalnetAddress[]).find(
(item) => item.type === "gatewayZEVM"
Expand All @@ -191,20 +191,18 @@ export class ZetaChainClient {
let gateway;
if (this.wallet) {
try {
const chainId = await this.wallet!.getChainId();
gateway = (this.contracts as MainnetTestnetAddress[]).find(
async (item) =>
(await this.wallet!.getChainId()) === item.chain_id &&
item.type === "gateway"
(item) => chainId === item.chain_id && item.type === "gateway"
);
} catch (error) {
throw new Error("Failed to get gateway address: " + error);
}
} else {
try {
const chainId = await this.signer!.getChainId();
gateway = (this.contracts as MainnetTestnetAddress[]).find(
async (item) =>
(await this.signer!.getChainId()) === item.chain_id &&
item.type === "gateway"
(item) => chainId === item.chain_id && item.type === "gateway"
);
} catch (error) {
throw new Error("Failed to get gateway address: " + error);
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/evmCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const evmCall = async function (
) {
const signer = this.signer;
const { utils } = ethers;
const gatewayEvmAddress = args.gatewayEvm || this.getGatewayAddress();
const gatewayEvmAddress = args.gatewayEvm || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayEvmAddress,
GatewayABI.abi,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/evmDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const evmDeposit = async function (
) {
const signer = this.signer;
const { utils } = ethers;
const gatewayEvmAddress = args.gatewayEvm || this.getGatewayAddress();
const gatewayEvmAddress = args.gatewayEvm || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayEvmAddress,
GatewayABI.abi,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/evmDepositAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const evmDepositAndCall = async function (
) {
const signer = this.signer;
const { utils } = ethers;
const gatewayEvmAddress = args.gatewayEvm || this.getGatewayAddress();
const gatewayEvmAddress = args.gatewayEvm || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayEvmAddress,
GatewayABI.abi,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/zetachainCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const zetachainCall = async function (
const signer = this.signer;
const { utils } = ethers;
const gatewayZetaChainAddress =
args.gatewayZetaChain || this.getGatewayAddress();
args.gatewayZetaChain || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayZetaChainAddress,
GatewayABI.abi,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/zetachainWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const zetachainWithdraw = async function (
const { utils } = ethers;

const gatewayZetaChainAddress =
args.gatewayZetaChain || this.getGatewayAddress();
args.gatewayZetaChain || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayZetaChainAddress,
GatewayABI.abi,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/zetachainWithdrawAndCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const zetachainWithdrawAndCall = async function (
const { utils } = ethers;

const gatewayZetaChainAddress =
args.gatewayZetaChain || this.getGatewayAddress();
args.gatewayZetaChain || (await this.getGatewayAddress());
const gateway = new ethers.Contract(
gatewayZetaChainAddress,
GatewayABI.abi,
Expand Down
39 changes: 7 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2800,10 +2800,10 @@
ethereumjs-util "^7.1.5"
secp256k1 "^5.0.0"

"@zetachain/protocol-contracts@11.0.0-rc3":
version "11.0.0-rc3"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-11.0.0-rc3.tgz#9b719391d0728fd1b4e046c5f496180a45ecf0d5"
integrity sha512-Q8lOFOi7S1wdOfOBZPTxsOoyV6kyWwYEhg4vk+HmB36n0Q6A2VvTI7qmw8rxCvq0a5BUASC8IYx0+HzsOPvNOw==
"@zetachain/protocol-contracts@11.0.0-rc4":
version "11.0.0-rc4"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-11.0.0-rc4.tgz#2e2df98734793873e9c50629f6ec9f5eec6f9f54"
integrity sha512-7MJzEyUad7JgHucveIhtU8aaPkoMMzsfhKkh9MDMdxUzlaOmmxrQw2hi5B2b7UPxw2K9vFffkmIox6gd6c1+Yw==
dependencies:
"@openzeppelin/contracts" "^5.0.2"
"@openzeppelin/contracts-upgradeable" "^5.0.2"
Expand Down Expand Up @@ -8959,7 +8959,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -8976,15 +8976,6 @@ string-width@^2.1.1:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -9036,7 +9027,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -9057,13 +9048,6 @@ strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -10073,7 +10057,7 @@ workerpool@^6.5.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -10091,15 +10075,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 51c699e

Please sign in to comment.