From 70276d0bb3400ad403cb94fd66d98102c4ac1a0c Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 11 Apr 2024 18:37:06 +0300 Subject: [PATCH] Add initial implementation --- typescript/base/src/domain/constants.ts | 1 + typescript/base/src/projects/factory.ts | 10 ++++ .../projects/ima/schain/SchainImaInstance.ts | 56 +++++++++++++++++++ .../projects/ima/schain/SchainImaProject.ts | 26 +++++++++ 4 files changed, 93 insertions(+) create mode 100644 typescript/base/src/projects/ima/schain/SchainImaInstance.ts create mode 100644 typescript/base/src/projects/ima/schain/SchainImaProject.ts diff --git a/typescript/base/src/domain/constants.ts b/typescript/base/src/domain/constants.ts index f1a372e..2599ff0 100644 --- a/typescript/base/src/domain/constants.ts +++ b/typescript/base/src/domain/constants.ts @@ -1,2 +1,3 @@ +export const PREDEPLOYED_ALIAS = "predeployed"; export const REPOSITORY_URL = "https://skalenetwork.github.io/skale-contracts/"; export const METADATA_FILENAME = "metadata.json"; diff --git a/typescript/base/src/projects/factory.ts b/typescript/base/src/projects/factory.ts index cb3d059..05281d9 100644 --- a/typescript/base/src/projects/factory.ts +++ b/typescript/base/src/projects/factory.ts @@ -4,6 +4,7 @@ import { Project } from "../project"; import { ProjectNotFoundError } from "../domain/errors/project/projectNotFoundError"; +import { SchainImaProject } from "./ima/schain/SchainImaProject"; import { SkaleAllocatorProject } from "./skale-allocator/skaleAllocatorProject"; import { SkaleManagerProject } from "./skale-manager/skaleManagerProject"; @@ -13,6 +14,10 @@ export const projects = { "name": "mainnet-ima", "path": "mainnet-ima" }, + "schainIma": { + "name": "schain-ima", + "path": "schain-ima" + }, "skaleAllocator": { "name": "skale-allocator", "path": "skale-allocator" @@ -38,6 +43,11 @@ export const createProject = network, projects.mainnetIma ); + } else if (name === projects.schainIma.name) { + return new SchainImaProject( + network, + projects.schainIma + ); } else if (name === projects.skaleAllocator.name) { return new SkaleAllocatorProject( network, diff --git a/typescript/base/src/projects/ima/schain/SchainImaInstance.ts b/typescript/base/src/projects/ima/schain/SchainImaInstance.ts new file mode 100644 index 0000000..5e4d3d4 --- /dev/null +++ b/typescript/base/src/projects/ima/schain/SchainImaInstance.ts @@ -0,0 +1,56 @@ +import { ImaInstance } from "../ImaInstance"; + + +export class SchainImaInstance extends + ImaInstance { + static PREDEPLOYED = new Map([ + [ + "CommunityLocker", + "0xD2aaa00300000000000000000000000000000000" + ], + [ + "KeyStorage", + "0xd2aaa00200000000000000000000000000000000" + ], + [ + "MessageProxyForSchain", + "0xd2AAa00100000000000000000000000000000000" + ], + [ + "ProxyAdmin", + "0xd2aAa00000000000000000000000000000000000" + ], + [ + "TokenManagerERC1155", + "0xD2aaA00900000000000000000000000000000000" + ], + [ + "TokenManagerERC20", + "0xD2aAA00500000000000000000000000000000000" + ], + [ + "TokenManagerERC721", + "0xD2aaa00600000000000000000000000000000000" + ], + [ + "TokenManagerERC721WithMetadata", + "0xd2AaA00a00000000000000000000000000000000" + ], + [ + "TokenManagerEth", + "0xd2AaA00400000000000000000000000000000000" + ], + [ + "TokenManagerLinker", + "0xD2aAA00800000000000000000000000000000000" + ] + ]); + + getContractAddress (name: string): Promise { + if (SchainImaInstance.PREDEPLOYED.has(name)) { + return Promise.resolve(SchainImaInstance.PREDEPLOYED. + get(name) as string); + } + throw new Error(`Can't get address of ${name} contract`); + } +} diff --git a/typescript/base/src/projects/ima/schain/SchainImaProject.ts b/typescript/base/src/projects/ima/schain/SchainImaProject.ts new file mode 100644 index 0000000..9a4fd24 --- /dev/null +++ b/typescript/base/src/projects/ima/schain/SchainImaProject.ts @@ -0,0 +1,26 @@ +import { ImaProject } from "../ImaProject"; +import { Instance } from "../../../instance"; +import { PREDEPLOYED_ALIAS } from "../../../domain/constants"; +import { SchainImaInstance } from "./SchainImaInstance"; + +export class SchainImaProject extends + ImaProject { + getAbiFilename (version: string) { + return `${this.metadata.name}-${version}-abi.json`; + } + + getInstance (aliasOrAddress: string) { + if (aliasOrAddress === PREDEPLOYED_ALIAS) { + return this.createInstance(SchainImaInstance.PREDEPLOYED. + get("MessageProxyForSchain")!); + } + return super.getInstance(aliasOrAddress); + } + + createInstance (address: string): Instance { + return new SchainImaInstance( + this, + address + ); + } +}