mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-09 05:30:28 +08:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import * as ethers from 'ethers';
|
|
import type { TransactionReceipt, TransactionResponse } from '@ethersproject/providers';
|
|
import type { ContractReceipt } from '@ethersproject/contracts';
|
|
|
|
import type { Config } from '@app/config';
|
|
|
|
const orgFactoryAbi = [
|
|
"function createOrg(address[], uint256) returns (address)",
|
|
"event OrgCreated(address, address)",
|
|
];
|
|
|
|
const orgAbi = ["function owner() view returns (address)"];
|
|
|
|
export class Org {
|
|
address: string
|
|
safe: string
|
|
|
|
constructor(address: string, safe: string) {
|
|
this.address = address;
|
|
this.safe = safe;
|
|
}
|
|
|
|
static fromReceipt(receipt: ContractReceipt): Org | null {
|
|
let event = receipt.events?.find(e => e.event === 'OrgCreated');
|
|
|
|
if (event && event.args) {
|
|
let address = event.args[0];
|
|
let safe = event.args[1];
|
|
|
|
return new Org(address, safe);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static async create(
|
|
owner: string,
|
|
config: Config,
|
|
): Promise<TransactionResponse> {
|
|
const orgFactory = new ethers.Contract(
|
|
config.orgFactory.address,
|
|
orgFactoryAbi,
|
|
config.signer
|
|
);
|
|
|
|
return orgFactory.createOrg([owner], 1, {
|
|
gasLimit: config.gasLimits.createOrg
|
|
});
|
|
}
|
|
}
|