Skip to content

Commit

Permalink
Add initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Apr 11, 2024
1 parent e200ce4 commit 70276d0
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions typescript/base/src/domain/constants.ts
Original file line number Diff line number Diff line change
@@ -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";
10 changes: 10 additions & 0 deletions typescript/base/src/projects/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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"
Expand All @@ -38,6 +43,11 @@ export const createProject =
network,
projects.mainnetIma
);
} else if (name === projects.schainIma.name) {
return new SchainImaProject<ContractType>(
network,
projects.schainIma
);
} else if (name === projects.skaleAllocator.name) {
return new SkaleAllocatorProject<ContractType>(
network,
Expand Down
56 changes: 56 additions & 0 deletions typescript/base/src/projects/ima/schain/SchainImaInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ImaInstance } from "../ImaInstance";


export class SchainImaInstance<ContractType> extends
ImaInstance<ContractType> {
static PREDEPLOYED = new Map<string, string>([
[
"CommunityLocker",
"0xD2aaa00300000000000000000000000000000000"
],
[
"KeyStorage",
"0xd2aaa00200000000000000000000000000000000"
],
[
"MessageProxyForSchain",
"0xd2AAa00100000000000000000000000000000000"
],
[
"ProxyAdmin",
"0xd2aAa00000000000000000000000000000000000"
],
[
"TokenManagerERC1155",
"0xD2aaA00900000000000000000000000000000000"
],
[
"TokenManagerERC20",
"0xD2aAA00500000000000000000000000000000000"
],
[
"TokenManagerERC721",
"0xD2aaa00600000000000000000000000000000000"
],
[
"TokenManagerERC721WithMetadata",
"0xd2AaA00a00000000000000000000000000000000"
],
[
"TokenManagerEth",
"0xd2AaA00400000000000000000000000000000000"
],
[
"TokenManagerLinker",
"0xD2aAA00800000000000000000000000000000000"
]
]);

getContractAddress (name: string): Promise<string> {

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (20)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (16)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (19)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (18)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (18)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (16)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (20)

Expected 'this' to be used by class method 'getContractAddress'

Check failure on line 49 in typescript/base/src/projects/ima/schain/SchainImaInstance.ts

View workflow job for this annotation

GitHub Actions / typescript (19)

Expected 'this' to be used by class method 'getContractAddress'
if (SchainImaInstance.PREDEPLOYED.has(name)) {
return Promise.resolve(SchainImaInstance.PREDEPLOYED.
get(name) as string);
}
throw new Error(`Can't get address of ${name} contract`);
}
}
26 changes: 26 additions & 0 deletions typescript/base/src/projects/ima/schain/SchainImaProject.ts
Original file line number Diff line number Diff line change
@@ -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<ContractType> extends
ImaProject<ContractType> {
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<ContractType> {
return new SchainImaInstance(
this,
address
);
}
}

0 comments on commit 70276d0

Please sign in to comment.