diff --git a/dictionary b/dictionary index 1187fd7..76852fd 160000 --- a/dictionary +++ b/dictionary @@ -1 +1 @@ -Subproject commit 1187fd7c0a2665788895da215a56906ed697bb0f +Subproject commit 76852fd21bdb6afb52820d8fac31fd8dcdb4755c diff --git a/typescript/base/.eslintrc.cjs b/typescript/base/.eslintrc.cjs index 70a084c..896c99a 100644 --- a/typescript/base/.eslintrc.cjs +++ b/typescript/base/.eslintrc.cjs @@ -24,6 +24,7 @@ module.exports = { "error", "separate-lines" ], + "no-warning-comments": ["warn"], "object-curly-spacing": [ "error", "always" diff --git a/typescript/base/package.json b/typescript/base/package.json index 9a5d4c8..bed09b4 100644 --- a/typescript/base/package.json +++ b/typescript/base/package.json @@ -25,6 +25,8 @@ "types": "lib/index.d.ts", "version": "1.0.1", "dependencies": { - "axios": "^1.4.0" + "@renovatebot/pep440": "^3.0.20", + "axios": "^1.4.0", + "semver": "^7.6.0" } } 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/instance.ts b/typescript/base/src/instance.ts index 9e22f59..58a55c7 100644 --- a/typescript/base/src/instance.ts +++ b/typescript/base/src/instance.ts @@ -1,9 +1,12 @@ +import * as semver from "semver"; import { ContractAddress, ContractName, MainContractAddress, SkaleABIFile } from "./domain/types"; +import { parse, stringify } from "@renovatebot/pep440/lib/version"; +import { Pep440Version } from "@renovatebot/pep440"; import { Project } from "./project"; export type InstanceData = { @@ -27,6 +30,37 @@ const defaultVersionAbi = [ } ]; +const processSemver = (semVersion: semver.SemVer) => { + if (!semVersion.prerelease.length) { + const defaultPrerelease = 0; + semVersion.prerelease = [ + "stable", + defaultPrerelease + ]; + } + return semVersion.format(); +}; + +const processPep440 = (pyVersion: Pep440Version) => { + const replaceMap = new Map([ + [ + "a", + "develop" + ], + [ + "b", + "beta" + ] + ]); + pyVersion.pre = pyVersion.pre.map((value: string | number) => { + if (typeof value === "string" && replaceMap.has(value)) { + return `-${replaceMap.get(value)!}.`; + } + return value; + }); + return stringify(pyVersion)!; +}; + export abstract class Instance { protected project: Project; @@ -87,9 +121,17 @@ export abstract class Instance { private async getVersion () { if (typeof this.version === "undefined") { - this.version = await this.queryVersion(); - if (!this.version.includes("-")) { - this.version = `${this.version}-stable.0`; + const rawVersion = await this.queryVersion(); + const semVersion = semver.parse(rawVersion); + if (semVersion) { + this.version = processSemver(semVersion); + } else { + const pyVersion = parse(rawVersion); + if (pyVersion) { + this.version = processPep440(pyVersion); + } else { + throw new Error(`Can't parse version ${rawVersion}`); + } } } return this.version; diff --git a/typescript/base/src/project.ts b/typescript/base/src/project.ts index f77af47..4087127 100644 --- a/typescript/base/src/project.ts +++ b/typescript/base/src/project.ts @@ -33,7 +33,7 @@ export abstract class Project { } async downloadAbiFile (version: string) { - const exceptions = []; + const exceptions: string[] = []; for (const abiUrl of this.getAbiUrls(version)) { try { // Await expression should be executed only @@ -42,10 +42,10 @@ export abstract class Project { const response = await axios.get(abiUrl); return response.data as SkaleABIFile; } catch (exception) { - exceptions.push(exception); + exceptions.push(`\nDownloading from ${abiUrl} - ${exception}`); } } - throw new Error(exceptions.toString()); + throw new Error(exceptions.join("")); } getAbiUrls (version: string) { 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..b130074 --- /dev/null +++ b/typescript/base/src/projects/ima/schain/SchainImaInstance.ts @@ -0,0 +1,59 @@ +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 (name === "MessageProxyForSchain") { + return Promise.resolve(this.address); + } + 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 + ); + } +} diff --git a/typescript/base/yarn.lock b/typescript/base/yarn.lock index 4882374..b0674b3 100644 --- a/typescript/base/yarn.lock +++ b/typescript/base/yarn.lock @@ -106,16 +106,25 @@ __metadata: languageName: node linkType: hard +"@renovatebot/pep440@npm:^3.0.20": + version: 3.0.20 + resolution: "@renovatebot/pep440@npm:3.0.20" + checksum: f7014e1774bd7df0db8d08ea9aa8432a668f829f5f6233aee28dc598dc43a4011e5a65962a8d5f295b39b1bb550fd172b85ecb5bb47b8e9cd8ab5db69dabb8e0 + languageName: node + linkType: hard + "@skalenetwork/skale-contracts@workspace:.": version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts@workspace:." dependencies: + "@renovatebot/pep440": ^3.0.20 "@tsconfig/recommended": ^1.0.2 "@types/node": ^20.2.5 "@typescript-eslint/eslint-plugin": ^6.0.0 "@typescript-eslint/parser": ^6.0.0 axios: ^1.4.0 eslint: ^8.45.0 + semver: ^7.6.0 typescript: ^5.1.6 languageName: unknown linkType: soft @@ -1163,6 +1172,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.6.0": + version: 7.6.0 + resolution: "semver@npm:7.6.0" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c + languageName: node + linkType: hard + "shebang-command@npm:^2.0.0": version: 2.0.0 resolution: "shebang-command@npm:2.0.0" diff --git a/typescript/ethers-v5/yarn.lock b/typescript/ethers-v5/yarn.lock index 6815fd2..66424e9 100644 --- a/typescript/ethers-v5/yarn.lock +++ b/typescript/ethers-v5/yarn.lock @@ -508,6 +508,13 @@ __metadata: languageName: node linkType: hard +"@renovatebot/pep440@npm:^3.0.20": + version: 3.0.20 + resolution: "@renovatebot/pep440@npm:3.0.20" + checksum: f7014e1774bd7df0db8d08ea9aa8432a668f829f5f6233aee28dc598dc43a4011e5a65962a8d5f295b39b1bb550fd172b85ecb5bb47b8e9cd8ab5db69dabb8e0 + languageName: node + linkType: hard + "@skalenetwork/skale-contracts-ethers-v5@workspace:.": version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts-ethers-v5@workspace:." @@ -526,7 +533,9 @@ __metadata: version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts@portal:../base/::locator=%40skalenetwork%2Fskale-contracts-ethers-v5%40workspace%3A." dependencies: + "@renovatebot/pep440": ^3.0.20 axios: ^1.4.0 + semver: ^7.6.0 languageName: node linkType: soft @@ -1703,6 +1712,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.6.0": + version: 7.6.0 + resolution: "semver@npm:7.6.0" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c + languageName: node + linkType: hard + "shebang-command@npm:^2.0.0": version: 2.0.0 resolution: "shebang-command@npm:2.0.0" diff --git a/typescript/ethers-v6/yarn.lock b/typescript/ethers-v6/yarn.lock index f96c89c..05283d1 100644 --- a/typescript/ethers-v6/yarn.lock +++ b/typescript/ethers-v6/yarn.lock @@ -127,6 +127,13 @@ __metadata: languageName: node linkType: hard +"@renovatebot/pep440@npm:^3.0.20": + version: 3.0.20 + resolution: "@renovatebot/pep440@npm:3.0.20" + checksum: f7014e1774bd7df0db8d08ea9aa8432a668f829f5f6233aee28dc598dc43a4011e5a65962a8d5f295b39b1bb550fd172b85ecb5bb47b8e9cd8ab5db69dabb8e0 + languageName: node + linkType: hard + "@skalenetwork/skale-contracts-ethers-v6@workspace:.": version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts-ethers-v6@workspace:." @@ -145,7 +152,9 @@ __metadata: version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts@portal:../base/::locator=%40skalenetwork%2Fskale-contracts-ethers-v6%40workspace%3A." dependencies: + "@renovatebot/pep440": ^3.0.20 axios: ^1.4.0 + semver: ^7.6.0 languageName: node linkType: soft @@ -1214,6 +1223,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.6.0": + version: 7.6.0 + resolution: "semver@npm:7.6.0" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c + languageName: node + linkType: hard + "shebang-command@npm:^2.0.0": version: 2.0.0 resolution: "shebang-command@npm:2.0.0"