Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway compose [WIP] #2

Open
wants to merge 81 commits into
base: gateway
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
85f3d14
Gateway Plugin: Support predecessors during registrar creation (WIP)
dankelleher Jun 14, 2022
af4157e
Merge branch 'gateway' into gateway-compose
dankelleher Jun 14, 2022
f61f7cd
Gateway Plugin: Composability first pass
dankelleher Jun 15, 2022
a8c471c
Merge branch 'gateway' into gateway-compose
dankelleher Jun 16, 2022
1c7918d
Merge branch 'gateway' into gateway-compose
dankelleher Jun 16, 2022
93d2844
Merge branch 'gateway' into gateway-compose
dankelleher Jun 16, 2022
57477c4
fix twtiter card logo + strategy invest (#771)
abrzezinski94 Jun 20, 2022
db80f28
img from github for twitter (#772)
abrzezinski94 Jun 20, 2022
9c1f571
fix mixed content (#773)
abrzezinski94 Jun 20, 2022
14c677b
Updated image file ext to .png (#738)
CreatedbyIO Jun 20, 2022
046a7f0
Civic Pass UI integration (#719)
dankelleher Jun 20, 2022
b37a292
set quote instruction (#777)
abrzezinski94 Jun 21, 2022
40cc462
Feature/fix naming spot market inst (#778)
abrzezinski94 Jun 21, 2022
3030ccd
Bugfix/gatekeeper network load on nft plugin (#779)
dankelleher Jun 22, 2022
494bf11
Update civic plugin UI version (#776)
dankelleher Jun 22, 2022
7c07171
Add Global DAO Alerts for Realms Notification across via Notifi Provi…
Nathan-Notifi Jun 22, 2022
e2c3daf
set market mode upgrade mango lib (#780)
abrzezinski94 Jun 22, 2022
2c7c9ce
Fix tutorial docs link (#781)
nramadas Jun 23, 2022
9a7164a
Feature/mango sol deposit fix (#782)
abrzezinski94 Jun 24, 2022
b4180f7
Feature/withdraw sol mang fix (#787)
abrzezinski94 Jun 24, 2022
ef24c6a
Add a typeahead for the transactions dropdown (#786)
nramadas Jun 27, 2022
ebaf09d
Add delegate card back (#794)
ndrabins Jun 27, 2022
b81ba33
Update set authority (#790)
tomjohn1028 Jun 28, 2022
1e6fa82
add PSY gov program to realms list (#792)
tomjohn1028 Jun 28, 2022
90e86e6
Flipside Governance Info (#800)
dobbinsi Jun 28, 2022
a906dcd
Update Notifi FAQ URL (#789)
nimesh-notifi Jun 28, 2022
2cffae1
Stop Switchboard code from running on all DAOs (#785)
S1nus Jun 28, 2022
76086e1
Wisdom Enterprsing Logo/details (#783)
dukemtambo Jun 28, 2022
55fe261
Update Realms Logos, Governance DAO, RED DAO (#808)
harivmasoor Jun 29, 2022
8ea5bf8
Add ability to transfer program authority (#805)
tomjohn1028 Jun 29, 2022
1af75db
Add a character count to proposal titles (#804)
nramadas Jun 29, 2022
1729f85
Improve the error message for "create dao" button (#809)
nramadas Jun 29, 2022
b5c1015
dev (#1) (#812)
EvgeniiVoznyuk Jun 30, 2022
22f6a5f
ADD YELLOW MAN DAO REALM INFO ON THE DEVNET (#810)
hassanv2 Jun 30, 2022
39f7048
Update Favicons (#814)
harivmasoor Jul 1, 2022
0b7e078
Don't create mint governance if there no authority (#815)
nramadas Jul 1, 2022
4bb0772
mango remove spot + perp instructions (#816)
abrzezinski94 Jul 1, 2022
6dc5ef6
Fix/delist spot (#817)
abrzezinski94 Jul 3, 2022
997317c
Fix/nft fix v2 (#818)
abrzezinski94 Jul 3, 2022
4332878
Feature/fix nfts v3 (#819)
abrzezinski94 Jul 3, 2022
91cf0ae
fix nft release (#820)
abrzezinski94 Jul 3, 2022
8e379de
lower transaction forward threshold (#821)
abrzezinski94 Jul 4, 2022
c86146e
Fix/remove spot instruction decode (#822)
abrzezinski94 Jul 4, 2022
610307c
Update AthensDAO Icon & Info (#824)
jahris23 Jul 6, 2022
094bedf
Samo Image (#827)
harivmasoor Jul 6, 2022
bb55e9c
upgrading Profile pic (#813)
DimiMili Jul 7, 2022
9be6c94
Banner Image ATH DAO (#834)
harivmasoor Jul 7, 2022
bb1ce22
Add Bootstrap DAO Charter (#835)
boot6567 Jul 7, 2022
29b764b
Merge remote-tracking branch 'upstream/main' into gateway-compose
dankelleher Jul 8, 2022
897c3b1
Add laptopDAO (#836)
xentoshi Jul 8, 2022
eaf7fee
Update gpl lib version
dankelleher Jul 9, 2022
79b5187
Feature/swap spot (#838)
abrzezinski94 Jul 9, 2022
e6b6aaa
Change of existing logo img (#837)
xentoshi Jul 9, 2022
1cb6680
Merge remote-tracking branch 'upstream/main' into gateway-compose
dankelleher Jul 11, 2022
ffd7296
Fix/mango withdraw (#842)
abrzezinski94 Jul 11, 2022
522694d
chore: change api RPC (#843)
SebastianBor Jul 11, 2022
063e9df
Improve proposal state display (#823)
nramadas Jul 12, 2022
1925a62
Move the discussion panel down on narrow screens (#845)
nramadas Jul 12, 2022
e5c8013
Add better loading and zero states to <ProposalVotingPower/> (#846)
nramadas Jul 13, 2022
81c0ce7
Update gpl lib version
dankelleher Jul 13, 2022
9ff2a95
fix: don't create mint governance if user has no authority (#850)
SebastianBor Jul 14, 2022
29de3ac
Add Ratio Finance (#851)
NicolasBnana Jul 14, 2022
02eae05
Feature/remove add signatory (#853)
abrzezinski94 Jul 14, 2022
dd3d6bd
Split nft fetching into smaller requests (#854)
nramadas Jul 15, 2022
71d5eea
Merge branch 'main' into gateway-compose
dankelleher Jul 15, 2022
3664aca
fix dao url in bot (#855)
abrzezinski94 Jul 15, 2022
32ca67b
Simplified Sending of NFT's (#852)
devsalmon Jul 15, 2022
2a9f956
npm: bump @project-serum/anchor from 0.24.2 to 0.25.0 (#856)
dependabot[bot] Jul 15, 2022
11585c7
npm: bump @typescript-eslint/parser from 5.18.0 to 5.30.6 (#857)
dependabot[bot] Jul 15, 2022
1dc44cc
Civic Gateway Lib: Post merge fixes
dankelleher Jul 15, 2022
97e2357
Merge branch 'main' into gateway-compose
dankelleher Jul 15, 2022
7cde8e3
Post merge build fixes
dankelleher Jul 15, 2022
b3cfdb7
fix: Always create mint governance for generated tokens (#859)
SebastianBor Jul 15, 2022
016efd0
Anchor update fixes
dankelleher Jul 15, 2022
9c894ee
fix build errors (#860)
abrzezinski94 Jul 15, 2022
0886f2f
npm: bump @typescript-eslint/eslint-plugin from 5.21.0 to 5.30.6 (#858)
dependabot[bot] Jul 15, 2022
c561e67
Merge branch 'main' into gateway-compose
dankelleher Jul 15, 2022
671d2f1
Updates after anchor revert
dankelleher Jul 15, 2022
1fd1933
Revert "npm: bump @project-serum/anchor from 0.24.2 to 0.25.0 (#856)"…
abrzezinski94 Jul 15, 2022
d1ab9ea
fix url (#865)
abrzezinski94 Jul 16, 2022
0d4a9c7
Merge branch 'main' into gateway-compose
dankelleher Jul 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["Addin", "blockworks", "lamports", "solana", "VERCEL"]
"cSpell.words": ["Addin", "blockworks", "lamports", "solana", "VERCEL"],
"editor.formatOnSave": true
}
135 changes: 66 additions & 69 deletions GatewayPlugin/sdk/accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
import { PublicKey } from '@solana/web3.js'
import { ProgramAccount, Realm } from '@solana/spl-governance'
import {
getTokenOwnerRecordAddress,
ProgramAccount,
Realm,
} from '@solana/spl-governance'
import { GatewayClient } from '@solana/governance-program-library/dist'
import { getRegistrarPDA, getVoterWeightRecord } from '@utils/plugin/accounts'

// TODO merge this with NFTVotePlugin as it is essentially identical
export const getGatewayRegistrarPDA = async (
realmPk: PublicKey,
mint: PublicKey,
clientProgramId: PublicKey
) => {
const [registrar, registrarBump] = await PublicKey.findProgramAddress(
[Buffer.from('registrar'), realmPk.toBuffer(), mint.toBuffer()],
clientProgramId
)
return {
registrar,
registrarBump,
}
}

export const getGatewayMaxVoterWeightRecord = async (
realmPk: PublicKey,
mint: PublicKey,
clientProgramId: PublicKey
) => {
const [
maxVoterWeightRecord,
maxVoterWeightRecordBump,
] = await PublicKey.findProgramAddress(
[
Buffer.from('max-voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
],
clientProgramId
export const getGatekeeperNetwork = async (
client: GatewayClient,
realm: ProgramAccount<Realm>
): Promise<PublicKey> => {
// Get the registrar for the realm
const { registrar } = await getRegistrarPDA(
realm.pubkey,
realm.account.communityMint,
client.program.programId
)
return {
maxVoterWeightRecord,
maxVoterWeightRecordBump,
}
}

export const getGatewayVoterWeightRecord = async (
realmPk: PublicKey,
mint: PublicKey,
walletPk: PublicKey,
clientProgramId: PublicKey
) => {
const [
voterWeightPk,
voterWeightRecordBump,
] = await PublicKey.findProgramAddress(
[
Buffer.from('voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
walletPk.toBuffer(),
],
clientProgramId
const registrarObject = await client.program.account.registrar.fetch(
registrar
)

return {
voterWeightPk,
voterWeightRecordBump,
}
// Find the gatekeeper network from the registrar
return registrarObject.gatekeeperNetwork
}

export const getGatekeeperNetwork = async (
export const getPredecessorProgramId = async (
client: GatewayClient,
realm: ProgramAccount<Realm>
): Promise<PublicKey> => {
): Promise<PublicKey | null> => {
// Get the registrar for the realm
const { registrar } = await getGatewayRegistrarPDA(
const { registrar } = await getRegistrarPDA(
realm.pubkey,
realm.account.communityMint,
client.program.programId
Expand All @@ -80,40 +40,77 @@ export const getGatekeeperNetwork = async (
)

// Find the gatekeeper network from the registrar
return registrarObject.gatekeeperNetwork
return registrarObject.previousVoterWeightPluginProgramId
}

export const getPreviousVotingWeightRecord = async (
client: GatewayClient,
realm: ProgramAccount<Realm>,
walletPk: PublicKey
): Promise<PublicKey> => {
// TODO cache this to avoid lookup every time someone votes
const predecessorProgramId = await getPredecessorProgramId(client, realm)

if (predecessorProgramId) {
// this gateway plugin registrar has a predecessor plugin - get its voting weight record
const { voterWeightPk } = await getVoterWeightRecord(
realm.pubkey,
realm.account.communityMint,
walletPk,
predecessorProgramId
)
return voterWeightPk
}

// this gateway plugin registrar has no predecessor plugin.
// The previous voting weight record is the token owner record
return getTokenOwnerRecordAddress(
realm.owner,
realm.pubkey,
realm.account.communityMint,
walletPk
)
}

export const getVoteInstruction = async (
client: GatewayClient,
gatewayToken: PublicKey,
realm: ProgramAccount<Realm>,
walletPk: PublicKey,
proposalPk: PublicKey
walletPk: PublicKey
) => {
// Throw if the user has no gateway token (TODO handle this later)
if (!gatewayToken) throw new Error(`Unable to vote: No Gateway Token found`)

// get the user's voter weight account address
const { voterWeightPk } = await getGatewayVoterWeightRecord(
const { voterWeightPk } = await getVoterWeightRecord(
realm.pubkey,
realm.account.communityMint,
walletPk,
client.program.programId
)

// Get the registrar for the realm
const { registrar } = await getGatewayRegistrarPDA(
const { registrar } = await getRegistrarPDA(
realm.pubkey,
realm.account.communityMint,
client.program.programId
)

// call updateVoterWeightRecord on the plugin
// the previous voting weight record in the chain of plugins,
// or the token owner record if this is the first plugin in the chain
const inputVoterWeight = await getPreviousVotingWeightRecord(
client,
realm,
walletPk
)

// call updateVotingWeightRecord on the plugin
return client.program.methods
.updateVoterWeightRecord({ castVote: {} }, proposalPk)
.updateVoterWeightRecord()
.accounts({
registrar,
voterWeightRecord: voterWeightPk,
inputVoterWeight,
gatewayToken,
})
.instruction()
Expand Down
9 changes: 9 additions & 0 deletions Strategies/components/DepositModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SolendModalContent from './SolendModalContent'
import MangoDeposit from './MangoDepositComponent'
import BigNumber from 'bignumber.js'
import { SolendStrategy } from 'Strategies/types/types'
import EverlendModalContent from './EverlendModalContent'

const DepositModal = ({
onClose,
Expand Down Expand Up @@ -49,6 +50,14 @@ const DepositModal = ({
createProposalFcn={createProposalFcn}
></MangoDeposit>
) : null}
{protocolName === 'Everlend' ? (
<EverlendModalContent
proposedInvestment={proposedInvestment}
governedTokenAccount={governedTokenAccount}
handledMint={handledMint}
createProposalFcn={createProposalFcn}
/>
) : null}
</Modal>
)
}
Expand Down
85 changes: 85 additions & 0 deletions Strategies/components/EverlendModalContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import ButtonGroup from '@components/ButtonGroup'
import { useEffect, useState } from 'react'
import { TreasuryStrategy } from 'Strategies/types/types'
import { CreateEverlendProposal } from 'Strategies/protocols/everlend/tools'
import { AssetAccount } from '@utils/uiTypes/assets'
import EverlendDeposit from './everlend/EverlendDeposit'
import EverlendWithdraw from './everlend/EverlendWithdraw'
import { findAssociatedTokenAccount } from '@everlend/common'
import { PublicKey } from '@solana/web3.js'
import useWalletStore from 'stores/useWalletStore'

enum Tabs {
DEPOSIT = 'Deposit',
WITHDRAW = 'Withdraw',
}

interface IProps {
proposedInvestment: TreasuryStrategy & { poolMint: string }
handledMint: string
createProposalFcn: CreateEverlendProposal
governedTokenAccount: AssetAccount
}

const EverlendModalContent = ({
proposedInvestment,
handledMint,
createProposalFcn,
governedTokenAccount,
}: IProps) => {
const [selectedTab, setSelectedTab] = useState(Tabs.DEPOSIT)
const [depositedAmount, setDepositedAmount] = useState(0)
const tabs = Object.values(Tabs)
const connection = useWalletStore((s) => s.connection)

const isSol = governedTokenAccount.isSol
const owner = isSol
? governedTokenAccount!.pubkey
: governedTokenAccount!.extensions!.token!.account.owner

useEffect(() => {
const loadMaxAmount = async () => {
const tokenMintATA = await findAssociatedTokenAccount(
owner,
new PublicKey(proposedInvestment.poolMint)
)
const tokenMintATABalance = await connection.current.getTokenAccountBalance(
tokenMintATA
)
setDepositedAmount(Number(tokenMintATABalance.value.uiAmount))
}
loadMaxAmount()
}, [proposedInvestment, handledMint])

return (
<div>
<div className="pb-4">
<ButtonGroup
activeValue={selectedTab}
onChange={(tab) => setSelectedTab(tab)}
values={tabs}
/>
</div>
{selectedTab === Tabs.DEPOSIT && (
<EverlendDeposit
proposedInvestment={proposedInvestment}
createProposalFcn={createProposalFcn}
governedTokenAccount={governedTokenAccount}
handledMint={handledMint}
depositedAmount={depositedAmount}
/>
)}
{selectedTab === Tabs.WITHDRAW && (
<EverlendWithdraw
proposedInvestment={proposedInvestment}
createProposalFcn={createProposalFcn}
governedTokenAccount={governedTokenAccount}
handledMint={handledMint}
depositedAmount={depositedAmount}
/>
)}
</div>
)
}

export default EverlendModalContent
5 changes: 1 addition & 4 deletions Strategies/components/MangoDepositComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import useGovernanceAssets from '@hooks/useGovernanceAssets'
import useQueryContext from '@hooks/useQueryContext'
import useRealm from '@hooks/useRealm'
import { getProgramVersionForRealm } from '@models/registry/api'
import { BN } from '@project-serum/anchor'
import {
getNativeTreasuryAddress,
RpcContext,
Expand Down Expand Up @@ -90,9 +89,7 @@ const MangoDepositComponent = ({
const wallet = useWalletStore((s) => s.current)
const tokenInfo = tokenService.getTokenInfo(handledMint)
const { canUseTransferInstruction } = useGovernanceAssets()
const treasuryAmount = governedTokenAccount.extensions?.token
? governedTokenAccount.extensions.token.account.amount
: new BN(0)
const treasuryAmount = governedTokenAccount.extensions.amount!
const mintInfo = governedTokenAccount.extensions?.mint?.account
const [form, setForm] = useState({
title: '',
Expand Down
Loading