Skip to content

Commit

Permalink
feat: update terra testnet, add ethereum public rpc endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
0x31 committed Apr 21, 2022
1 parent df3cd61 commit 28ee695
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@glif/filecoin-number": "^1.1.0",
"@glif/filecoin-rpc-client": "^1.1.0",
"@glif/filecoin-wallet-provider": "^1.1.1",
"@terra-money/terra.js": "^3.0.9",
"@terra-money/terra.js": "^3.0.11",
"@types/bchaddrjs": "^0.4.0",
"@zondax/filecoin-signing-tools": "^0.20.1",
"axios": "^0.26.1",
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/ETH/ETHHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getEthersSigner,
getNetwork,
getTransactionConfig,
Network,
} from "./ethUtils";

interface ConstructorOptions {
Expand All @@ -31,7 +32,7 @@ export class ETHHandler
Handler<ConstructorOptions, AddressOptions, BalanceOptions, TxOptions>
{
private readonly privateKey: string;
private readonly network: string;
private readonly network: Network;

private readonly decimals = 18;

Expand Down
36 changes: 24 additions & 12 deletions src/handlers/ETH/ethUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ export const getEthersSigner = (
// Free tier - only used as a fallback.
const defaultInfuraKey = "3b7a6c29f9c048d688a848899888aa96";

export const getEndpoint = (
network: string | undefined,
ethereumNode: string | undefined,
infuraKey: string | undefined
) => {
return ethereumNode
? ethereumNode
: infuraKey || network !== "mainnet"
? `https://${network}.infura.io/v3/${infuraKey || defaultInfuraKey}`
: "https://cloudflare-eth.com";
};

export enum Network {
Mainnet = "mainnet",
Ropsten = "ropsten",
Expand All @@ -34,6 +22,13 @@ export enum Network {
Görli = "goerli",
}

const publicEndpoints: { [network in Network]?: string } = {
[Network.Mainnet]: "https://cloudflare-eth.com",
[Network.Kovan]: "https://kovan.poa.network",
[Network.Rinkeby]: "https://rinkeby-light.eth.linkpool.io",
[Network.Görli]: "https://rpc.goerli.mudit.blog",
};

export const getNetwork = (network: string): Network => {
switch (network.toLowerCase()) {
case "mainnet":
Expand All @@ -58,6 +53,23 @@ export const getNetwork = (network: string): Network => {
}
};

const infuraUrl = (network: Network, infuraKey: string) =>
`https://${network}.infura.io/v3/${infuraKey}`;

export const getEndpoint = (
network: Network,
ethereumNode: string | undefined,
infuraKey: string | undefined
): string =>
// Check if an ethereum node has been provided.
ethereumNode ||
// Check if an infura key has been provided.
(infuraKey && infuraUrl(network, infuraKey)) ||
// Check if there's a public endpoint.
publicEndpoints[network] ||
// Use the public infura key.
infuraUrl(network, defaultInfuraKey);

// Create a `txConfig` object with only the relevant fields in the `options`
// object.
export const getTransactionConfig = <T extends Overrides>(
Expand Down
6 changes: 2 additions & 4 deletions src/handlers/TERRA/TERRAHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { strip0x } from "../../lib/utils";
import { Asset, Handler } from "../../types/types";

export enum TerraNetwork {
Tequila = "tequila-0004",
Bombay = "bombay-12",
Columbus = "columbus-3",
}

Expand Down Expand Up @@ -52,9 +52,7 @@ export class TERRAHandler
sharedState?: any
) {
this.network =
network === "mainnet"
? TerraNetwork.Columbus
: TerraNetwork.Tequila;
network === "mainnet" ? TerraNetwork.Columbus : TerraNetwork.Bombay;

const client =
sharedState.client ||
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,13 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@terra-money/terra.js@^3.0.9":
version "3.0.9"
resolved "https://registry.yarnpkg.com/@terra-money/terra.js/-/terra.js-3.0.9.tgz#f9afe33d836ad0d8fcc96f728a70aa9270c373e0"
integrity sha512-jC7E8SjYiUV7nTk8g3LwQhJXlW5t2aiulB6Qg+K9dWpNzfqMn1ovuOD250gyx9aFaCilbDVLzPiZJLLbKPCO0w==
"@terra-money/terra.js@^3.0.11":
version "3.0.11"
resolved "https://registry.yarnpkg.com/@terra-money/terra.js/-/terra.js-3.0.11.tgz#55616723a2c8b0b53e321e9331db45a50ee9e068"
integrity sha512-qabXxsycWF1tEcFE3dG7FFXuIcXPlSeYgha5IYU+x4QNKiZuxT9Asi84HrCUSajQkZZ3N7ORfr+aGGE84HD+uw==
dependencies:
"@terra-money/terra.proto" "^0.1.7"
axios "^0.24.0"
axios "^0.26.1"
bech32 "^2.0.0"
bip32 "^2.0.6"
bip39 "^3.0.3"
Expand Down

0 comments on commit 28ee695

Please sign in to comment.