-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from zer0-os/je/configurable-config
Allow modification of zAuction config before an instance is created
- Loading branch information
Showing
8 changed files
with
193 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}\\build\\src\\index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}\\build\\src\\index.js" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Mocha Tests", | ||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"-r", | ||
"ts-node/register", | ||
"--slow", | ||
"5000", | ||
"test/**/*.test.ts", | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"internalConsoleOptions": "openOnSessionStart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ethers } from "ethers"; | ||
import * as zAuction from "@zero-tech/zauction-sdk"; | ||
|
||
export const zAuctionConfiguration = ( | ||
web3Provider: ethers.providers.Web3Provider, | ||
apiUri?: string, | ||
subgraphUri?: string, | ||
zAuctionAddress?: string, | ||
tokenContract?: string | ||
): zAuction.Config => { | ||
let defaultApiUri; | ||
let defaultSubgraphUri; | ||
let defaultZAuctionAddress; | ||
let defaultTokenContract; | ||
|
||
if (web3Provider.network.name == "mainnet") { | ||
defaultApiUri = "https://mainnet.zauction.api.zero.tech/api"; | ||
defaultSubgraphUri = | ||
"https://api.thegraph.com/subgraphs/name/zer0-os/zauction"; | ||
defaultZAuctionAddress = "0x05cBD37cA528B7ea50800aA80ddD0F9F30C952F0"; | ||
defaultTokenContract = "0xc2e9678A71e50E5AEd036e00e9c5caeb1aC5987D"; | ||
} else if (web3Provider.network.name === "kovan") { | ||
defaultApiUri = "https://zauction-kovan-api.herokuapp.com/api"; | ||
defaultSubgraphUri = | ||
"https://api.thegraph.com/subgraphs/name/zer0-os/zauction-kovan"; | ||
defaultZAuctionAddress = "0x18A804a028aAf1F30082E91d2947734961Dd7f89"; | ||
defaultTokenContract = "0xC613fCc3f81cC2888C5Cccc1620212420FFe4931"; | ||
} else { | ||
throw Error(`Network ${web3Provider.network.name} is not supported`); | ||
} | ||
|
||
return { | ||
web3Provider: web3Provider, | ||
apiUri: apiUri ?? defaultApiUri, | ||
subgraphUri: subgraphUri ?? defaultSubgraphUri, | ||
zAuctionAddress: zAuctionAddress ?? defaultZAuctionAddress, | ||
tokenContract: tokenContract ?? defaultTokenContract, | ||
} as zAuction.Config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import * as zAuction from "@zero-tech/zauction-sdk"; | ||
import { zAuctionRoute } from "../types"; | ||
import { zAuctionRoute, RouteUriToInstance } from "../types"; | ||
import { Config } from ".."; | ||
|
||
type GetDomainNameFromIdFunction = (domainId: string) => Promise<string>; | ||
|
||
export const getZAuctionInstanceForDomain = async ( | ||
domainId: string, | ||
zAuctionRoutes: zAuctionRoute[], | ||
routeUriToInstance: RouteUriToInstance, | ||
getDomainName: GetDomainNameFromIdFunction | ||
): Promise<zAuction.Instance> => { | ||
const domainName = await getDomainName(domainId); | ||
|
||
for (const route of zAuctionRoutes) { | ||
const match = RegExp(`^${route.uriPattern}`).exec(domainName); | ||
if (match) { | ||
return route.instance; | ||
return routeUriToInstance[route.uriPattern]; | ||
} | ||
} | ||
|
||
throw Error(`No zAuction Route configured for this domain!`); | ||
}; | ||
|
||
export const createZAuctionInstances = (config: Config): RouteUriToInstance => { | ||
const routeUriToInstance: RouteUriToInstance = {}; | ||
for (const route of config.zAuctionRoutes) { | ||
routeUriToInstance[route.uriPattern] = zAuction.createInstance( | ||
route.config | ||
); | ||
} | ||
return routeUriToInstance; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.