Remove deprecated Gnosis org functionality

This functionality is deprecated and the dependencies prevent us from
upgrading our stack.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-10-11 15:36:01 +02:00
parent 4bac3fcfdc
commit cb12d8eeab
12 changed files with 69 additions and 948 deletions
+9 -135
View File
@@ -1,140 +1,22 @@
import * as ethers from "ethers";
import type { TransactionResponse } from "@ethersproject/providers";
import { OperationType } from "@gnosis.pm/safe-core-sdk-types";
import { assert } from "@app/error";
import * as utils from "@app/utils";
import * as cache from "@app/cache";
import type { Safe } from "@app/utils";
import type { Config } from "@app/config";
import * as ethers from "ethers";
import * as cache from "@app/cache";
import * as utils from "@app/utils";
import { assert } from "@app/error";
export class Org {
address: string;
owner: string;
name?: string | null;
safe?: Safe | null;
constructor(
address: string,
owner: string,
name?: string | null,
safe?: Safe | null,
) {
constructor(address: string, owner: string, name?: string | null) {
assert(ethers.utils.isAddress(address), "address must be valid");
this.address = address.toLowerCase(); // Don't store address checksum.
this.owner = owner;
this.name = name;
this.safe = safe;
}
async setName(name: string, config: Config): Promise<TransactionResponse> {
assert(config.signer);
const org = new ethers.Contract(
this.address,
config.abi.org,
config.signer,
);
return org.setName(name, config.provider.network.ensAddress, {
gasLimit: 200_000,
});
}
async setNameMultisig(name: string, config: Config): Promise<void> {
assert(config.signer);
assert(config.safe.client);
const safeAddress = ethers.utils.getAddress(this.owner);
const orgAddress = ethers.utils.getAddress(this.address);
const org = new ethers.Contract(
this.address,
config.abi.org,
config.signer,
);
const unsignedTx = await org.populateTransaction.setName(
name,
config.provider.network.ensAddress,
);
const txData = unsignedTx.data;
if (!txData) {
throw new Error(
"Org::setNameMultisig: Could not generate transaction for `setName` call",
);
}
const safeTx = {
to: orgAddress,
value: ethers.constants.Zero.toString(),
data: txData,
operation: OperationType.Call,
};
await utils.proposeSafeTransaction(safeTx, safeAddress, config);
}
async setOwner(
address: string,
config: Config,
): Promise<TransactionResponse> {
assert(config.signer);
const org = new ethers.Contract(
this.address,
config.abi.org,
config.signer,
);
return org.setOwner(address);
}
async setOwnerMultisig(owner: string, config: Config): Promise<void> {
assert(config.signer);
assert(config.safe.client);
const safeAddress = ethers.utils.getAddress(this.owner);
const orgAddress = ethers.utils.getAddress(this.address);
const org = new ethers.Contract(
this.address,
config.abi.org,
config.signer,
);
const unsignedTx = await org.populateTransaction.setOwner(owner);
const txData = unsignedTx.data;
if (!txData) {
throw new Error(
"Org::setOwnerMultisig: Could not generate transaction for `setOwner` call",
);
}
const safeTx = {
to: orgAddress,
value: ethers.constants.Zero.toString(),
data: txData,
operation: OperationType.Call,
};
await utils.proposeSafeTransaction(safeTx, safeAddress, config);
}
async getMembers(config: Config): Promise<Array<string>> {
if (this.safe) return this.safe.owners;
const safe = await this.getSafe(config);
if (safe) {
return safe.owners;
}
return [];
}
async getSafe(config: Config): Promise<Safe | null> {
if (this.safe) return this.safe;
return utils.getSafe(this.owner, config);
}
async isMember(address: string, config: Config): Promise<boolean> {
const members = await this.getMembers(config);
return members.includes(address.toLowerCase());
}
static async get(addressOrName: string, config: Config): Promise<Org | null> {
@@ -143,26 +25,18 @@ export class Org {
try {
const [owner, resolved] = await resolveOrgOwner(org);
const safe = await utils.getSafe(owner, config);
// If what is resolved is not the same as the input, it's because we
// were given a name.
if (utils.isAddressEqual(addressOrName, resolved)) {
return new Org(resolved, owner, null, safe);
return new Org(resolved, owner, null);
} else {
return new Org(resolved, owner, addressOrName, safe);
return new Org(resolved, owner, addressOrName);
}
} catch (e) {
console.error(e);
return null;
}
}
static async getOrgsByMember(
_owner: string,
_config: Config,
): Promise<Org[]> {
return [];
}
}
export const getOrgContract = cache.cached(