Skip to content

Commit

Permalink
Merge pull request #71 from skalenetwork/paymaster
Browse files Browse the repository at this point in the history
Add paymaster support
  • Loading branch information
DimaStebaev authored Aug 14, 2024
2 parents c001eea + 633b78c commit e810a21
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/src/skale_contracts/projects/paymaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_contract_address(
return self.address
if name == "PaymasterAccessManager":
return to_canonical_address(
self.get_contract("FastForwardPaymaster")
self.get_contract("Paymaster")
.functions.authority().call()
)
raise RuntimeError(f"Can't get address of {name} contract")
Expand Down
10 changes: 10 additions & 0 deletions typescript/base/src/projects/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MainnetImaProject } from "./ima/mainnet/MainnetImaProject";
import { Network } from "../network";
import { PaymasterProject } from "./paymaster/paymasterProject";
import { Project } from "../project";
import {
ProjectNotFoundError
Expand All @@ -14,6 +15,10 @@ export const projects = {
"name": "mainnet-ima",
"path": "mainnet-ima"
},
"paymaster": {
"name": "paymaster",
"path": "paymaster"
},
"schainIma": {
"name": "schain-ima",
"path": "schain-ima"
Expand Down Expand Up @@ -53,6 +58,11 @@ export const createProject =
network,
projects.skaleAllocator
);
} else if (name === projects.paymaster.name) {
return new PaymasterProject<ContractType>(
network,
projects.paymaster
);
}
throw new ProjectNotFoundError(`Project with name ${name} is unknown`);
};
40 changes: 40 additions & 0 deletions typescript/base/src/projects/paymaster/paymasterInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
ContractAddress,
ContractName
} from "../../domain/types";
import { Instance } from "../../instance";


export class PaymasterInstance<ContractType> extends
Instance<ContractType> {
async getContractAddress (name: ContractName): Promise<ContractAddress> {
if ([
"Paymaster",
"FastForwardPaymaster"
].includes(name)) {
return this.address;
}
if (name === "PaymasterAccessManager") {
return await this.callPaymaster(
"authority",
[]
) as ContractAddress;
}
throw new Error(`Contract ${name} is not found`);
}

// Private

private async callPaymaster (functionName: string, args: unknown[]) {
return this.project.network.adapter.makeCall(
{
"abi": await this.getContractAbi("Paymaster"),
"address": this.address
},
{
args,
functionName
}
);
}
}
19 changes: 19 additions & 0 deletions typescript/base/src/projects/paymaster/paymasterProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Instance } from "../../instance";
import { PaymasterInstance } from "./paymasterInstance";
import { Project } from "../../project";

export class PaymasterProject<ContractType> extends
Project<ContractType> {
githubRepo = "https://github.com/skalenetwork/paymaster/";

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

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

0 comments on commit e810a21

Please sign in to comment.