Skip to content

Commit

Permalink
Dual finance changes, validation and preview of strikes on Staking Op…
Browse files Browse the repository at this point in the history
…tion (#1785)
  • Loading branch information
brittcyr authored Aug 23, 2023
1 parent 2424bc8 commit 3f78e68
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 44 deletions.
30 changes: 28 additions & 2 deletions components/instructions/programs/dual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
StakingOptions,
STAKING_OPTIONS_PK,
} from '@dual-finance/staking-options'
import { AIRDROP_PK } from '@dual-finance/airdrop'
import { BN, BorshInstructionCoder, Idl } from '@coral-xyz/anchor'
import { AccountMetaData } from '@solana/spl-governance'
import { tryGetMint } from '@utils/tokens'
Expand Down Expand Up @@ -63,7 +64,31 @@ interface exerciseReversibleInstruction {
strike: BN
}

const INSTRUCTIONS = {
// TODO: merkle airdrop
const AIRDROP_INSTRUCTIONS = {
245: {
name: 'Airdrop Configure',
accounts: [
{ name: 'payer' },
{ name: 'state' },
{ name: 'vault' },
{ name: 'mint' },
{ name: 'verifierSignature' },
{ name: 'tokenProgram' },
{ name: 'systemProgram' },
{ name: 'rent' },
],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<div className="space-y-3">
<div>State seed: {data.toString()}</div>
</div>
)
},
},
};

const SO_INSTRUCTIONS = {
45: {
name: 'Staking Option ConfigV3',
accounts: [
Expand Down Expand Up @@ -473,6 +498,7 @@ const GSO_INSTRUCTIONS = {
}

export const DUAL_INSTRUCTIONS = {
[STAKING_OPTIONS_PK.toBase58()]: INSTRUCTIONS,
[AIRDROP_PK.toBase58()]: AIRDROP_INSTRUCTIONS,
[STAKING_OPTIONS_PK.toBase58()]: SO_INSTRUCTIONS,
[GSO_PK.toBase58()]: GSO_INSTRUCTIONS,
}
14 changes: 14 additions & 0 deletions components/instructions/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ export const ACCOUNT_NAMES = {
'Marinade Voter Stake Registry Program Governance',
'6egAu2HDLcSgeUYmiBvNLgp7Bd4nPk16gX9MvWuJpeX2':
'Marinade SPL Program Governance',

// Dual DAO
'4yx1NJ4Vqf2zT1oVLk4SySBhhDJXmXFt88ncm4gPxtL7':
'Staking Options Program',
'2fJcpdR6qzqDP7fBqvoJQ5PGYdaRFBNyUKZkZf5t12mr':
'Airdrop Program',
'8tBcmZAMNm11DuGAS2r6PqSA3CKt72amoz8bVj14xRiT':
'Merkle Airdrop Verifier Program',
ATCsJvzSbHaJj3a9uKTRHSoD8ZmWPfeC3sYxzcJJHTM5:
'Governance Airdrop Verifier Program',
DuALd6fooWzVDkaTsQzDAxPGYCnLrnWamdNNTNxicdX8:
'Lockup Staking Options Program',
'7Z36Efbt7a4nLiV7s5bY7J2e4TJ6V9JEKGccsy2od2bE':
'Dual DAO wallet',
}

// TODO: Add this to on-chain metadata to Governance account
Expand Down
6 changes: 3 additions & 3 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ export default function useGovernanceAssets() {
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceExercise]: {
name: 'Exercise',
[Instructions.DualFinanceExerciseStakingOption]: {
name: 'Exercise Staking Option',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
Expand All @@ -367,7 +367,7 @@ export default function useGovernanceAssets() {
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
},
[Instructions.DualFinanceWithdraw]: {
[Instructions.DualFinanceStakingOptionWithdraw]: {
name: 'Withdraw',
isVisible: canUseTransferInstruction,
packageId: PackageEnum.Dual,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useMemo, useContext, useEffect, useState } from 'react'
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -79,9 +80,8 @@ const DualAirdrop = ({
setGovernedAccount(form.treasury?.governance)
}, [form.treasury])

const merkleSchema = useMemo(getDualFinanceMerkleAirdropSchema, [])

const governanceSchema = useMemo(getDualFinanceGovernanceAirdropSchema, [])
const merkleSchema = getDualFinanceMerkleAirdropSchema({form});
const governanceSchema = getDualFinanceGovernanceAirdropSchema({form});

return (
<>
Expand Down Expand Up @@ -156,8 +156,9 @@ const DualAirdrop = ({
/>
</>
)}
{/* TODO: Note that this is full tokens, not atoms since expectation is that this composes with staking options */}
<Input
label="Total number of tokens"
label="Total number of tokens."
value={form.amount}
type="text"
onChange={(evt) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useMemo, useState } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DualGso = ({
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const schema = getDualFinanceGsoSchema()
const schema = getDualFinanceGsoSchema({form})
useEffect(() => {
function getInstruction(): Promise<UiInstruction> {
return getConfigGsoInstruction({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState, useMemo } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState, useMemo } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -62,7 +62,7 @@ const LiquidityStakingOption = ({
useEffect(() => {
setGovernedAccount(form.baseTreasury?.governance)
}, [form.baseTreasury])
const schema = useMemo(getDualFinanceLiquidityStakingOptionSchema, [])
const schema = getDualFinanceLiquidityStakingOptionSchema({form})

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState, useMemo } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand All @@ -14,6 +14,15 @@ import { getDualFinanceStakingOptionSchema } from '@utils/validations'
import Tooltip from '@components/Tooltip'
import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import useLegacyConnectionContext from '@hooks/useLegacyConnectionContext'
import { getTreasuryAccountItemInfoV2 } from '@utils/treasuryTools'

interface MintMetadata {
logo: string,
name: string,
symbol: string,
displayPrice: string,
decimals: number,
}

const StakingOption = ({
index,
Expand All @@ -26,7 +35,7 @@ const StakingOption = ({
soName: undefined,
optionExpirationUnixSeconds: 0,
numTokens: 0,
lotSize: 0,
lotSize: 1,
baseTreasury: undefined,
quoteTreasury: undefined,
payer: undefined,
Expand All @@ -42,12 +51,16 @@ const StakingOption = ({
>(undefined)

const [formErrors, setFormErrors] = useState({})

const [baseMetadata, setBaseMetadata] = useState<MintMetadata>()
const [quoteMetadata, setQuoteMetadata] = useState<MintMetadata>()

const { handleSetInstructions } = useContext(NewProposalContext)
const handleSetForm = ({ propertyName, value }) => {
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const schema = useMemo(getDualFinanceStakingOptionSchema, [])
const schema = getDualFinanceStakingOptionSchema({form, connection});
useEffect(() => {
function getInstruction(): Promise<UiInstruction> {
return getConfigInstruction({
Expand All @@ -62,6 +75,40 @@ const StakingOption = ({
{ governedAccount: governedAccount, getInstruction },
index
)
if (form.baseTreasury && form.baseTreasury.extensions.mint && form.baseTreasury.extensions.mint.account.decimals) {
const {
logo,
name,
symbol,
displayPrice,
} = getTreasuryAccountItemInfoV2(form.baseTreasury)
setBaseMetadata({
logo,
name,
symbol,
displayPrice,
decimals: form.baseTreasury.extensions.mint.account.decimals
})
} else {
setBaseMetadata(undefined)
}
if (form.quoteTreasury && form.quoteTreasury.extensions.mint && form.quoteTreasury.extensions.mint.account.decimals) {
const {
logo,
name,
symbol,
displayPrice,
} = getTreasuryAccountItemInfoV2(form.quoteTreasury)
setQuoteMetadata({
logo,
name,
symbol,
displayPrice,
decimals: form.quoteTreasury.extensions.mint.account.decimals
})
} else {
setQuoteMetadata(undefined)
}
}, [
form,
governedAccount,
Expand Down Expand Up @@ -205,6 +252,31 @@ const StakingOption = ({
error={formErrors['userPk']}
/>
</Tooltip>
{baseMetadata && quoteMetadata && (
<>
<div className="p-3 border rounded-lg text-fgd-1 border-fgd-4 w-full">
{form.strike / form.lotSize * 10 ** (-quoteMetadata.decimals + baseMetadata.decimals) / form.numTokens * 10 ** baseMetadata.decimals}
<img
className={`h-6 w-6`}
src={quoteMetadata.logo}
onError={({ currentTarget }) => {
currentTarget.onerror = null // prevents looping
currentTarget.hidden = true
}}
/>
=
{form.numTokens / 10 ** baseMetadata.decimals}
<img
className={`h-6 w-6`}
src={baseMetadata.logo}
onError={({ currentTarget }) => {
currentTarget.onerror = null // prevents looping
currentTarget.hidden = true
}}
/>
</ div >
</>
)}
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions pages/dao/[symbol]/proposal/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ const New = () => {
[Instructions.DualFinanceGsoWithdraw]: DualGsoWithdraw,
[Instructions.DualFinanceInitStrike]: InitStrike,
[Instructions.DualFinanceLiquidityStakingOption]: LiquidityStakingOption,
[Instructions.DualFinanceWithdraw]: DualWithdraw,
[Instructions.DualFinanceExercise]: DualExercise,
[Instructions.DualFinanceStakingOptionWithdraw]: DualWithdraw,
[Instructions.DualFinanceExerciseStakingOption]: DualExercise,
[Instructions.DualFinanceDelegate]: DualDelegate,
[Instructions.DualFinanceDelegateWithdraw]: DualVoteDepositWithdraw,
[Instructions.DualFinanceVoteDeposit]: DualVoteDeposit,
Expand Down
6 changes: 3 additions & 3 deletions utils/uiTypes/proposalCreationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as PaymentStreaming from '@mean-dao/payment-streaming'
// Alphabetical order
export enum PackageEnum {
Common,
Dual,
Foresight,
GatewayPlugin,
Identity,
Expand All @@ -25,7 +26,6 @@ export enum PackageEnum {
Solend,
Switchboard,
VsrPlugin,
Dual,
}

export interface UiInstruction {
Expand Down Expand Up @@ -329,13 +329,13 @@ export enum Instructions {
DepositReserveLiquidityAndObligationCollateral,
DifferValidatorStake,
DualFinanceAirdrop,
DualFinanceExercise,
DualFinanceExerciseStakingOption,
DualFinanceLiquidityStakingOption,
DualFinanceInitStrike,
DualFinanceStakingOption,
DualFinanceGso,
DualFinanceGsoWithdraw,
DualFinanceWithdraw,
DualFinanceStakingOptionWithdraw,
DualFinanceDelegate,
DualFinanceDelegateWithdraw,
DualFinanceVoteDeposit,
Expand Down
Loading

1 comment on commit 3f78e68

@vercel
Copy link

@vercel vercel bot commented on 3f78e68 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

governance-ui-git-main-solana-labs.vercel.app
governance-ui-solana-labs.vercel.app
app.realms.today

Please sign in to comment.