mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
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:
+4
-217
@@ -8,14 +8,10 @@
|
||||
import Icon from "@app/Icon.svelte";
|
||||
import SetName from "@app/ens/SetName.svelte";
|
||||
import SeedAddress from "@app/SeedAddress.svelte";
|
||||
import TransferOwnership from "@app/components/TransferOwnership.svelte";
|
||||
import Link from "@app/Link.svelte";
|
||||
import { getBalance, Profile, ProfileType } from "@app/profile";
|
||||
import { Profile, ProfileType } from "@app/profile";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import * as utils from "@app/utils";
|
||||
import { session } from "@app/session";
|
||||
import { Org } from "@app/base/orgs/Org";
|
||||
import Message from "@app/Message.svelte";
|
||||
import ErrorModal from "@app/ErrorModal.svelte";
|
||||
import { User } from "@app/base/users/User";
|
||||
import Projects from "@app/base/seeds/View/Projects.svelte";
|
||||
@@ -36,11 +32,6 @@
|
||||
setNameForm = SetName;
|
||||
};
|
||||
|
||||
let transferOwnerForm: typeof SvelteComponent | null = null;
|
||||
const transferOwnership = () => {
|
||||
transferOwnerForm = TransferOwnership;
|
||||
};
|
||||
|
||||
const getProjectsAndStats = async (
|
||||
seed: Seed,
|
||||
id?: string,
|
||||
@@ -53,51 +44,9 @@
|
||||
return { stats, projects };
|
||||
};
|
||||
|
||||
$: account = $session && $session.address;
|
||||
$: isOwner = (org: Org): boolean =>
|
||||
$session ? utils.isAddressEqual(org.owner, $session.address) : false;
|
||||
$: getOrgTreasury = async (
|
||||
org: Org,
|
||||
): Promise<Array<utils.Token> | undefined> => {
|
||||
const addressType = await utils.identifyAddress(org.owner, config);
|
||||
// We query the org treasury only for Gnosis Safes, to maintain some privacy for EOA org owners.
|
||||
if (addressType === utils.AddressType.Safe) {
|
||||
try {
|
||||
const tokens = await utils.getTokens(org.owner, config);
|
||||
const balance = await getBalance(org.owner, config);
|
||||
|
||||
if (!balance.isZero()) {
|
||||
// To maintain the format we hardcode the ETH specs.
|
||||
return [
|
||||
{
|
||||
balance,
|
||||
decimals: 18,
|
||||
logo: "",
|
||||
name: "Ethereum",
|
||||
symbol: "ETH",
|
||||
},
|
||||
...tokens,
|
||||
];
|
||||
} else {
|
||||
return tokens;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
$: isUserAuthorized = (address: string): boolean | null => {
|
||||
return $session && utils.isAddressEqual(address, $session.address);
|
||||
};
|
||||
$: isOrgAuthorized = async (org: Org): Promise<boolean> => {
|
||||
if ($session) {
|
||||
if (isOwner(org)) {
|
||||
return true;
|
||||
}
|
||||
return await org.isMember($session.address, config);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -161,29 +110,6 @@
|
||||
height: 1.6rem;
|
||||
align-items: center;
|
||||
}
|
||||
.members {
|
||||
margin-top: 2rem;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.members.loading {
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
.members .member {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 2rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.members .member:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
.members .member-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
main {
|
||||
width: 100%;
|
||||
@@ -192,9 +118,6 @@
|
||||
.fields {
|
||||
grid-template-columns: 5rem auto;
|
||||
}
|
||||
.members .member {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -284,32 +207,7 @@
|
||||
<div class="mobile">
|
||||
<Address compact resolve {config} address={profile.org.owner} />
|
||||
</div>
|
||||
<div class="desktop">
|
||||
{#await account && profile.org.isMember(account, config) then isMember}
|
||||
{#if isOwner(profile.org) || isMember}
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="small"
|
||||
on:click={transferOwnership}>
|
||||
Transfer
|
||||
</Button>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
<!-- Org Treasury -->
|
||||
{#await getOrgTreasury(profile.org) then tokens}
|
||||
{#if tokens && tokens.length > 0}
|
||||
<div class="label">Treasury</div>
|
||||
<div>
|
||||
{#each tokens as token}
|
||||
{` ${utils.formatBalance(token.balance, token.decimals)} ${
|
||||
token.symbol
|
||||
} `}
|
||||
{/each}
|
||||
</div>
|
||||
<div class="desktop" />
|
||||
{/if}
|
||||
{/await}
|
||||
<div class="desktop" />
|
||||
{/if}
|
||||
<!-- Org Name/Profile -->
|
||||
<div class="label">Profile</div>
|
||||
@@ -324,30 +222,7 @@
|
||||
<span class="txt-missing">Not set</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="desktop">
|
||||
{#await isOrgAuthorized(profile.org)}
|
||||
<!-- Loading -->
|
||||
{:then authorized}
|
||||
{#if authorized}
|
||||
<Button variant="secondary" size="small" on:click={setName}>
|
||||
Set
|
||||
</Button>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
{/if}
|
||||
<!-- Quorum -->
|
||||
{#await profile.org.getSafe(config) then safe}
|
||||
{#if safe}
|
||||
<div class="label">Quorum</div>
|
||||
<div>
|
||||
{safe.threshold}
|
||||
<span class="faded">of</span>
|
||||
{safe.owners.length}
|
||||
</div>
|
||||
<div class="desktop" />
|
||||
{/if}
|
||||
{/await}
|
||||
{:else}
|
||||
<!-- User Profile -->
|
||||
<div>
|
||||
@@ -360,7 +235,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="desktop">
|
||||
{#if isUserAuthorized(profile.address)}
|
||||
{#if isUserAuthorized(profile.address) && !profile.org}
|
||||
<Button variant="secondary" size="small" on:click={setName}>
|
||||
Set
|
||||
</Button>
|
||||
@@ -369,89 +244,6 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if profile.org}
|
||||
{#await profile.org.getMembers(config)}
|
||||
<Loading center />
|
||||
{:then members}
|
||||
{#if members.length > 0}
|
||||
<!-- We don't need to catch errors here, since it's not defined by user input and defaults to ETH addresses -->
|
||||
{#await Profile.getMulti(members, config)}
|
||||
<div class="members loading">
|
||||
<Loading small />
|
||||
</div>
|
||||
{:then members}
|
||||
<div class="members">
|
||||
{#each members as profile}
|
||||
<div class="member">
|
||||
<div class="member-icon">
|
||||
<Link to="/{profile.address}">
|
||||
<Avatar
|
||||
source={profile.avatar ?? profile.address}
|
||||
title={profile.address} />
|
||||
</Link>
|
||||
</div>
|
||||
<div class="desktop">
|
||||
<Address
|
||||
address={profile.address}
|
||||
compact
|
||||
resolve
|
||||
noBadge
|
||||
noAvatar
|
||||
{profile}
|
||||
{config} />
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
{:catch err}
|
||||
<Message error>
|
||||
<span class="txt-bold">Error:</span>
|
||||
failed to load org members: {err.message}.
|
||||
</Message>
|
||||
{/await}
|
||||
{:else}
|
||||
{#await Org.getOrgsByMember(profile.address, config)}
|
||||
<Loading center />
|
||||
{:then orgs}
|
||||
{#if orgs.length > 0}
|
||||
<div class="members">
|
||||
{#each orgs as org}
|
||||
<div class="member">
|
||||
<!-- We don't need to catch errors here, since it's not defined by user input and defaults to ETH addresses -->
|
||||
{#await Profile.get(org.address, ProfileType.Minimal, config)}
|
||||
<Loading small margins />
|
||||
{:then profile}
|
||||
<div class="member-icon">
|
||||
<Link to="/{profile.address}">
|
||||
<Avatar
|
||||
source={profile.avatar ?? profile.address}
|
||||
title={profile.address} />
|
||||
</Link>
|
||||
</div>
|
||||
<div class="desktop">
|
||||
<Address
|
||||
address={profile.address}
|
||||
compact
|
||||
resolve
|
||||
noBadge
|
||||
noAvatar
|
||||
{profile}
|
||||
{config} />
|
||||
</div>
|
||||
{/await}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{:catch err}
|
||||
<Message error>
|
||||
<span class="txt-bold">Error:</span>
|
||||
failed to load orgs: {err.message}.
|
||||
</Message>
|
||||
{/await}
|
||||
{/if}
|
||||
{#if profile.seed?.valid}
|
||||
<Async fetch={getProjectsAndStats(profile.seed, profile.id)} let:result>
|
||||
<Projects
|
||||
@@ -465,14 +257,9 @@
|
||||
|
||||
<svelte:component
|
||||
this={setNameForm}
|
||||
entity={profile.org ?? new User(profile.address)}
|
||||
entity={new User(profile.address)}
|
||||
{config}
|
||||
on:close={() => (setNameForm = null)} />
|
||||
<svelte:component
|
||||
this={transferOwnerForm}
|
||||
org={profile.org}
|
||||
{config}
|
||||
on:close={() => (transferOwnerForm = null)} />
|
||||
{:catch err}
|
||||
{#if err instanceof NotFoundError}
|
||||
<NotFound
|
||||
|
||||
+9
-135
@@ -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(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
// TODO: When name is registered, prompt user to edit records.
|
||||
// TODO: When transfering name, warn about transfering to org.
|
||||
import { onMount } from "svelte";
|
||||
import { navigate } from "svelte-routing";
|
||||
import type { Session } from "@app/session";
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import type { Org } from "@app/base/orgs/Org";
|
||||
import type { Config } from "@app/config";
|
||||
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
import * as utils from "@app/utils";
|
||||
import Address from "@app/Address.svelte";
|
||||
import Button from "@app/Button.svelte";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import Modal from "@app/Modal.svelte";
|
||||
import TextInput from "@app/TextInput.svelte";
|
||||
import { formatAddress, isAddress } from "@app/utils";
|
||||
|
||||
export let org: Org;
|
||||
export let config: Config;
|
||||
|
||||
const dispatch = createEventDispatcher<{ close: boolean }>();
|
||||
|
||||
let state:
|
||||
| "idle"
|
||||
// Single sig.
|
||||
| "signing"
|
||||
| "pending"
|
||||
| "success"
|
||||
// Multi sig.
|
||||
| "proposing"
|
||||
| "proposed"
|
||||
| "failed" = "idle";
|
||||
|
||||
let newOwner: string = "";
|
||||
let errorMessage: string | null = null;
|
||||
let valid: boolean = false;
|
||||
let validationMessage: string | undefined = undefined;
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (org && (await utils.isSafe(org.owner, config))) {
|
||||
state = "proposing";
|
||||
await org.setOwnerMultisig(newOwner, config);
|
||||
state = "proposed";
|
||||
} else {
|
||||
state = "signing";
|
||||
const tx = await org.setOwner(newOwner, config);
|
||||
state = "pending";
|
||||
await tx.wait();
|
||||
state = "success";
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
errorMessage = error.message;
|
||||
} else {
|
||||
errorMessage = "Unknown error.";
|
||||
}
|
||||
console.error(error);
|
||||
state = "failed";
|
||||
}
|
||||
};
|
||||
|
||||
function validate(address: string) {
|
||||
if (address === "") {
|
||||
return { valid: false };
|
||||
}
|
||||
|
||||
if (state !== "idle") {
|
||||
return { valid: false };
|
||||
}
|
||||
|
||||
if (!isAddress(address)) {
|
||||
return {
|
||||
valid: false,
|
||||
validationMessage: "Please enter a valid Ethereum address.",
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
$: ({ valid, validationMessage } = validate(newOwner));
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.actions {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
.message {
|
||||
padding-left: 1rem;
|
||||
padding-top: 1rem;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
|
||||
{#if state === "success" && newOwner}
|
||||
<Modal floating small>
|
||||
<div slot="title">✅</div>
|
||||
|
||||
<div slot="subtitle">
|
||||
The ownership of <span class="txt-bold">
|
||||
{formatAddress(org.address)}
|
||||
</span>
|
||||
was successfully transfered to
|
||||
<span class="txt-bold">{newOwner}</span>
|
||||
.
|
||||
</div>
|
||||
|
||||
<div slot="actions">
|
||||
<Button variant="secondary" on:click={() => dispatch("close")}>
|
||||
Done
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
{:else if state === "proposed" && org}
|
||||
<Modal floating>
|
||||
<div slot="title">🪴</div>
|
||||
|
||||
<div slot="subtitle">
|
||||
<p>
|
||||
The transaction to set the owner of <span class="txt-bold">
|
||||
{formatAddress(org.address)}
|
||||
</span>
|
||||
to
|
||||
<span class="txt-bold">{newOwner}</span>
|
||||
was proposed to:
|
||||
</p>
|
||||
<p><Address address={org.owner} {config} compact /></p>
|
||||
</div>
|
||||
|
||||
<div slot="actions">
|
||||
<Button variant="secondary" on:click={() => dispatch("close")}>
|
||||
Done
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
{:else if state === "failed"}
|
||||
<Modal floating error small>
|
||||
<div slot="title">
|
||||
🔑
|
||||
<div>Transfer ownership</div>
|
||||
</div>
|
||||
|
||||
<div slot="subtitle">
|
||||
<div class="message">
|
||||
{errorMessage}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div slot="actions" class="actions">
|
||||
<Button
|
||||
variant="negative"
|
||||
on:click={() => {
|
||||
state = "idle";
|
||||
}}>
|
||||
Back
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
{:else}
|
||||
<Modal floating>
|
||||
<div slot="title">
|
||||
🔑
|
||||
<div>Transfer ownership</div>
|
||||
</div>
|
||||
|
||||
<div slot="subtitle">
|
||||
{#if state === "signing"}
|
||||
Please confirm the transaction in your wallet.
|
||||
{:else if state === "pending"}
|
||||
Waiting for transaction to be processed…
|
||||
{:else if state === "proposing" && org}
|
||||
Proposal is being submitted to the safe
|
||||
<span class="txt-bold">{formatAddress(org.owner)}</span>
|
||||
, please sign the transaction in your wallet.
|
||||
{:else if state === "idle"}
|
||||
Transfer the ownership of Org <span class="txt-bold">
|
||||
{formatAddress(org.address)}
|
||||
</span>
|
||||
to a new address.
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div slot="body" style="display: flex;justify-content: center;">
|
||||
{#if state === "idle"}
|
||||
<div style="position: absolute; text-align: left;">
|
||||
<div style="width: 31rem;">
|
||||
<TextInput
|
||||
autofocus
|
||||
{valid}
|
||||
{validationMessage}
|
||||
on:submit={onSubmit}
|
||||
disabled={state !== "idle"}
|
||||
bind:value={newOwner} />
|
||||
</div>
|
||||
</div>
|
||||
{:else if state === "pending" || state === "proposing" || state === "signing"}
|
||||
<Loading small center />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div slot="actions" class="actions">
|
||||
{#if state === "signing"}
|
||||
<Button variant="text" on:click={() => dispatch("close")}>
|
||||
Cancel
|
||||
</Button>
|
||||
{:else if state === "pending"}
|
||||
<Button variant="text" on:click={() => dispatch("close")}>Close</Button>
|
||||
{:else}
|
||||
<Button variant="primary" on:click={onSubmit} disabled={!valid}>
|
||||
Submit
|
||||
</Button>
|
||||
|
||||
<Button variant="text" on:click={() => dispatch("close")}>
|
||||
Cancel
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</Modal>
|
||||
{/if}
|
||||
+1
-32
@@ -7,21 +7,6 @@
|
||||
"radToken": {
|
||||
"address": "0x31c8EAcBFFdD875c74b94b077895Bd78CF1E64A3"
|
||||
},
|
||||
"orgFactory": {
|
||||
"address": "0xa15bEb4876F20018b6b4A4116B7560c5fcC9336e"
|
||||
},
|
||||
"orgs": {
|
||||
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74",
|
||||
"pinned": [
|
||||
"alt-clients.radicle.eth",
|
||||
"community.radicle.eth",
|
||||
"upstream.radicle.eth",
|
||||
"gnosisguild.radicle.eth",
|
||||
"grants.radicle.eth",
|
||||
"gip-editors.radicle.eth",
|
||||
"dxdao.radicle.eth"
|
||||
]
|
||||
},
|
||||
"users": {
|
||||
"pinned": ["cloudhead.radicle.eth"]
|
||||
},
|
||||
@@ -44,13 +29,6 @@
|
||||
"address": "0x7b6CbebC5646D996d258dcD4ca1d334B282e9948",
|
||||
"faucet": "0x9Aa75397eD632A3060aCb5dE7f96e2457bceED8d"
|
||||
},
|
||||
"orgFactory": {
|
||||
"address": "0xF3D04e874D07d680e8b26332eEae5b9B1c263121"
|
||||
},
|
||||
"orgs": {
|
||||
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74",
|
||||
"pinned": []
|
||||
},
|
||||
"users": {
|
||||
"pinned": []
|
||||
},
|
||||
@@ -177,17 +155,8 @@
|
||||
"function setAddr(bytes32 node, address addr)",
|
||||
"function setText(bytes32 node, string calldata key, string calldata value)"
|
||||
],
|
||||
"orgFactory": [
|
||||
"function createOrg(address) returns (address)",
|
||||
"function createOrg(address[], uint256) returns (address)",
|
||||
"event OrgCreated(address, address)"
|
||||
],
|
||||
"reverseRegistrar": ["function setName(string) returns (bytes32)"],
|
||||
"org": [
|
||||
"function owner() view returns (address)",
|
||||
"function setOwner(address)",
|
||||
"function setName(string, address) returns (bytes32)"
|
||||
],
|
||||
"org": ["function owner() view returns (address)"],
|
||||
"vesting": [
|
||||
"function token() view returns (address)",
|
||||
"function totalVestingAmount() view returns (uint256)",
|
||||
|
||||
@@ -2,7 +2,6 @@ import { get, writable } from "svelte/store";
|
||||
import type { Writable } from "svelte/store";
|
||||
import { ethers } from "ethers";
|
||||
import type { TypedDataSigner } from "@ethersproject/abstract-signer";
|
||||
import SafeServiceClient from "@gnosis.pm/safe-service-client";
|
||||
import WalletConnect from "@walletconnect/client";
|
||||
import config from "@app/config.json";
|
||||
import { WalletConnectSigner } from "./WalletConnectSigner";
|
||||
@@ -16,11 +15,6 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gas limits for various transactions.
|
||||
const gasLimits = {
|
||||
createOrg: 1_200_000,
|
||||
};
|
||||
|
||||
export type WalletConnectState =
|
||||
| { state: "close" }
|
||||
| { state: "open"; uri: string; onClose: any };
|
||||
@@ -29,13 +23,10 @@ export class Config {
|
||||
network: { name: string; chainId: number };
|
||||
registrar: { address: string; domain: string };
|
||||
radToken: { address: string; faucet: string };
|
||||
orgFactory: { address: string };
|
||||
reverseRegistrar: { address: string };
|
||||
orgs: { contractHash: string; pinned: string[] };
|
||||
users: { pinned: string[] };
|
||||
projects: { pinned: { urn: string; name: string; seed: string }[] };
|
||||
seeds: { pinned: Record<string, { emoji: string }> };
|
||||
gasLimits: { createOrg: number };
|
||||
provider: ethers.providers.JsonRpcProvider;
|
||||
signer: (ethers.Signer & TypedDataSigner) | WalletConnectSigner | null;
|
||||
walletConnect: {
|
||||
@@ -56,7 +47,6 @@ export class Config {
|
||||
};
|
||||
safe: {
|
||||
api?: string;
|
||||
client?: SafeServiceClient;
|
||||
viewer: string | null;
|
||||
};
|
||||
abi: { [contract: string]: string[] };
|
||||
@@ -105,17 +95,11 @@ export class Config {
|
||||
this.seed = config.radicle.seed;
|
||||
this.registrar = cfg.registrar;
|
||||
this.radToken = cfg.radToken;
|
||||
this.orgFactory = cfg.orgFactory;
|
||||
this.reverseRegistrar = cfg.reverseRegistrar;
|
||||
this.orgs = cfg.orgs;
|
||||
this.users = cfg.users;
|
||||
this.safe = cfg.safe;
|
||||
this.safe.client = this.safe.api
|
||||
? new SafeServiceClient(this.safe.api)
|
||||
: undefined;
|
||||
this.provider = provider;
|
||||
this.signer = null;
|
||||
this.gasLimits = gasLimits;
|
||||
this.projects = config.projects;
|
||||
this.seeds = config.seeds;
|
||||
this.abi = config.abi;
|
||||
|
||||
+7
-51
@@ -4,37 +4,25 @@
|
||||
import Modal from "@app/Modal.svelte";
|
||||
import type { Config } from "@app/config";
|
||||
import { formatAddress, isAddressEqual } from "@app/utils";
|
||||
import { Org } from "@app/base/orgs/Org";
|
||||
import type { User } from "@app/base/users/User";
|
||||
import ErrorModal from "@app/ErrorModal.svelte";
|
||||
import Address from "@app/Address.svelte";
|
||||
import * as utils from "@app/utils";
|
||||
import Button from "@app/Button.svelte";
|
||||
import TextInput from "@app/TextInput.svelte";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let entity: Org | User;
|
||||
export let entity: User;
|
||||
export let config: Config;
|
||||
|
||||
const org = Org.hasOwnProperty.call(entity, "owner") ? (entity as Org) : null;
|
||||
|
||||
const label = org ? "org" : "profile";
|
||||
|
||||
enum State {
|
||||
Idle,
|
||||
Checking,
|
||||
|
||||
// Single-sig states.
|
||||
Signing,
|
||||
Pending,
|
||||
Success,
|
||||
|
||||
// Multi-sig states.
|
||||
Proposing,
|
||||
Proposed,
|
||||
|
||||
Failed,
|
||||
Mismatch,
|
||||
}
|
||||
@@ -54,17 +42,11 @@
|
||||
|
||||
if (resolved && isAddressEqual(resolved, entity.address)) {
|
||||
try {
|
||||
if (org && (await utils.isSafe(org.owner, config))) {
|
||||
state = State.Proposing;
|
||||
await org.setNameMultisig(domain, config);
|
||||
state = State.Proposed;
|
||||
} else {
|
||||
state = State.Signing;
|
||||
const tx = await entity.setName(domain, config);
|
||||
state = State.Pending;
|
||||
await tx.wait();
|
||||
state = State.Success;
|
||||
}
|
||||
state = State.Signing;
|
||||
const tx = await entity.setName(domain, config);
|
||||
state = State.Pending;
|
||||
await tx.wait();
|
||||
state = State.Success;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
state = State.Failed;
|
||||
@@ -100,28 +82,6 @@
|
||||
.
|
||||
</div>
|
||||
|
||||
<div slot="actions">
|
||||
<Button variant="secondary" on:click={() => dispatch("close")}>
|
||||
Done
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
{:else if state === State.Proposed && org}
|
||||
<Modal floating>
|
||||
<div slot="title">🪴</div>
|
||||
|
||||
<div slot="subtitle">
|
||||
<p>
|
||||
The transaction to set the ENS name for <span class="txt-bold">
|
||||
{formatAddress(entity.address)}
|
||||
</span>
|
||||
to
|
||||
<span class="txt-bold">{name}.{config.registrar.domain}</span>
|
||||
was proposed to:
|
||||
</p>
|
||||
<p><Address address={org.owner} {config} compact /></p>
|
||||
</div>
|
||||
|
||||
<div slot="actions">
|
||||
<Button variant="secondary" on:click={() => dispatch("close")}>
|
||||
Done
|
||||
@@ -161,16 +121,12 @@
|
||||
Please confirm the transaction in your wallet.
|
||||
{:else if state === State.Pending}
|
||||
Waiting for transaction to be processed…
|
||||
{:else if state === State.Proposing && org}
|
||||
Proposal is being submitted
|
||||
<span class="txt-bold">{formatAddress(org.owner)}</span>
|
||||
, please sign the transaction in your wallet.
|
||||
{:else}
|
||||
Set an ENS name for <span class="txt-bold">
|
||||
{formatAddress(entity.address)}
|
||||
</span>
|
||||
to associate a profile. ENS profiles provide human-identifiable data to your
|
||||
{label}, such as a unique name, avatar and URL, and help make your {label}
|
||||
profile, such as a unique name, avatar and URL, and help make your profile
|
||||
more discoverable.
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// This shim is used as a stand-in for the node "stream" library, used by
|
||||
// the "keccack" package depended on by @gnosis.pm/safe-core-sdk.
|
||||
import * as streams from "@stardazed/streams";
|
||||
|
||||
// "Transform" is the old name for "TransformStream".
|
||||
export const Transform = streams.TransformStream;
|
||||
export default streams;
|
||||
-122
@@ -5,9 +5,6 @@ import { BigNumber } from "ethers";
|
||||
import multibase from "multibase";
|
||||
import katex from "katex";
|
||||
import multihashes from "multihashes";
|
||||
import type { TransactionResult } from "@gnosis.pm/safe-core-sdk";
|
||||
import EthersSafe, { EthersAdapter } from "@gnosis.pm/safe-core-sdk";
|
||||
import type { SafeSignature } from "@gnosis.pm/safe-core-sdk-types";
|
||||
import type { Config } from "@app/config";
|
||||
import config from "@app/config.json";
|
||||
import { assert } from "@app/error";
|
||||
@@ -422,18 +419,10 @@ export async function identifyAddress(
|
||||
address: string,
|
||||
config: Config,
|
||||
): Promise<AddressType> {
|
||||
const safe = await isSafe(address, config);
|
||||
if (safe) {
|
||||
return AddressType.Safe;
|
||||
}
|
||||
|
||||
const code = await getCode(address, config);
|
||||
const bytes = ethers.utils.arrayify(code);
|
||||
|
||||
if (bytes.length > 0) {
|
||||
if (ethers.utils.keccak256(bytes) === config.orgs.contractHash) {
|
||||
return AddressType.Org;
|
||||
}
|
||||
return AddressType.Contract;
|
||||
}
|
||||
return AddressType.EOA;
|
||||
@@ -513,22 +502,6 @@ export async function resolveEnsProfile(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check whether a Gnosis Safe exists at an address.
|
||||
export async function isSafe(
|
||||
_address: string,
|
||||
_config: Config,
|
||||
): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a Gnosis Safe at an address.
|
||||
export async function getSafe(
|
||||
_address: string,
|
||||
_config: Config,
|
||||
): Promise<Safe | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get token balances for an address.
|
||||
export async function getTokens(
|
||||
address: string,
|
||||
@@ -595,101 +568,6 @@ export function gravatarURL(email: string): string {
|
||||
return `https://www.gravatar.com/avatar/${hash}`;
|
||||
}
|
||||
|
||||
// Propose a Gnosis Safe multi-sig transaction.
|
||||
export async function proposeSafeTransaction(
|
||||
safeTx: SafeTransaction,
|
||||
safeAddress: string,
|
||||
config: Config,
|
||||
): Promise<void> {
|
||||
assert(config.signer);
|
||||
assert(config.safe.client);
|
||||
|
||||
const ethAdapter = new EthersAdapter({
|
||||
ethers,
|
||||
signer: config.signer,
|
||||
});
|
||||
const safeSdk = await EthersSafe.create({
|
||||
ethAdapter,
|
||||
safeAddress,
|
||||
});
|
||||
const estimation = await config.safe.client.estimateSafeTransaction(
|
||||
safeAddress,
|
||||
safeTx,
|
||||
);
|
||||
const transaction = await safeSdk.createTransaction({
|
||||
...safeTx,
|
||||
safeTxGas: Number(estimation.safeTxGas),
|
||||
});
|
||||
const safeTxHash = await safeSdk.getTransactionHash(transaction);
|
||||
const signature = await safeSdk.signTransactionHash(safeTxHash);
|
||||
|
||||
await config.safe.client.proposeTransaction(
|
||||
safeAddress,
|
||||
transaction.data,
|
||||
safeTxHash,
|
||||
signature,
|
||||
);
|
||||
}
|
||||
|
||||
// Sign a Gnosis Safe multi-sig transaction.
|
||||
export async function signSafeTransaction(
|
||||
safeAddress: string,
|
||||
safeTxHash: string,
|
||||
config: Config,
|
||||
): Promise<SafeSignature> {
|
||||
assert(config.signer);
|
||||
|
||||
const ethAdapter = new EthersAdapter({
|
||||
ethers,
|
||||
signer: config.signer,
|
||||
});
|
||||
const safeSdk = await EthersSafe.create({
|
||||
ethAdapter,
|
||||
safeAddress,
|
||||
});
|
||||
return await safeSdk.signTransactionHash(safeTxHash);
|
||||
}
|
||||
|
||||
// Execute a Gnosis Safe signed transaction by safeTxHash.
|
||||
export async function executeSignedSafeTransaction(
|
||||
safeAddress: string,
|
||||
safeTxHash: string,
|
||||
config: Config,
|
||||
): Promise<TransactionResult> {
|
||||
assert(config.signer);
|
||||
assert(config.safe.client);
|
||||
|
||||
const ethAdapter = new EthersAdapter({
|
||||
ethers,
|
||||
signer: config.signer,
|
||||
});
|
||||
const safeSdk = await EthersSafe.create({
|
||||
ethAdapter,
|
||||
safeAddress,
|
||||
});
|
||||
|
||||
const signedTx = await config.safe.client.getTransaction(safeTxHash);
|
||||
|
||||
assert(signedTx.data);
|
||||
assert(signedTx.confirmations);
|
||||
|
||||
const safeTx = await safeSdk.createTransaction({
|
||||
...signedTx,
|
||||
gasPrice: Number(signedTx.gasPrice),
|
||||
data: signedTx.data,
|
||||
});
|
||||
|
||||
signedTx.confirmations.forEach(confirmation => {
|
||||
const signature = new EthSignSignature(
|
||||
confirmation.owner,
|
||||
confirmation.signature,
|
||||
);
|
||||
safeTx.addSignature(signature);
|
||||
});
|
||||
|
||||
return await safeSdk.executeTransaction(safeTx);
|
||||
}
|
||||
|
||||
export class EthSignSignature {
|
||||
signer: string;
|
||||
data: string;
|
||||
|
||||
Reference in New Issue
Block a user