Skip to content

Commit

Permalink
Add Friktion - Claim Pending Deposit/Withdraw Instructions (solana-la…
Browse files Browse the repository at this point in the history
…bs#514)

* start adding friktion

* fix friktion deposit

* add claim pending ixs

* remove unnecessary createATA check

* bump friktion sdk

* fix merge conflicts

* bump friktion sdk

* parent 8155368
author bigdefidev <[email protected]> 1651008195 -0500
committer bigdefidev <[email protected]> 1654563073 -0500

parent 8155368
author bigdefidev <[email protected]> 1651008195 -0500
committer bigdefidev <[email protected]> 1654563034 -0500

upgrade sdk, change how volt is loaded

friktion related changes

* upgrade friktion sdk to 1.1.114

* use upstream main yarn.lock

* fix lint errors

fmt

fix withdrawHumanAmount params

* update yarn.lock to friktion sdk 1.1.115

* revert back

* new yarn.lock

* Revert "new yarn.lock"

This reverts commit 5582762.

* update yarn lock

* update lock file

* bump sdk again

* remove duplicate

Co-authored-by: bigdefidev <[email protected]>
  • Loading branch information
jasonchitla and bigdefidev authored Jun 13, 2022
1 parent a2e46d5 commit 3d75c1b
Show file tree
Hide file tree
Showing 12 changed files with 812 additions and 341 deletions.
1 change: 0 additions & 1 deletion actions/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export const createProposal = async (
sendingMessage: `creating ${notificationTitle}`,
successMessage: `${notificationTitle} created`,
})

await sendTransaction({
transaction: transaction2,
wallet,
Expand Down
43 changes: 39 additions & 4 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,30 @@ export default function useGovernanceAssets() {
isVisible: canUseProgramUpgradeInstruction && symbol === 'MNGO',
},
{
id: Instructions.DepositIntoCastle,
name: 'Castle: Deposit into Vault',
id: Instructions.Mint,
name: 'Mint Tokens',
isVisible: canUseMintInstruction,
},
{
id: Instructions.CreateAssociatedTokenAccount,
name: 'Create Associated Token Account',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.WithrawFromCastle,
name: 'Castle: Withdraw from Vault',
id: Instructions.Base64,
name: 'Execute Custom Instruction',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.VotingMintConfig,
name: 'Vote Escrowed Tokens: Configure Voting Mint',
isVisible: canUseAuthorityInstruction,
},
{
id: Instructions.CreateVsrRegistrar,
name: 'Vote Escrowed Tokens: Create Registrar',
isVisible: canUseAuthorityInstruction,
},
{
id: Instructions.DepositIntoVolt,
name: 'Friktion: Deposit into Volt',
Expand All @@ -311,6 +326,26 @@ export default function useGovernanceAssets() {
name: 'Friktion: Withdraw from Volt',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ClaimPendingDeposit,
name: 'Friktion: Claim Volt Tokens',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ClaimPendingWithdraw,
name: 'Friktion: Claim Pending Withdraw',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.DepositIntoCastle,
name: 'Castle: Deposit into Vault',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.WithrawFromCastle,
name: 'Castle: Withdraw from Vault',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.DepositIntoGoblinGold,
name: 'GoblinGold: Deposit into GoblinGold',
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"@dialectlabs/react-ui": "0.8.2",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@friktion-labs/friktion-sdk": "^1.1.118",
"@foresight-tmp/foresight-sdk": "^0.1.44",
"@friktion-labs/friktion-sdk": "^1.1.25",
"@headlessui/react": "^1.5.0",
"@heroicons/react": "^1.0.1",
"@marinade.finance/marinade-ts-sdk": "^2.0.9",
Expand All @@ -54,7 +54,7 @@
"@solana/governance-program-library": "^0.15.2",
"@solana/spl-governance": "^0.0.34",
"@solana/spl-token": "0.1.8",
"@solana/spl-token-registry": "^0.2.3470",
"@solana/spl-token-registry": "^0.2.3775",
"@solana/wallet-adapter-base": "^0.9.5",
"@solana/wallet-adapter-glow": "^0.1.1",
"@solana/wallet-adapter-phantom": "^0.9.3",
Expand Down Expand Up @@ -98,15 +98,15 @@
"@types/react": "^17.0.44",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.18.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.3.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-react-hooks": "^4.5.0",
"husky": "^6.0.0",
"jest": "^27.4.5",
"lint-staged": "^10.0.10",
"next-router-mock": "^0.6.7",
"postcss": "^8.2.12",
"postcss": "^8.4.12",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.0.2",
"tailwindcss": "^3.0.23",
Expand All @@ -117,5 +117,8 @@
"twin": {
"preset": "emotion"
}
},
"resolutions": {
"port-sdk/@saberhq/token-utils": "1.12.53"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React, { useContext, useEffect, useState } from 'react'
import useRealm from '@hooks/useRealm'
import { PublicKey } from '@solana/web3.js'
import useWalletStore from 'stores/useWalletStore'
import {
FriktionClaimPendingDepositForm,
UiInstruction,
} from '@utils/uiTypes/proposalCreationTypes'
import { NewProposalContext } from '../../../new'
import { getFriktionClaimPendingDepositSchema } from '@utils/validations'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import GovernedAccountSelect from '../../GovernedAccountSelect'
import { getFriktionClaimPendingDepositInstruction } from '@utils/instructions/Friktion'
import Select from '@components/inputs/Select'
import { FriktionSnapshot, VoltSnapshot } from '@friktion-labs/friktion-sdk'

const FriktionClaimPendingDeposit = ({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) => {
const connection = useWalletStore((s) => s.connection)
const wallet = useWalletStore((s) => s.current)
const { realmInfo } = useRealm()
const { governedTokenAccountsWithoutNfts } = useGovernanceAssets()
const shouldBeGoverned = index !== 0 && governance
const programId: PublicKey | undefined = realmInfo?.programId
const [form, setForm] = useState<FriktionClaimPendingDepositForm>({
governedTokenAccount: undefined,
voltVaultId: '',
programId: programId?.toString(),
mintInfo: undefined,
})
// eslint-disable-next-line @typescript-eslint/ban-types
const [friktionVolts, setFriktionVolts] = useState<VoltSnapshot[] | null>(
null
)
const [governedAccount, setGovernedAccount] = useState<
ProgramAccount<Governance> | undefined
>(undefined)
const [formErrors, setFormErrors] = useState({})
const { handleSetInstructions } = useContext(NewProposalContext)
const handleSetForm = ({ propertyName, value }) => {
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const setMintInfo = (value) => {
setForm({ ...form, mintInfo: value })
}

async function getInstruction(): Promise<UiInstruction> {
return getFriktionClaimPendingDepositInstruction({
schema,
form,
programId,
connection,
wallet,
setFormErrors,
})
}
useEffect(() => {
// call for the mainnet friktion volts
const callfriktionRequest = async () => {
const response = await fetch(
'https://friktion-labs.github.io/mainnet-tvl-snapshots/friktionSnapshot.json'
)
const parsedResponse = (await response.json()) as FriktionSnapshot
setFriktionVolts(parsedResponse.allMainnetVolts as VoltSnapshot[])
}

callfriktionRequest()
}, [])

useEffect(() => {
handleSetForm({
propertyName: 'programId',
value: programId?.toString(),
})
}, [realmInfo?.programId])
useEffect(() => {
handleSetInstructions(
{ governedAccount: governedAccount, getInstruction },
index
)
}, [form])
useEffect(() => {
setGovernedAccount(form.governedTokenAccount?.governance)
setMintInfo(form.governedTokenAccount?.extensions.mint?.account)
}, [form.governedTokenAccount])
const schema = getFriktionClaimPendingDepositSchema()

return (
<>
<GovernedAccountSelect
label="Source account"
governedAccounts={governedTokenAccountsWithoutNfts}
onChange={(value) => {
handleSetForm({ value, propertyName: 'governedTokenAccount' })
}}
value={form.governedTokenAccount}
error={formErrors['governedTokenAccount']}
shouldBeGoverned={shouldBeGoverned}
governance={governance}
></GovernedAccountSelect>
<Select
label="Friktion Volt"
value={form.voltVaultId}
placeholder="Please select..."
onChange={(value) =>
handleSetForm({ value, propertyName: 'voltVaultId' })
}
error={formErrors['voltVaultId']}
>
{friktionVolts
?.filter((x) => !x.isInCircuits)
.map((value) => (
<Select.Option key={value.voltVaultId} value={value.voltVaultId}>
<div className="break-all text-fgd-1 ">
<div className="mb-2">{`Volt #${value.voltType} - ${
value.voltType === 1
? 'Generate Income'
: value.voltType === 2
? 'Sustainable Stables'
: ''
} - ${value.underlyingTokenSymbol} - APY: ${value.apy}%`}</div>
<div className="space-y-0.5 text-xs text-fgd-3">
<div className="flex items-center">
Deposit Token: {value.depositTokenSymbol}
</div>
{/* <div>Capacity: {}</div> */}
</div>
</div>
</Select.Option>
))}
</Select>
</>
)
}

export default FriktionClaimPendingDeposit
Loading

0 comments on commit 3d75c1b

Please sign in to comment.