Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
WHIP multisig anchoring
Browse files Browse the repository at this point in the history
Signed-off-by: Rūdolfs Ošiņš <[email protected]>
  • Loading branch information
rudolfs committed May 25, 2021
1 parent 81121ef commit e02eedc
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"@apollo/client": "^3.3.15",
"@ethersproject/bytes": "^5.1.0",
"@ethersproject/properties": "^5.1.0",
"@gnosis.pm/safe-core-sdk": "^0.1.2",
"@types/big.js": "^6.0.2",
"@types/qs": "^6.9.6",
"@types/uuid": "^8.3.0",
Expand Down
6 changes: 5 additions & 1 deletion ui/Modal/Org/AnchorProject.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="typescript">
import * as modal from "ui/src/modal";
import * as org from "ui/src/org";
import { Button, Emoji } from "ui/DesignSystem/Primitive";
import { Dropdown, Modal } from "ui/DesignSystem/Component";
Expand Down Expand Up @@ -52,6 +53,9 @@
}} />
<div class="actions">
<Button variant="transparent" on:click={() => modal.hide()}>Cancel</Button>
<Button on:click={() => {}}>Confirm in your wallet</Button>
<Button
on:click={() => {
org.anchorProject();
}}>Confirm in your wallet</Button>
</div>
</Modal>
73 changes: 69 additions & 4 deletions ui/src/org.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as svelteStore from "svelte/store";
import * as ethers from "ethers";
import EthersSafe, {
SafeTransactionDataPartial,
} from "@gnosis.pm/safe-core-sdk";
import { push } from "svelte-spa-router";

import * as notification from "./notification";
import * as path from "./path";
import * as wallet from "./wallet";
import * as theGraphApi from "./theGraphApi";
import * as ethereum from "ui/src/ethereum";
import * as urn from "ui/src/urn";

import type {
TransactionReceipt,
Expand All @@ -20,22 +24,83 @@ const orgFactoryAbi = [
"event OrgCreated(address, address)",
];

const orgAbi = ["function owner() view returns (address)"];
const orgAbi = [
"function owner() view returns (address)",
"function anchor(bytes32, bytes32, uint8, uint8)",
];

const orgFactoryAddress = (network: ethereum.Environment) => {
switch (network) {
case ethereum.Environment.Local:
throw new Error("Not implemented");
break;
case ethereum.Environment.Ropsten:
return "0x2007bcEf1247CD03Bb4262eF420D6487368f473B";
break;
case ethereum.Environment.Rinkeby:
return "0xe30aA5594FFB52B6bF5bbB21eB7e71Ac525bB028";
break;
}
};

export const anchorProject = async (): Promise<void> => {
const orgAddress = "0x01acd1dded15eadf7ed8de1885a9541c5481eb60";
const gnosisSafeAddress = "0xb173a59b8f315a4bd36e218207b71dc9d5f79d8b";
const projectUrn = "rad:git:hnrke3q1pob41qjq5y57xn698xzt86yht74by";
const commitHash = "900b6cf6cf1ff822a423bb47cecb9eb80738bff4";

const walletStore = svelteStore.get(wallet.store);
const safeSdk = await EthersSafe.create(
ethers,
gnosisSafeAddress,
walletStore.signer
);

console.log(safeSdk);

const decodedProjectUrn = urn.parseIdentitySha1(projectUrn);
const decodedCommitHash = new Uint8Array(
commitHash.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
);
const paddedProjectUrn = ethers.utils.zeroPad(decodedProjectUrn, 32);
const paddedCommitHash = ethers.utils.zeroPad(decodedCommitHash, 32);

console.log(paddedProjectUrn);
console.log(paddedCommitHash);

const orgContract = new ethers.Contract(orgAddress, orgAbi);

console.log("AAAAAAAAAA: ", orgContract);
const orgContractInstance = await orgContract.populateTransaction.anchor(
paddedProjectUrn,
paddedCommitHash,
ethers.constants.Zero,
ethers.constants.Zero
);

console.log(orgContractInstance);

const txData = orgContractInstance.data;
if (!txData) {
throw new Error("Could not generate transaction");
}
console.log("BBBBBBBB: ", txData);

const partialTx: SafeTransactionDataPartial = {
to: orgAddress,
data: txData,
value: "0",
};

// THIS WORKS IF THERE'S ONLY ONE OWNER IN THE SAFE
// console.log("PARTIAL: ", partialTx);
// const safeTransaction = await safeSdk.createTransaction(partialTx);
// const approveTxResponse = await safeSdk.executeTransaction(safeTransaction);
// console.log(approveTxResponse);

const safeTransaction = await safeSdk.createTransaction(partialTx);
const txHash = await safeSdk.getTransactionHash(safeTransaction);
const approveTxResponse = await safeSdk.approveTransactionHash(txHash);
await approveTxResponse.wait();
};

export const createOrg = async (owner: string): Promise<void> => {
const walletStore = svelteStore.get(wallet.store);
const orgFactory = new ethers.Contract(
Expand Down
42 changes: 41 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,15 @@ __metadata:
languageName: node
linkType: hard

"@gnosis.pm/safe-core-sdk@npm:^0.1.2":
version: 0.1.2
resolution: "@gnosis.pm/safe-core-sdk@npm:0.1.2"
dependencies:
ethereumjs-util: ^7.0.10
checksum: 7ce0553120a2489c5c10985d3a263ad86ed427404b26ffdd3ff793ce6e968d5feca8bd4cd6c8a3b86d447f4207c80e1e6538e677afc288e50d47051efc7101f3
languageName: node
linkType: hard

"@graphql-typed-document-node/core@npm:^3.0.0":
version: 3.1.0
resolution: "@graphql-typed-document-node/core@npm:3.1.0"
Expand Down Expand Up @@ -1476,6 +1485,15 @@ __metadata:
languageName: node
linkType: hard

"@types/bn.js@npm:^5.1.0":
version: 5.1.0
resolution: "@types/bn.js@npm:5.1.0"
dependencies:
"@types/node": "*"
checksum: e33009f99b19bfbef4591704c2deb18f3c55dc433435091895d462846b97bc22ec0440ff0a05439bc7e3a25b07f8bfd2c43215ee50523e4238a9e2865f98578e
languageName: node
linkType: hard

"@types/conventional-changelog-config-spec@npm:*":
version: 2.1.0
resolution: "@types/conventional-changelog-config-spec@npm:2.1.0"
Expand Down Expand Up @@ -3032,6 +3050,13 @@ __metadata:
languageName: node
linkType: hard

"bn.js@npm:^5.1.2":
version: 5.2.0
resolution: "bn.js@npm:5.2.0"
checksum: 7a73bdbba63013a7f9953fbbd6ea3351e4cf36d6fdbb5adf7969fcd65255b9c04f2994b0132d89d74ffe608a0eb5a48322526bee20c0e03e71e502603b420f63
languageName: node
linkType: hard

"boolbase@npm:^1.0.0, boolbase@npm:~1.0.0":
version: 1.0.0
resolution: "boolbase@npm:1.0.0"
Expand Down Expand Up @@ -5607,6 +5632,20 @@ __metadata:
languageName: node
linkType: hard

"ethereumjs-util@npm:^7.0.10":
version: 7.0.10
resolution: "ethereumjs-util@npm:7.0.10"
dependencies:
"@types/bn.js": ^5.1.0
bn.js: ^5.1.2
create-hash: ^1.1.2
ethereum-cryptography: ^0.1.3
ethjs-util: 0.1.6
rlp: ^2.2.4
checksum: 4dd40fd92063179af80be2384c0faa39b93d9583bbaf0ab2f418aefce721c6311b420ca91bc03057568a360b01c304328439f418cc152df32f1a25f7da0ad1d0
languageName: node
linkType: hard

"ethers@npm:^5.1.0, ethers@npm:^5.1.4":
version: 5.1.4
resolution: "ethers@npm:5.1.4"
Expand Down Expand Up @@ -10614,6 +10653,7 @@ __metadata:
"@ethersproject/bytes": ^5.1.0
"@ethersproject/cli": ^5.1.0
"@ethersproject/properties": ^5.1.0
"@gnosis.pm/safe-core-sdk": ^0.1.2
"@tsconfig/svelte": ^1.0.10
"@types/big.js": ^6.0.2
"@types/jest": ^26.0.23
Expand Down Expand Up @@ -11219,7 +11259,7 @@ __metadata:
languageName: node
linkType: hard

"rlp@npm:^2.2.3":
"rlp@npm:^2.2.3, rlp@npm:^2.2.4":
version: 2.2.6
resolution: "rlp@npm:2.2.6"
dependencies:
Expand Down

0 comments on commit e02eedc

Please sign in to comment.