Skip to content

Commit

Permalink
feat: implement isTestnet method
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Oct 25, 2023
1 parent 6f610b4 commit 3000267
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
1 change: 0 additions & 1 deletion aave_integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ export default {
treasuryAddress: '0xd0A1E359811322d97991E03f863a0C30C2cF029C',
agreementFee: 15,
},
testNet: true,
} as NeverminedOptions
4 changes: 2 additions & 2 deletions src/keeper/Keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export class Keeper extends Instantiable {
`Keeper could not connect to ${await this.getNetworkName()} - ${err.message} ${err.stack}`,
)
}
const chainId = Number((await this.web3.getNetwork()).chainId)

if (this.config.testNet) {
if (KeeperUtils.isTestnet(chainId)) {
this.instances.dispenser = await Dispenser.getInstance(this.instantiableConfig)
this.instances.token = await Token.getInstance(this.instantiableConfig)
}
Expand Down Expand Up @@ -210,7 +211,6 @@ export class Keeper extends Instantiable {
eventHandler: new EventHandler(),
}
// version
const chainId = Number((await this.web3.getNetwork()).chainId)
this.network = {
chainId,
version: this.didRegistry.version.replace('v', ''),
Expand Down
59 changes: 58 additions & 1 deletion src/keeper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,64 @@ export async function getNetworkName(networkId: number): Promise<string> {
throw new KeeperError(`Network with id ${networkId} not supported.`)
}
}

export async function isTestnet(networkId: number): Promise<boolean> {
switch (networkId) {
case 1:
return false
case 2:
return true
case 3:
return true
case 4:
return true
case 5:
return true
case 77:
return false
case 99:
return false
case 42:
return true
case 100:
return false
case 137:
return false
case 1337:
return true
case 3141:
return true
case 10200:
return true
case 31337:
return true
case 8996:
return true
case 8997:
return true
case 8998:
return true
case 42220:
return false
case 44787:
return true
case 62320:
return true
case 80001:
return true
case 42161:
return false
case 421613:
return true
case 1313161554:
return false
case 1313161555:
return true
case 1313161556:
return true
default:
throw new KeeperError(`Network with id ${networkId} not supported.`)
}
}
// Wrapper for implementing web3 provider. Needed for OpenGSN
export interface JsonRpcPayload {
jsonrpc: string
Expand Down
2 changes: 0 additions & 2 deletions src/models/NeverminedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,4 @@ export class NeverminedOptions {
* Use a gas station to calculate transaction fees
*/
public gasStationUri?: string

public testNet?: boolean
}
1 change: 0 additions & 1 deletion test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const config = {
treasuryAddress: '0xd0A1E359811322d97991E03f863a0C30C2cF029C',
agreementFee: 15,
},
testNet: true,
} as NeverminedOptions

if (process.env.SEED_WORDS) {
Expand Down

0 comments on commit 3000267

Please sign in to comment.