-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b4e11e
commit 7009be5
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
typescript/base/src/projects/skale-allocator/skaleAllocatorInstance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
typescript/base/src/projects/skale-allocator/skaleAllocatorProject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; | ||
} | ||
} |