diff --git a/src/config.json b/src/config.json
index e6857c2b8..20b4b4501 100644
--- a/src/config.json
+++ b/src/config.json
@@ -15,7 +15,7 @@
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74"
},
"safe": {
- "api": "https://safe-transaction.gnosis.io/api/v1",
+ "api": "https://safe-transaction.gnosis.io",
"subgraph": null,
"viewer": "https://gnosis-safe.io/app/#/safes"
},
@@ -59,7 +59,7 @@
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74"
},
"safe": {
- "api": "https://safe-transaction.rinkeby.gnosis.io/api/v1",
+ "api": "https://safe-transaction.rinkeby.gnosis.io",
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/gnosis-safe-rinkeby",
"viewer": "https://rinkeby.gnosis-safe.io/app/#/safes"
},
diff --git a/src/config.ts b/src/config.ts
index d2a1ebf18..522e64176 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1,5 +1,6 @@
import { ethers } from "ethers";
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
+import SafeServiceClient from "@gnosis.pm/safe-service-client";
import config from "@app/config.json";
declare global {
@@ -7,7 +8,6 @@ declare global {
ethereum: any;
registrarState: any;
}
-
}
export class Config {
@@ -19,7 +19,12 @@ export class Config {
gasLimits: { createOrg: number };
provider: ethers.providers.JsonRpcProvider;
signer: ethers.Signer & TypedDataSigner | null;
- safe: { api: string | null; subgraph: string; viewer: string | null };
+ safe: {
+ api?: string;
+ client?: SafeServiceClient;
+ subgraph: string;
+ viewer: string | null;
+ };
abi: { [contract: string]: string[] };
seed: { api?: string };
tokens: string[];
@@ -44,6 +49,9 @@ export class Config {
this.orgFactory = cfg.orgFactory;
this.orgs = cfg.orgs;
this.safe = cfg.safe;
+ this.safe.client = this.safe.api
+ ? new SafeServiceClient(this.safe.api)
+ : undefined;
this.provider = provider;
this.signer = signer;
this.gasLimits = gasLimits;
diff --git a/src/ens/SetName.svelte b/src/ens/SetName.svelte
index 1c93a62f6..fb470b7a4 100644
--- a/src/ens/SetName.svelte
+++ b/src/ens/SetName.svelte
@@ -7,6 +7,8 @@
import type { Org } from '@app/base/orgs/Org';
import Loading from '@app/Loading.svelte';
import Error from '@app/Error.svelte';
+ import Address from '@app/Address.svelte';
+ import * as utils from '@app/utils';
const dispatch = createEventDispatcher();
@@ -16,16 +18,23 @@
enum State {
Idle,
Checking,
+
+ // Single-sig states.
Signing,
Pending,
Success,
+
+ // Multi-sig states.
+ Proposing,
+ Proposed,
+
Failed,
+ Mismatch,
}
let name = "";
let state = State.Idle;
let error: string | null = null;
- let mismatchError = false; // Set if the name entered does not resolve to the address.
const onSubmit = async () => {
state = State.Checking;
@@ -34,20 +43,25 @@
let resolved = await config.provider.resolveName(domain);
if (resolved && isAddressEqual(resolved, org.address)) {
- state = State.Signing;
try {
- let tx = await org.setName(domain, config);
- state = State.Pending;
- await tx.wait();
- state = State.Success;
+ if (utils.isSafe(org.owner, config)) {
+ state = State.Proposing;
+ await org.setNameMultisig(domain, config);
+ state = State.Proposed;
+ } else {
+ state = State.Signing;
+ let tx = await org.setName(domain, config);
+ state = State.Pending;
+ await tx.wait();
+ state = State.Success;
+ }
} catch (e) {
console.error(e);
state = State.Failed;
error = e.message;
}
} else {
- state = State.Idle;
- mismatchError = true;
+ state = State.Mismatch;
}
};
@@ -69,31 +83,31 @@
-{:else if mismatchError}
-
+{:else if state === State.Proposed}
+
- 👻
+ 🪴
-
-
- The name {name}.{config.registrar.domain} does not
- resolve to {formatAddress(org.address)}. Please update
- The ENS record for {name}.{config.registrar.domain} to
- point to the correct address and try again.
-
+
+
The transaction to set the ENS name for {formatAddress(org.address)}
+ to {name}.{config.registrar.domain} was proposed to:
+
-
-
-
+{:else if state === State.Mismatch}
+
+ The name {name}.{config.registrar.domain} does not
+ resolve to {formatAddress(org.address)}. Please update
+ The ENS record for {name}.{config.registrar.domain} to
+ point to the correct address and try again.
+
{:else if state === State.Failed && error}
{:else}
@@ -107,6 +121,10 @@
Please confirm the transaction in your wallet.
{:else if state == State.Pending}
Transaction is being processed by the network...
+ {:else if state == State.Proposing}
+ Proposal is being submitted to the safe
+ {formatAddress(org.owner)},
+ please sign the transaction in your wallet.
{:else}
Set an ENS name for {formatAddress(org.address)}
{/if}
@@ -114,7 +132,7 @@
{#if state === State.Idle || state === State.Checking}
- mismatchError = false}
+
{:else}
diff --git a/src/polyfills/stream.ts b/src/polyfills/stream.ts
new file mode 100644
index 000000000..a7260ffd0
--- /dev/null
+++ b/src/polyfills/stream.ts
@@ -0,0 +1,7 @@
+// 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;
diff --git a/src/utils.ts b/src/utils.ts
index a77ff8b38..c5ad068c9 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -2,7 +2,9 @@ import { ethers } from "ethers";
import type { BigNumber } from "ethers";
import multibase from 'multibase';
import multihashes from 'multihashes';
+import EthersSafe from "@gnosis.pm/safe-core-sdk";
import type { Config } from '@app/config';
+import { assert } from '@app/error';
export enum AddressType {
Contract,
@@ -17,6 +19,13 @@ export interface Safe {
threshold: number;
}
+export interface SafeTransaction {
+ to: string;
+ value: string;
+ data: string;
+ operation: number;
+}
+
export function isAddressEqual(left: string, right: string): boolean {
return left.toLowerCase() === right.toLowerCase();
}
@@ -178,7 +187,7 @@ export async function isSafe(address: string, config: Config): Promise
if (! config.safe.api) return false;
const addr = ethers.utils.getAddress(address);
- const response = await fetch(`${config.safe.api}/safes/${addr}`, { method: 'HEAD' });
+ const response = await fetch(`${config.safe.api}/api/v1/safes/${addr}`, { method: 'HEAD' });
return response.ok;
}
@@ -188,7 +197,7 @@ export async function getSafe(address: string, config: Config): Promise {
+ assert(config.signer);
+ assert(config.safe.client);
+
+ const safeSdk = await EthersSafe.create({
+ ethers, safeAddress, providerOrSigner: config.signer,
+ });
+ 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
+ );
+}
diff --git a/vite.config.ts b/vite.config.ts
index f32399966..861c92049 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -11,6 +11,8 @@ const config: UserConfig = {
resolve: {
alias: {
"@app": path.resolve("./src"),
+ // Polyfill for Node.js "stream" library.
+ "stream": path.resolve("./src/polyfills/stream.ts"),
},
},
build: {