Skip to content

Commit

Permalink
πŸ›‘πŸ„ ↣ Adding Supabase components & working DAO scripts to #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Nov 24, 2022
1 parent d14fbf2 commit 2ba259c
Show file tree
Hide file tree
Showing 18 changed files with 1,038 additions and 63 deletions.
Binary file modified .DS_Store
Binary file not shown.
33 changes: 33 additions & 0 deletions Scripts/10-create-vote-proposals.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sdk from "./1-initialize-sdk.mjs";
import { ethers } from "ethers";

(async () => {
try {
const vote = await sdk.getContract("0x267239EA5C955D2681652a2B9c6AAbD6f8207Cc9", 'vote');
const token = await sdk.getContract('0x6e4A2c27a080ae51C825e7b08D753D8851F9a455', 'token');
const amount = 420_000;
const description = "Should we call the rover eye the Photoreceptor, like from Star Wars, in the production DAO?";
const executions = [
{
toAddress: token.getAddress(),
nativeTokenValue: 0,
transactionData: token.encoder.encode(
"mintTo", [
vote.getAddress(),
ethers.utils.parseUnits(amount.toString(), 18),
]
),
}
];
await vote.propose(description, executions);
console.log("βœ… Successfully created proposal to mint tokens");
} catch (error) {
console.error("Failed to create proposal. ", error);
process.exit(1);
}
})();

/* Output:
πŸ‘‹ -> SDK Initialised by address: 0x15A4C3b42f3386Cd1A642908525469684Cac7C6d
βœ… Successfully created proposal to mint tokens
*/
20 changes: 20 additions & 0 deletions Scripts/5-deploy-token.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AddressZero } from "@ethersproject/constants";
import sdk from './1-initialize-sdk.mjs';

(async () => {
try {
const tokenAddress = await sdk.deployer.deployToken({
name: "Star Sailors Governance Token",
symbol: "SAILOR",
primary_sale_recipient: AddressZero,
});
console.log("βœ… Successfully deployed token contract. Address: ", tokenAddress,);
} catch (error) {
console.error("Failed to deploy token contract. Error: ", error);
}
})();

/* Output
πŸ‘‹ -> SDK Initialised by address: 0x15A4C3b42f3386Cd1A642908525469684Cac7C6d
βœ… Successfully deployed token contract. Address: 0x6e4A2c27a080ae51C825e7b08D753D8851F9a455
*/
13 changes: 13 additions & 0 deletions Scripts/6-print-tokens.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sdk from "./1-initialize-sdk.mjs";

(async () => {
try {
const token = await sdk.getContract("0x6e4A2c27a080ae51C825e7b08D753D8851F9a455", 'token');
const amount = 1_000_000;
await token.mint(amount);
const totalSupply = await token.totalSupply();
console.log("βœ… There now are ", totalSupply.displayValue, " $SAILORS in circulation");
} catch (error) {
console.error("Failed to print tokens, ", error);
}
})();
42 changes: 42 additions & 0 deletions Scripts/7-airdrop-token.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sdk from "./1-initialize-sdk.mjs";

(async () => {
try {
// This is the address to our ERC-1155 membership NFT contract.
const editionDrop = await sdk.getContract("0x93FC4ba29c41c059fB9f4727F3903df776771Af8", "edition-drop");
// This is the address to our ERC-20 token contract.
const token = await sdk.getContract("0x6e4A2c27a080ae51C825e7b08D753D8851F9a455", "token");
// Grab all the addresses of people who own our membership NFT, which has
// a tokenId of 0.
const walletAddresses = await editionDrop.history.getAllClaimerAddresses(0);

if (walletAddresses.length === 0) {
console.log(
"No NFTs have been claimed yet, maybe get some friends to claim your free NFTs!",
);
process.exit(0);
}

// Loop through the array of addresses.
const airdropTargets = walletAddresses.map((address) => {
// Pick a random # between 1000 and 10000.
const randomAmount = Math.floor(Math.random() * (10000 - 1000 + 1) + 1000);
console.log("βœ… Going to airdrop", randomAmount, "tokens to", address);

// Set up the target.
const airdropTarget = {
toAddress: address,
amount: randomAmount,
};

return airdropTarget;
});

// Call transferBatch on all our airdrop targets.
console.log("🌈 Starting airdrop...");
await token.transferBatch(airdropTargets);
console.log("βœ… Successfully airdropped tokens to all the holders of the NFT!");
} catch (err) {
console.error("Failed to airdrop tokens", err);
}
})();
23 changes: 23 additions & 0 deletions Scripts/8-deploy-vote.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sdk from './1-initialize-sdk.mjs';

(async () => {
try {
const voteContractAddress = await sdk.deployer.deployVote({
name: "Star Sailors DAO",
voting_token_address: "0x6e4A2c27a080ae51C825e7b08D753D8851F9a455",
voting_delay_in_blocks: 0,
voting_period_in_blocks: 6570,
voting_quorum_fraction: 0,
proposal_token_threshold: 0,
});

console.log("βœ… Successfully deployed vote contract, address: ", voteContractAddress,);
} catch (err) {
console.error("Failed to deploy vote contract, ", err);
}
})();

/* Output:
πŸ‘‹ -> SDK Initialised by address: 0x15A4C3b42f3386Cd1A642908525469684Cac7C6d
βœ… Successfully deployed vote contract, address: 0x267239EA5C955D2681652a2B9c6AAbD6f8207Cc9
*/
40 changes: 40 additions & 0 deletions Scripts/9-setup-vote.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sdk from "./1-initialize-sdk.mjs";

(async () => {
try {
const vote = await sdk.getContract("0x267239EA5C955D2681652a2B9c6AAbD6f8207Cc9", 'vote');
const token = await sdk.getContract("0x6e4A2c27a080ae51C825e7b08D753D8851F9a455", 'token');
await token.roles.grant("minter", vote.getAddress()); // Treasury has power to mint additional tokens if needed
console.log(
"Successfully gave vote contract permissions to act on token contract"
);
} catch (error) {
console.error(
"failed to grant vote contract permissions on token contract",
error
);
process.exit(1);
}

try {
const vote = await sdk.getContract("0x267239EA5C955D2681652a2B9c6AAbD6f8207Cc9", "vote");
const token = await sdk.getContract("0x6e4A2c27a080ae51C825e7b08D753D8851F9a455", 'token');
const ownedTokenBalance = await token.balanceOf(process.env.WALLET_ADDRESS);
const ownedAmount = ownedTokenBalance.displayValue;
const percent90 = Number(ownedAmount) / 100 * 90;

await token.transfer(
vote.getAddress(),
percent90
);
console.log("βœ… Successfully transferred " + percent90 + " tokens to vote contract");
} catch (err) {
console.error("failed to transfer tokens to vote contract", err);
}
})();

/* Output:
πŸ‘‹ -> SDK Initialised by address: 0x15A4C3b42f3386Cd1A642908525469684Cac7C6d
Successfully gave vote contract permissions to act on token contract
βœ… Successfully transferred 1800000 tokens to vote contract
*/
65 changes: 65 additions & 0 deletions components/Auth/Account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useState, useEffect } from 'react';
import { supabase } from '../../pages/supabaseClient';
//import Avatar from './Avatar';

const Account = ({ session }) => {
const [loading, setLoading] = useState(true);
const [username, setUsername] = useState(null);
const [website, setWebsite] = useState(null);
const [avatar_url, setAvatarUrl] = useState(null);

useEffect(() => {
getProfile()
}, [session]);

const getProfile = async () => {
try {
setLoading(true);
const user = supabase.auth.user();

let { data, error, status } = await supabase
.from('profiles')
.select(`username, website, avatar_url`)
.eq('id', user.id)
.single()
//setUserId(user.id)

if (data) {
setUsername(data.username);
setWebsite(data.website);
setAvatarUrl(data.avatar_url);
}
} catch (error) {
alert(error.message);
} finally {
setLoading(false);
}
}

const updateProfile = async (e) => {
e.preventDefault();

try {
setLoading(true);
const user = supabase.auth.user();
const update = {
id: user.id,
username,
website,
avatar_url,
updated_at: newDate()
}

let { error } = await supabase.from('profiles')
.upsert(updates, { returning : 'minimal' })

if (error) {
throw error;
}
} catch (error) {
alert(error.message);
} finally {
setLoading(false);
}
}
}
Empty file added components/Supabase.js
Empty file.
Loading

0 comments on commit 2ba259c

Please sign in to comment.