Skip to content

Commit

Permalink
Integration: Castle deposit and withdraw (solana-labs#661)
Browse files Browse the repository at this point in the history
* npm: bump @solana/spl-token from 0.1.8 to 0.2.0 (#2)

Bumps [@solana/spl-token](https://github.com/solana-labs/solana-program-library) from 0.1.8 to 0.2.0.
- [Release notes](https://github.com/solana-labs/solana-program-library/releases)
- [Commits](https://github.com/solana-labs/solana-program-library/compare/@solana/spl-token@v0.1.8...stake-pool-v0.2.0)

---
updated-dependencies:
- dependency-name: "@solana/spl-token"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump tsconfig-paths from 3.12.0 to 3.14.1 (#3)

Bumps [tsconfig-paths](https://github.com/dividab/tsconfig-paths) from 3.12.0 to 3.14.1.
- [Release notes](https://github.com/dividab/tsconfig-paths/releases)
- [Changelog](https://github.com/dividab/tsconfig-paths/blob/master/CHANGELOG.md)
- [Commits](dividab/tsconfig-paths@v3.12.0...v3.14.1)

---
updated-dependencies:
- dependency-name: tsconfig-paths
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump next from 12.1.4 to 12.1.5 (#4)

Bumps [next](https://github.com/vercel/next.js) from 12.1.4 to 12.1.5.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v12.1.4...v12.1.5)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump dayjs from 1.10.7 to 1.11.1 (#6)

Bumps [dayjs](https://github.com/iamkun/dayjs) from 1.10.7 to 1.11.1.
- [Release notes](https://github.com/iamkun/dayjs/releases)
- [Changelog](https://github.com/iamkun/dayjs/blob/dev/CHANGELOG.md)
- [Commits](iamkun/dayjs@v1.10.7...v1.11.1)

---
updated-dependencies:
- dependency-name: dayjs
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @typescript-eslint/eslint-plugin from 5.19.0 to 5.20.0 (#7)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.19.0 to 5.20.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.20.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @blockworks-foundation/mango-client from 3.4.3 to 3.4.4 (#9)

Bumps [@blockworks-foundation/mango-client](https://github.com/blockworks-foundation/mango-client-v3) from 3.4.3 to 3.4.4.
- [Release notes](https://github.com/blockworks-foundation/mango-client-v3/releases)
- [Commits](https://github.com/blockworks-foundation/mango-client-v3/commits)

---
updated-dependencies:
- dependency-name: "@blockworks-foundation/mango-client"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Integration: Castle deposit and withdraw (#13)

* Add @castlefinance/vault-sdk dependency

* Add CastleDepositForm interface + Instructions.DepositIntoCastle to proposalCreationTypes

* Add Instructions.DepositIntoCastle to hooks/useGovernanceAssets.ts

* Add getCastleDepositInstruction to instructionTools.ts

* Add getCastleDepositSchema to utils/validations

* Add CastleDeposit component

* Add CastleDeposi to New Proposal component

* Fixed eslint errors

* execution option button

* Implement execution option

* fix - lint error

* Fix formatting divergence

* Revert formatting updates

* Undo formatting changes?

* Add deposit into tx without refresh

* Integrate updated sdk

* Add Castle Withdraw initial files

* Implement basic withdraw, deposit works on mainnet

* Temporarily remove git hooks

* Integrate vault-core

* Remove old config code from CastleWithdraw

* Grab amount from instruction data

* Remove unused param

* Fix duplicate cases

* Remove duplicate case

* temporarily disable husky

* Clean up

* Update ExecuteInstructionButton.tsx

* fix nft amount match (solana-labs#640)

* fix

* fix

* filter fix (solana-labs#641)

* Feature/release loader and council (solana-labs#643)

* release loader

* hide multi vote for nfts

* vote with council alone when plugin is on

* fix council

* release nfts addon

* Add Foresight DAO (solana-labs#642)

* add foresight-sdk dep

* add foresight to devnet.json

* fix programId

* add FORE mint to MINT_METADATA

* add example instruction to form

* remove comma

* add MakeInitMarketParams for Foresight

* husky did this

* lint

* more lin

* more foresight instructions

* lint

* tidy up provider

* lint

* add initCategory for foresight

* useGovernanceAssets

* missing import

* use DEVNET_TREASURY const

* add ForesightMakeResolveMarketParams

* finish adding resolve market

* avoid repeated constant

* missing resolve market in useGovernanceAssets

* clean up foresight instructions

* add AddMarketListToCategory

* add ForesightAddMarketListToCategory

* update foresight-sdk

* add AddMarketMetadata

* add ForesightGovernedAccountSelect

* start using ForesightGovernedAccountSelect

* reduce type duplication

* save unsaved file

* save unsaved file

* remove unused imports

* more refactoring to avoid duplication

* fix empty object type

* fix empty object type

* fix empty object type

* unused imports

* fix types import

* more refactoring

* unused import

* extract ForesightUseEffects

* unused import

* refactor more

* unused import

* refactor addmarketmetadataparams

* refactor init category

* refactor MakeInitMarketList

* big refactor

* lint

* more refactoring

* lint

* try using the user wallet as an authority

* change other stuff (except resolving markets) to user wallet

* missing param

* reorder element

* reorder elements

* update for newer foresight-sdk

* remove unused import

* fix issue with wrong program id

* bump foresight-sdk version

* npm: bump @blockworks-foundation/mango-client from 3.4.3 to 3.4.4 (#2)

Bumps [@blockworks-foundation/mango-client](https://github.com/blockworks-foundation/mango-client-v3) from 3.4.3 to 3.4.4.
- [Release notes](https://github.com/blockworks-foundation/mango-client-v3/releases)
- [Commits](https://github.com/blockworks-foundation/mango-client-v3/commits)

---
updated-dependencies:
- dependency-name: "@blockworks-foundation/mango-client"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @friktion-labs/friktion-sdk from 1.1.25 to 1.1.70 (#3)

Bumps [@friktion-labs/friktion-sdk](https://github.com/Friktion-Labs/volt) from 1.1.25 to 1.1.70.
- [Release notes](https://github.com/Friktion-Labs/volt/releases)
- [Commits](https://github.com/Friktion-Labs/volt/commits)

---
updated-dependencies:
- dependency-name: "@friktion-labs/friktion-sdk"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump tsconfig-paths from 3.12.0 to 3.14.1 (#5)

Bumps [tsconfig-paths](https://github.com/dividab/tsconfig-paths) from 3.12.0 to 3.14.1.
- [Release notes](https://github.com/dividab/tsconfig-paths/releases)
- [Changelog](https://github.com/dividab/tsconfig-paths/blob/master/CHANGELOG.md)
- [Commits](dividab/tsconfig-paths@v3.12.0...v3.14.1)

---
updated-dependencies:
- dependency-name: tsconfig-paths
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @solana/spl-token-registry from 0.2.3470 to 0.2.3635 (#6)

Bumps [@solana/spl-token-registry](https://github.com/solana-labs/token-list) from 0.2.3470 to 0.2.3635.
- [Release notes](https://github.com/solana-labs/token-list/releases)
- [Changelog](https://github.com/solana-labs/token-list/blob/main/CHANGELOG.md)
- [Commits](solana-labs/token-list@v0.2.3470...v0.2.3635)

---
updated-dependencies:
- dependency-name: "@solana/spl-token-registry"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump postcss from 8.4.4 to 8.4.12 (#10)

Bumps [postcss](https://github.com/postcss/postcss) from 8.4.4 to 8.4.12.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](postcss/postcss@8.4.4...8.4.12)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update lock file

* npm: bump @solana/spl-token from 0.1.8 to 0.2.0 (#7)

Bumps [@solana/spl-token](https://github.com/solana-labs/solana-program-library) from 0.1.8 to 0.2.0.
- [Release notes](https://github.com/solana-labs/solana-program-library/releases)
- [Commits](https://github.com/solana-labs/solana-program-library/compare/@solana/spl-token@v0.1.8...stake-pool-v0.2.0)

---
updated-dependencies:
- dependency-name: "@solana/spl-token"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump axios from 0.26.1 to 0.27.1 (#4)

Bumps [axios](https://github.com/axios/axios) from 0.26.1 to 0.27.1.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](axios/axios@v0.26.1...v0.27.1)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* switch to AssetAccount

* fix friktion-sdk version in line with main

* remove accidental package.json entries

* get rid of package.json deviations

* update lock file

* npm: bump next from 12.1.4 to 12.1.5 (#12)

Bumps [next](https://github.com/vercel/next.js) from 12.1.4 to 12.1.5.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v12.1.4...v12.1.5)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump react from 18.0.0 to 18.1.0 (#13)

Bumps [react](https://github.com/facebook/react/tree/HEAD/packages/react) from 18.0.0 to 18.1.0.
- [Release notes](https://github.com/facebook/react/releases)
- [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/react/commits/v18.1.0/packages/react)

---
updated-dependencies:
- dependency-name: react
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump ts-node from 10.5.0 to 10.7.0 (#14)

Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 10.5.0 to 10.7.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](TypeStrong/ts-node@v10.5.0...v10.7.0)

---
updated-dependencies:
- dependency-name: ts-node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @typescript-eslint/eslint-plugin from 5.19.0 to 5.21.0 (#16)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.19.0 to 5.21.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.21.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix friktion-sdk version in lock file

* add foresight to devnet.json

* move foresight utils to utils dir

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix type errors, updated packages

* auxliary token accounts (solana-labs#644)

* auxliary token accounts

* params page

* revert accounts from params page

* fixes

* fix

* fix auxiliary accounts display

* fix;

* Feature/anchor npm upgrade (solana-labs#646)

* anchor npm upgrade

* instructions change wip

* upgrade instructions to use new syntax anchor

* fix decode

* small my proposals fix

* fix vote records

* fix

* commit yarn lock

* Add NFTClubBerlin Multisig (solana-labs#648)

* Add trade with serum (solana-labs#583)

* setup framework for token actions
get proposal and TX simulation working as expected
add some more complex validations
remove unused vars
change verbage
remove form field for deposit address and use ATA
bump package version

* devs doin stuff

* clean up

* tweak trade on serum button

* use pre-requisite instruction to avoid TX limit

* add slight disclaimer and link to Serum remote

* fix nfts var

* fix double send button; restrict trade on serum to SPL tokens

* Fix logo path and update info (solana-labs#649)

* FIRST COMMINT LOGO AND INFO NFT OFF ROAD FAN CLUB DAO

* FIX LOGO AND INFO NFT OFF ROAD FAN CLUB DAO

* 'Token' on About tab should show mint rather than realm pubkey (solana-labs#651)

* Token should show mint rather than realm pubkey

* Only show token symbol if realm is certified

* transaction timeouts based on blocks (solana-labs#653)

* send transction v2 player

* timeout based on block height

* forward function + comments

* fix

* reject all on timeout

* pull vaults from api, render execution option based on program parsing

* Fix CI issue

* Use castle dependency for anchor

* Fix type errors

Co-authored-by: Alexander Schwartzberg <aeksco@gmail.com>
Co-authored-by: Adrian Brzeziński <a.brzezinski94@gmail.com>
Co-authored-by: Kevin Heavey <24635973+kevinheavey@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Chris Nagy <20590073+what-name@users.noreply.github.com>
Co-authored-by: Tommy Johnson <32071703+tomjohn1028@users.noreply.github.com>
Co-authored-by: Xavier Baquero <93201271+axbaquero@users.noreply.github.com>
Co-authored-by: Evan Doyle <evanmdoyle@gmail.com>

* Update yarn.lock

* Add back husky

* sleep-gap send, remove dead code, use getters

* Use try/catch for ATA creation

* Rename execution option buttons

* Update instructionTools.ts

* Implement generic execution options

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alexander Schwartzberg <aeksco@gmail.com>
Co-authored-by: Adrian Brzeziński <a.brzezinski94@gmail.com>
Co-authored-by: Kevin Heavey <24635973+kevinheavey@users.noreply.github.com>
Co-authored-by: Chris Nagy <20590073+what-name@users.noreply.github.com>
Co-authored-by: Tommy Johnson <32071703+tomjohn1028@users.noreply.github.com>
Co-authored-by: Xavier Baquero <93201271+axbaquero@users.noreply.github.com>
Co-authored-by: Evan Doyle <evanmdoyle@gmail.com>
  • Loading branch information
9 people committed May 12, 2022
1 parent be7976f commit cb3a4ed
Show file tree
Hide file tree
Showing 18 changed files with 1,715 additions and 257 deletions.
3 changes: 2 additions & 1 deletion @types/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EndpointTypes } from '@models/types'
import type { AccountInfo, PublicKey } from '@solana/web3.js'

export interface EndpointInfo {
name: string
name: EndpointTypes
url: string
}

Expand Down
84 changes: 67 additions & 17 deletions actions/executeTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { Keypair, Transaction, TransactionInstruction } from '@solana/web3.js'

import {
getGovernanceProgramVersion,
sendSignedAndAdjacentTransactions,
sendTransaction,
signTransactions,
} from '@utils/send'
import Wallet from '@project-serum/sol-wallet-adapter'
import {
RpcContext,
Proposal,
ProposalTransaction,
getGovernanceProgramVersion,
withExecuteTransaction,
ProgramAccount,
} from '@solana/spl-governance'

import { withExecuteTransaction } from '@solana/spl-governance'
import { RpcContext } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import { sendTransaction } from '@utils/send'

/**
* Executes a proposal transaction
* @param rpcContext RPC contextual information
* @param proposal Metadata about the proposal
* @param instruction Instruction that will be executed by the proposal
* @param adjacentTransaction Optional transaction that is sent in the same slot as the proposal instruction.
* @param preExecutionTransactions Optional tansactions that are executed before the proposal instruction
*/
export const executeTransaction = async (
{ connection, wallet, programId }: RpcContext,
proposal: ProgramAccount<Proposal>,
instruction: ProgramAccount<ProposalTransaction>
instruction: ProgramAccount<ProposalTransaction>,
adjacentTransaction?: Transaction,
preExecutionTransactions?: Transaction[]
) => {
const signers: Keypair[] = []
const instructions: TransactionInstruction[] = []
Expand All @@ -36,16 +50,52 @@ export const executeTransaction = async (
[instruction.account.getSingleInstruction()]
)

const transaction = new Transaction()
// Create proposal transaction
const proposalTransaction = new Transaction().add(...instructions)

transaction.add(...instructions)
// Sign and send all pre-execution transactions
if (preExecutionTransactions && !preExecutionTransactions?.length) {
await Promise.all(
preExecutionTransactions.map((transaction) =>
sendTransaction({
transaction,
wallet,
connection,
sendingMessage: 'Sending pre-execution transaction',
successMessage: 'Sent pre-execution transaction',
})
)
)
console.log('sent preExecutionTransactions', preExecutionTransactions)
}

await sendTransaction({
transaction,
wallet,
connection,
signers,
sendingMessage: 'Executing instruction',
successMessage: 'Execution finalized',
})
// Some proposals require additional adjacent transactions due to tx size limits
if (adjacentTransaction) {
const [signedProposalTx, signedAdjacentTx] = await signTransactions({
transactionsAndSigners: [
{ transaction: proposalTransaction },
{ transaction: adjacentTransaction },
],
wallet: (wallet as unknown) as Wallet,
connection,
})
// Send proposal transaction with prepended adjacent transaction
await sendSignedAndAdjacentTransactions({
signedTransaction: signedProposalTx,
adjacentTransaction: signedAdjacentTx,
connection,
sendingMessage: 'Executing instruction',
successMessage: 'Execution finalized',
})
} else {
// Send the proposal transaction
await sendTransaction({
transaction: proposalTransaction,
wallet,
connection,
signers,
sendingMessage: 'Executing instruction',
successMessage: 'Execution finalized',
})
}
}
78 changes: 78 additions & 0 deletions components/InstructionOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Fragment } from 'react'
import { Listbox, Transition } from '@headlessui/react'
import { SelectorIcon } from '@heroicons/react/solid'

// Add more options as needed
export enum InstructionOptions {
none = 'none',
castleRefresh = 'Castle: Refresh',
castleReconcileRefresh = 'Castle: Reconcile and Refresh',
}

export type InstructionOption = `${InstructionOptions}`

// Mapping between listbox option label and underlying option
const executionOptions: { label: string; value: InstructionOption }[] = [
{ label: 'Select Option', value: InstructionOptions.none },
{ label: 'Castle: Deposit', value: InstructionOptions.castleRefresh },
{
label: 'Castle: Withdraw',
value: InstructionOptions.castleReconcileRefresh,
},
]

export default function InstructionOptionInput(props: {
value: InstructionOption
setValue: (updatedValue: InstructionOption) => void
}) {
const { value, setValue } = props

const selectedOption = executionOptions.find((o) => o.value === value)

return (
<Listbox value={value} onChange={setValue}>
<div className="relative">
<Listbox.Button className="relative py-1 text-left border border-primary-light default-transition font-bold rounded-full px-4 text-primary-light text-sm hover:border-primary-dark hover:text-primary-dark">
<span className="block truncate mr-3">{selectedOption?.label}</span>
<span className="absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none">
<SelectorIcon className="w-5 h-5 text-primary-light" />
</span>
</Listbox.Button>
<Transition
as={Fragment}
leave="transition ease-in duration-100"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Listbox.Options className="absolute text-sm bg-bkg-1 border border-gray-50 py-1 mt-1 overflow-auto text-primary-dark rounded-md shadow-lg max-h-60">
{executionOptions.map((option, optionIdx) => (
<Listbox.Option
key={optionIdx}
className={({ active }) =>
`cursor-default select-none relative py-2 px-4 ${
active
? 'text-amber-900 bg-amber-100'
: 'text-primary-light'
}`
}
value={option.value}
>
{({ selected }) => (
<>
<span
className={`block truncate ${
selected ? 'font-medium' : 'font-normal'
}`}
>
{option.label}
</span>
</>
)}
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</div>
</Listbox>
)
}
54 changes: 52 additions & 2 deletions components/instructions/ExecuteInstructionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ import { RpcContext } from '@solana/spl-governance'
import useRealm from '@hooks/useRealm'
import useWalletStore from 'stores/useWalletStore'
import { ProgramAccount } from '@solana/spl-governance'
import { PublicKey } from '@solana/web3.js'
import { PublicKey, Transaction } from '@solana/web3.js'
import Tooltip from '@components/Tooltip'
import { getProgramVersionForRealm } from '@models/registry/api'
import { notify } from '@utils/notifications'
import {
InstructionOption,
InstructionOptions,
} from '@components/InstructionOptions'
import dayjs from 'dayjs'
import {
getFormattedStringFromDays,
SECS_PER_DAY,
} from 'VoteStakeRegistry/tools/dateTools'
import {
getCastleReconcileInstruction,
getCastleRefreshInstruction,
} from '@utils/instructions/Castle'
import Wallet from '@project-serum/sol-wallet-adapter'

export enum PlayState {
Played,
Expand All @@ -35,11 +44,13 @@ export function ExecuteInstructionButton({
playing,
setPlaying,
proposalInstruction,
instructionOption,
}: {
proposal: ProgramAccount<Proposal>
proposalInstruction: ProgramAccount<ProposalTransaction>
playing: PlayState
setPlaying: React.Dispatch<React.SetStateAction<PlayState>>
instructionOption: InstructionOption
}) {
const { realmInfo } = useRealm()
const wallet = useWalletStore((s) => s.current)
Expand Down Expand Up @@ -79,7 +90,46 @@ export function ExecuteInstructionButton({
setPlaying(PlayState.Playing)

try {
await executeTransaction(rpcContext, proposal, proposalInstruction)
let preExecutionTransactions: Transaction[] | undefined = undefined
let adjacentTransaction: Transaction | undefined = undefined

// Depending on the instruction option, add the appropriate pre-execution
// and adjacent transactions to the proposal execution
switch (instructionOption) {
case InstructionOptions.castleRefresh:
adjacentTransaction = new Transaction().add(
await getCastleRefreshInstruction(
rpcContext.connection,
(wallet as unknown) as Wallet,
proposalInstruction
)
)
break
case InstructionOptions.castleReconcileRefresh: {
preExecutionTransactions = await getCastleReconcileInstruction(
rpcContext.connection,
(wallet as unknown) as Wallet,
proposalInstruction
)
adjacentTransaction = new Transaction().add(
await getCastleRefreshInstruction(
rpcContext.connection,
(wallet as unknown) as Wallet,
proposalInstruction
)
)
break
}
}

await executeTransaction(
rpcContext,
proposal,
proposalInstruction,
adjacentTransaction,
preExecutionTransactions
)

await refetchProposals()
} catch (error) {
notify({ type: 'error', message: `error executing instruction ${error}` })
Expand Down
40 changes: 34 additions & 6 deletions components/instructions/instructionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ProposalTransaction,
} from '@solana/spl-governance'
import {
ALL_CASTLE_PROGRAMS,
getAccountName,
getInstructionDescriptor,
InstructionDescriptor,
Expand All @@ -24,6 +25,10 @@ import { Metadata } from '@metaplex-foundation/mpl-token-metadata'
import axios from 'axios'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import tokenService from '@utils/services/token'
import InstructionOptionInput, {
InstructionOption,
InstructionOptions,
} from '@components/InstructionOptions'

export default function InstructionCard({
index,
Expand All @@ -41,13 +46,22 @@ export default function InstructionCard({
const connection = useWalletStore((s) => s.connection)
const tokenRecords = useWalletStore((s) => s.selectedRealm)
const [descriptor, setDescriptor] = useState<InstructionDescriptor>()
const [instructionOption, setInstructionOption] = useState<InstructionOption>(
InstructionOptions.none
)

const [playing, setPlaying] = useState(
proposalInstruction.account.executedAt
? PlayState.Played
: PlayState.Unplayed
)
const [nftImgUrl, setNftImgUrl] = useState('')
const [tokenImgUrl, setTokenImgUrl] = useState('')

const allProposalPrograms = proposalInstruction.account.instructions
?.map((i) => i.programId.toBase58())
.flat()

useEffect(() => {
getInstructionDescriptor(
connection,
Expand Down Expand Up @@ -165,12 +179,26 @@ export default function InstructionCard({
/>

{proposal && (
<ExecuteInstructionButton
proposal={proposal}
proposalInstruction={proposalInstruction}
playing={playing}
setPlaying={setPlaying}
/>
<React.Fragment>
<ExecuteInstructionButton
proposal={proposal}
proposalInstruction={proposalInstruction}
playing={playing}
setPlaying={setPlaying}
instructionOption={instructionOption}
/>
{/* Show execution option if the proposal contains a specified program id and
proposal has not executed already. */}
{allProposalPrograms?.filter((a) =>
ALL_CASTLE_PROGRAMS.map((a) => a.toBase58()).includes(a)
).length > 0 &&
playing != PlayState.Played && (
<InstructionOptionInput
value={instructionOption}
setValue={setInstructionOption}
/>
)}
</React.Fragment>
)}
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions components/instructions/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ATA_PROGRAM_INSTRUCTIONS } from './programs/associatedTokenAccount'
import { governance as foresightGov } from '@foresight-tmp/foresight-sdk'
import { ConnectionContext } from '@utils/connection'
import { NFT_VOTER_INSTRUCTIONS } from './programs/nftVotingClient'
import { PROGRAM_IDS } from '@castlefinance/vault-sdk'
/**
* Default governance program id instance
*/
Expand Down Expand Up @@ -199,6 +200,12 @@ export const AUXILIARY_TOKEN_ACCOUNTS = {

export const HIDDEN_TREASURES = [...HIDDEN_MNGO_TREASURES]

export const ALL_CASTLE_PROGRAMS = [
PROGRAM_IDS['devnet-parity'],
PROGRAM_IDS['devnet-staging'],
PROGRAM_IDS['mainnet'],
]

export interface AccountDescriptor {
name: string
important?: boolean
Expand Down
10 changes: 10 additions & 0 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export default function useGovernanceAssets() {
name: 'Execute Custom Instruction',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.DepositIntoCastle,
name: 'Castle: Deposit into Vault',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.WithrawFromCastle,
name: 'Castle: Withdraw from Vault',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.DepositIntoVolt,
name: 'Friktion: Deposit into Volt',
Expand Down

0 comments on commit cb3a4ed

Please sign in to comment.