Skip to content

Commit

Permalink
Merge pull request #9 from FreenameDomains/dev
Browse files Browse the repository at this point in the history
Freename chains and connections
  • Loading branch information
alessandrovisentini authored Sep 15, 2022
2 parents 44b8838 + 028430b commit f8d8d18
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-domain-resolver",
"version": "0.1.3",
"version": "1.0.0",
"description": "Web3 Library that enable with just one function to resolve domains on multiple web3 providers such as ENS, UnstoppableDomains and Freename",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
36 changes: 31 additions & 5 deletions src/defaults/default-connections.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { NetworkConnection, NetworkName } from "../networks/connections/network-connection.types";

export const DEFAULT_RPC_URL: Record<NetworkName, string> = {
"polygon-mumbai": "https://rpc-mumbai.matic.today",
bsc: "https://bsc-dataseed.binance.org",
bsc: "https://bsc-dataseed1.ninicoin.io",
ethereum: "https://eth-mainnet.public.blastapi.io",
polygon: "https://rpc-mainnet.matic.quiknode.pro",
aurora: "https://mainnet.aurora.dev",
cronos: "https://node.croswap.com/rpc",

//TEST
"polygon-mumbai": "https://rpc-mumbai.matic.today",
hardhat: "http://127.0.0.1:8545/",
zil: "",
hardhat: "http://127.0.0.1:8545/"
};

//theese urls can only connect to Freename smart contract addresses
export const DEFAULT_INFURA_RPC_URL: Record<NetworkName, string> = {
polygon: "https://polygon-mainnet.infura.io/v3/de21d7dc37334e459e15e172ee9d45f2",
ethereum: "https://mainnet.infura.io/v3/de21d7dc37334e459e15e172ee9d45f2",
aurora: "https://aurora-mainnet.infura.io/v3/de21d7dc37334e459e15e172ee9d45f2",
"polygon-mumbai": "",
bsc: "",
zil: "",
hardhat: "",
cronos: ""
}

export class DefaultTools {
static getDefaultConnection(networkName: NetworkName): NetworkConnection {
const url = DEFAULT_RPC_URL[networkName];
static getDefaultConnection(networkName: NetworkName, options: { infuraIfAvailable?: boolean } = {}): NetworkConnection {
const { infuraIfAvailable = false } = options
let url: string | undefined;

if (infuraIfAvailable) {
url = DEFAULT_INFURA_RPC_URL[networkName];
}

if (!url) {
url = DEFAULT_RPC_URL[networkName];
}

return {
networkName: networkName,
rpcUrl: url,
Expand Down
4 changes: 3 additions & 1 deletion src/networks/connections/network-connection.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export enum NetworkName {
ETHEREUM = "ethereum",
BSC = "bsc",
ZILLIQA = "zil",
HARDHAT = "hardhat"
HARDHAT = "hardhat",
AURORA = "aurora",
CRONOS = "cronos"
}

export type NetworkConnection = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,5 +1533,61 @@ export const FREENAME_CONTRACT_CONFS: { networkName: NetworkName, address: strin
test: true,
type: "write",
abi: FNS_ABI
}
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.POLYGON,
test: false,
type: "read",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.POLYGON,
test: false,
type: "write",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.CRONOS,
test: false,
type: "read",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.CRONOS,
test: false,
type: "write",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.BSC,
test: false,
type: "read",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.BSC,
test: false,
type: "write",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.AURORA,
test: false,
type: "read",
abi: FNS_ABI
},
{
address: "0x465ea4967479A96D4490d575b5a6cC2B4A4BEE65",
networkName: NetworkName.AURORA,
test: false,
type: "write",
abi: FNS_ABI
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FreenameResolverProvider extends BaseResolverProvider implements IR
const freenameContractConfs = cloneDeep(FREENAME_CONTRACT_CONFS);
for (const contractConf of freenameContractConfs) {
if (contractConf.test == options.testMode) {
const connection = options.connectionLibrary?.getConnection(contractConf.networkName) || DefaultTools.getDefaultConnection(contractConf.networkName);
const connection = options.connectionLibrary?.getConnection(contractConf.networkName) || DefaultTools.getDefaultConnection(contractConf.networkName, { infuraIfAvailable: true });
if (contractConf.type == "read") {
readContractConnections.push(new ContractConnection(connection, contractConf.address, contractConf.abi))
} else if (contractConf.type == "write") {
Expand Down
1 change: 1 addition & 0 deletions src/tools/name-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class NameTools {

if (detailedName.type === NameType.TLD) {
tld = domainOrTld;
tldAsciiName = detailedName.asciiName
}
else if (detailedName.type === NameType.SECOND_LEVEL_DOMAIN || detailedName.type === NameType.SUB_DOMAINED_DOMAIN) {
const nameSplitted = detailedName.name.split(".");
Expand Down

0 comments on commit f8d8d18

Please sign in to comment.