-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ππ β£ Adding Supabase components & working DAO scripts to #18
- Loading branch information
1 parent
d14fbf2
commit 2ba259c
Showing
18 changed files
with
1,038 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.