From 7009be5767f0afe05ef59acbec2fcd0faf237348 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 2 Feb 2024 13:06:02 +0200 Subject: [PATCH] Add skale-allocator files --- .../skale-allocator/skaleAllocatorInstance.ts | 45 +++++++++++++++++++ .../skale-allocator/skaleAllocatorProject.ts | 19 ++++++++ 2 files changed, 64 insertions(+) create mode 100644 typescript/base/src/projects/skale-allocator/skaleAllocatorInstance.ts create mode 100644 typescript/base/src/projects/skale-allocator/skaleAllocatorProject.ts diff --git a/typescript/base/src/projects/skale-allocator/skaleAllocatorInstance.ts b/typescript/base/src/projects/skale-allocator/skaleAllocatorInstance.ts new file mode 100644 index 0000000..b223498 --- /dev/null +++ b/typescript/base/src/projects/skale-allocator/skaleAllocatorInstance.ts @@ -0,0 +1,45 @@ +import { + ContractAddress, + ContractName +} from "../../domain/types"; +import { Instance } from "../../instance"; + + +export class SkaleAllocatorInstance extends + Instance { + getContractAddress ( + name: ContractName, + args?: unknown[] + ): Promise { + if (name === "Allocator") { + return Promise.resolve(this.address); + } + if (name === "Escrow") { + const firstArgument = 0; + const beneficiary = args?.at(firstArgument) as string; + if (!this.project.network.adapter.isAddress(beneficiary)) { + throw Error("Beneficiary is not set"); + } + return this.getEscrow(beneficiary); + } + throw new Error(`Contract ${name} is not found`); + } + + // Private + + private async getEscrow (beneficiary: string) { + const allocatorAddress = await this.getContractAddress("Allocator"); + const allocatorAbi = await this.getContractAbi("Allocator"); + + return await this.project.network.adapter.makeCall( + { + "abi": allocatorAbi, + "address": allocatorAddress + }, + { + "args": [beneficiary], + "functionName": "getEscrowAddress" + } + ) as ContractAddress; + } +} diff --git a/typescript/base/src/projects/skale-allocator/skaleAllocatorProject.ts b/typescript/base/src/projects/skale-allocator/skaleAllocatorProject.ts new file mode 100644 index 0000000..ae9a7b6 --- /dev/null +++ b/typescript/base/src/projects/skale-allocator/skaleAllocatorProject.ts @@ -0,0 +1,19 @@ +import { Instance } from "../../instance"; +import { Project } from "../../project"; +import { SkaleAllocatorInstance } from "./skaleAllocatorInstance"; + +export class SkaleAllocatorProject extends + Project { + githubRepo = "https://github.com/skalenetwork/skale-manager/"; + + createInstance (address: string): Instance { + return new SkaleAllocatorInstance( + this, + address + ); + } + + getAbiFilename (version: string) { + return `${this.metadata.name}-${version}-abi.json`; + } +}