Skip to content

Commit 8a477a6

Browse files
authored
Merge branch 'solana-labs:main' into main
2 parents a4688ef + 5dd9af7 commit 8a477a6

File tree

73 files changed

+9920
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+9920
-281
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/node_modules/*
22
**/out/*
33
**/.next/*
4+
**/docs/build/*

.github/workflows/deploy-docs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
push:
3+
branches: [main]
4+
paths: [docs/**]
5+
6+
jobs:
7+
deploy:
8+
name: Deploy Docs to GitHub Pages
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v2
13+
with:
14+
node-version: lts/*
15+
cache: yarn
16+
17+
# temporary hack so that root postcss config doesn't
18+
# interfere with the build process for the docs
19+
- name: Remove root postcss config
20+
run: rm postcss.config.js
21+
22+
- name: Build docs
23+
working-directory: docs
24+
run: |
25+
yarn install --frozen-lockfile
26+
yarn build
27+
28+
- name: Deploy to GitHub Pages
29+
uses: peaceiris/actions-gh-pages@v3
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
# Build output to publish to the `gh-pages` branch:
33+
publish_dir: ./docs/build
34+
# Assign commit authorship to the official GH-Actions bot for deploys to `gh-pages` branch:
35+
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
36+
# The GH actions bot is used by default if you didn't specify the two fields.
37+
# You can swap them out with your own user credentials.
38+
user_name: github-actions[bot]
39+
user_email: 41898282+github-actions[bot]@users.noreply.github.com

actions/createMultisigRealm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const createMultisigRealm = async (
9393
teamWalletPk,
9494
walletPk
9595
)
96+
9697
// Mint 1 council token to each team member
9798
await withMintTo(
9899
councilMembersInstructions,

actions/registerRealm.ts

Lines changed: 137 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,95 @@
1-
import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js'
1+
import {
2+
Connection,
3+
Keypair,
4+
PublicKey,
5+
Transaction,
6+
TransactionInstruction,
7+
} from '@solana/web3.js'
28
import BN from 'bn.js'
39
import { MintMaxVoteWeightSource } from '../models/accounts'
410
import { withCreateRealm } from '../models/withCreateRealm'
511
import { RpcContext } from '../models/core/api'
612
import { sendTransaction } from '../utils/send'
713
import { ProgramVersion } from '@models/registry/constants'
14+
import { sendTransactions, SequenceType } from 'utils/sendTransactions'
15+
import { withCreateMint } from '@tools/sdk/splToken/withCreateMint'
16+
import { withCreateAssociatedTokenAccount } from '@tools/sdk/splToken/withCreateAssociatedTokenAccount'
17+
import { withMintTo } from '@tools/sdk/splToken/withMintTo'
18+
import { chunks } from '@utils/helpers'
19+
import { WalletConnectionError } from '@solana/wallet-adapter-base'
20+
import { withDepositGoverningTokens } from '@models/withDepositGoverningTokens'
21+
22+
/**
23+
* Prepares the council instructions
24+
* @param connection
25+
* @param walletPubkey
26+
* @param councilMint
27+
* @param councilWalletPks
28+
*/
29+
async function prepareCouncilInstructions(
30+
connection: Connection,
31+
walletPubkey: PublicKey,
32+
councilMint?: PublicKey,
33+
councilWalletPks?: PublicKey[]
34+
) {
35+
let councilMintPk: PublicKey | undefined = undefined
36+
let walletAtaPk: PublicKey | undefined
37+
const councilMintInstructions: TransactionInstruction[] = []
38+
const councilMintSigners: Keypair[] = []
39+
40+
// If the array of council wallets is not empty
41+
// then should create mints to the council
42+
if (councilWalletPks && councilWalletPks.length) {
43+
// If councilMint is undefined, then
44+
// should create the council mint
45+
councilMintPk =
46+
councilMint ??
47+
(await withCreateMint(
48+
connection,
49+
councilMintInstructions,
50+
councilMintSigners,
51+
walletPubkey,
52+
null,
53+
0,
54+
walletPubkey
55+
))
56+
57+
for (const teamWalletPk of councilWalletPks) {
58+
const ataPk = await withCreateAssociatedTokenAccount(
59+
councilMintInstructions,
60+
councilMintPk,
61+
teamWalletPk,
62+
walletPubkey
63+
)
64+
65+
// Mint 1 council token to each team member
66+
await withMintTo(
67+
councilMintInstructions,
68+
councilMintPk,
69+
ataPk,
70+
walletPubkey,
71+
1
72+
)
73+
74+
if (teamWalletPk.equals(walletPubkey)) {
75+
walletAtaPk = ataPk
76+
}
77+
}
78+
}
79+
80+
const councilMembersChunks = chunks(councilMintInstructions, 10)
81+
// only walletPk needs to sign the minting instructions and it's a signer by default and we don't have to include any more signers
82+
const councilSignersChunks = Array(councilMembersChunks.length).fill(
83+
councilMintSigners
84+
)
85+
86+
return {
87+
councilMintPk,
88+
walletAtaPk,
89+
councilMembersChunks,
90+
councilSignersChunks,
91+
}
92+
}
893

994
export async function registerRealm(
1095
{ connection, wallet, walletPubkey }: RpcContext,
@@ -14,27 +99,72 @@ export async function registerRealm(
1499
communityMint: PublicKey,
15100
councilMint: PublicKey | undefined,
16101
communityMintMaxVoteWeightSource: MintMaxVoteWeightSource,
17-
minCommunityTokensToCreateGovernance: BN
102+
minCommunityTokensToCreateGovernance: BN,
103+
councilWalletPks?: PublicKey[]
18104
): Promise<PublicKey> {
19-
const instructions: TransactionInstruction[] = []
105+
const realmInstructions: TransactionInstruction[] = []
106+
107+
const {
108+
councilMintPk,
109+
walletAtaPk,
110+
councilMembersChunks,
111+
councilSignersChunks,
112+
} = await prepareCouncilInstructions(
113+
connection,
114+
walletPubkey,
115+
councilMint,
116+
councilWalletPks
117+
)
20118

21119
const realmAddress = await withCreateRealm(
22-
instructions,
120+
realmInstructions,
23121
programId,
24122
programVersion,
25123
name,
26124
walletPubkey,
27125
communityMint,
28126
walletPubkey,
29-
councilMint,
127+
councilMintPk,
30128
communityMintMaxVoteWeightSource,
31129
minCommunityTokensToCreateGovernance,
32130
undefined
33131
)
34132

133+
// If the current wallet is in the team then deposit the council token
134+
if (councilMintPk)
135+
if (walletAtaPk) {
136+
await withDepositGoverningTokens(
137+
realmInstructions,
138+
programId,
139+
realmAddress,
140+
walletAtaPk,
141+
councilMintPk,
142+
walletPubkey,
143+
walletPubkey,
144+
walletPubkey
145+
)
146+
} else {
147+
// Let's throw for now if the current wallet isn't in the team
148+
// TODO: To fix it we would have to make it temp. as part of the team and then remove after the realm is created
149+
throw new Error('Current wallet must be in the team')
150+
}
151+
35152
const transaction = new Transaction()
36-
transaction.add(...instructions)
153+
transaction.add(...realmInstructions)
154+
155+
if (!wallet) throw WalletConnectionError
156+
157+
if (councilMembersChunks.length) {
158+
await sendTransactions(
159+
connection,
160+
wallet,
161+
[...councilMembersChunks, realmInstructions],
162+
[...councilSignersChunks, []],
163+
SequenceType.Sequential
164+
)
165+
} else {
166+
await sendTransaction({ transaction, wallet, connection })
167+
}
37168

38-
await sendTransaction({ transaction, wallet, connection })
39169
return realmAddress
40170
}

components/ConnectWalletButton.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ const ConnectWalletButton = (props) => {
2525
providerUrl,
2626
])
2727

28-
const handleConnectDisconnect = () => {
29-
if (connected) {
30-
current?.disconnect()
31-
} else {
32-
current?.connect()
28+
const handleConnectDisconnect = async () => {
29+
try {
30+
if (connected) {
31+
await current?.disconnect()
32+
} else {
33+
await current?.connect()
34+
}
35+
} catch (e) {
36+
console.warn('handleConnectDisconnect', e)
3337
}
3438
}
3539

components/DiscordIcon.tsx

Lines changed: 27 additions & 0 deletions
Large diffs are not rendered by default.

components/Footer.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import DiscordIcon from './DiscordIcon'
2+
import GithubIcon from './GithubIcon'
3+
import TwitterIcon from './TwitterIcon'
4+
5+
const Footer = () => {
6+
return (
7+
<div className="flex justify-around bottom-0 bg-bkg-1 w-full absolute left-0 h-20 px-12 border-t border-primary-light">
8+
<div className="flex justify-center items-center gap-x-6">
9+
<a
10+
rel="noreferrer"
11+
href="https://docs.realms.today/"
12+
target="_blank"
13+
className="text-white text-base font-bold hover:text-primary-dark transition-all duration-200"
14+
>
15+
Docs
16+
</a>
17+
18+
<a
19+
rel="noreferrer"
20+
href="https://github.com/solana-labs/solana-program-library/blob/master/governance/README.md"
21+
target="_blank"
22+
className="text-white text-base font-light hover:text-primary-dark transition-all duration-200"
23+
>
24+
Programs Github
25+
</a>
26+
</div>
27+
28+
<div className="flex justify-center items-center gap-x-24">
29+
<a
30+
rel="noreferrer"
31+
target="_blank"
32+
href="https://twitter.com/solana"
33+
className="text-primary-light text-base font-light"
34+
>
35+
<TwitterIcon className="" />
36+
</a>
37+
38+
<a
39+
rel="noreferrer"
40+
target="_blank"
41+
href="https://github.com/solana-labs/governance-ui"
42+
className="text-primary-light text-base font-light"
43+
>
44+
<GithubIcon className="" />
45+
</a>
46+
47+
<a
48+
rel="noreferrer"
49+
target="_blank"
50+
href="https://discord.com/invite/VsPbrK2hJk"
51+
className="text-primary-light text-base font-light"
52+
>
53+
<DiscordIcon className="" />
54+
</a>
55+
</div>
56+
57+
<div className="flex justify-center items-center gap-x-1">
58+
<p className="text-white text-base font-light cursor-default">
59+
Powered by
60+
</p>
61+
62+
<a
63+
rel="noreferrer"
64+
href="https://solana.com/"
65+
target="_blank"
66+
className="text-white text-base font-bold hover:text-primary-dark transition-all duration-200"
67+
>
68+
Solana
69+
</a>
70+
</div>
71+
</div>
72+
)
73+
}
74+
75+
export default Footer

components/GithubIcon.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const GithubIcon = ({ className }) => {
2+
return (
3+
<svg
4+
className={className}
5+
width="24"
6+
height="24"
7+
viewBox="0 0 24 24"
8+
fill="none"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<path
12+
d="M15.9995 21.9999V18.1299C16.037 17.6531 15.9726 17.1737 15.8105 16.7237C15.6485 16.2737 15.3924 15.8634 15.0595 15.5199C18.1995 15.1699 21.4995 13.9799 21.4995 8.51994C21.4993 7.12377 20.9622 5.78114 19.9995 4.76994C20.4554 3.54844 20.4231 2.19829 19.9095 0.999938C19.9095 0.999938 18.7295 0.649938 15.9995 2.47994C13.7075 1.85876 11.2915 1.85876 8.99951 2.47994C6.26951 0.649938 5.08951 0.999938 5.08951 0.999938C4.57589 2.19829 4.54366 3.54844 4.99951 4.76994C4.02964 5.78864 3.49203 7.1434 3.49951 8.54994C3.49951 13.9699 6.79951 15.1599 9.93951 15.5499C9.61051 15.8899 9.35678 16.2953 9.19482 16.7399C9.03287 17.1844 8.96632 17.658 8.99951 18.1299V21.9999M8.99951 18.9999C3.99951 20.4999 3.99951 16.4999 1.99951 15.9999L8.99951 18.9999Z"
13+
stroke="#E1CE7A"
14+
strokeWidth="1.5"
15+
strokeLinecap="round"
16+
strokeLinejoin="round"
17+
/>
18+
</svg>
19+
)
20+
}
21+
22+
export default GithubIcon

components/Members/AddMember.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const AddMember = () => {
205205
<h3 className="mb-4 flex items-center hover:cursor-pointer">
206206
<>
207207
<ArrowLeftIcon
208-
onClick={() => setCurrentCompactView(ViewState.MemberOverview)}
208+
onClick={handleGoBackToMainView}
209209
className="h-4 w-4 mr-1 text-primary-light mr-2"
210210
/>
211211
Add new member

0 commit comments

Comments
 (0)