Skip to content

Commit

Permalink
Add skale-allocator files
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Feb 2, 2024
1 parent 2b4e11e commit 7009be5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
ContractAddress,
ContractName
} from "../../domain/types";
import { Instance } from "../../instance";


export class SkaleAllocatorInstance<ContractType> extends
Instance<ContractType> {
getContractAddress (
name: ContractName,
args?: unknown[]
): Promise<ContractAddress> {
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Instance } from "../../instance";
import { Project } from "../../project";
import { SkaleAllocatorInstance } from "./skaleAllocatorInstance";

export class SkaleAllocatorProject<ContractType> extends
Project<ContractType> {
githubRepo = "https://github.com/skalenetwork/skale-manager/";

createInstance (address: string): Instance<ContractType> {
return new SkaleAllocatorInstance(
this,
address
);
}

getAbiFilename (version: string) {
return `${this.metadata.name}-${version}-abi.json`;
}
}

0 comments on commit 7009be5

Please sign in to comment.