Skip to content

Commit

Permalink
Add Foresight DAO (#642)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kevinheavey and dependabot[bot] committed Apr 29, 2022
1 parent 646e4f9 commit c53b586
Show file tree
Hide file tree
Showing 16 changed files with 1,722 additions and 856 deletions.
2 changes: 2 additions & 0 deletions Strategies/protocols/foresight/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FORESIGHT_MINT_DEVNET =
'H7uqouPsJkeEiLpCEoC1qYVVquDrZan6ZfdPK2gS44zm'
1 change: 1 addition & 0 deletions components/instructions/programs/splToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const MINT_METADATA = {
SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt: { name: 'SRM' },
MyHd6a7HWKTMeJMHBkrbMq4hZwZxwn9x7dxXcopQ4Wd: { name: 'OMH' },
UXPhBoR3qG4UCiGNJfV7MqhHyFqKN68g45GoYvAeL2M: { name: 'UXP' },
H7uqouPsJkeEiLpCEoC1qYVVquDrZan6ZfdPK2gS44zm: { name: 'FORE' },
}

export function getMintMetadata(
Expand Down
3 changes: 3 additions & 0 deletions components/instructions/tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { VOTE_STAKE_REGISTRY_INSTRUCTIONS } from './programs/voteStakeRegistry'
import { MARINADE_INSTRUCTIONS } from './programs/marinade'
import { SOLEND_PROGRAM_INSTRUCTIONS } from './programs/solend'
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'
/**
Expand Down Expand Up @@ -62,6 +63,8 @@ export const ACCOUNT_NAMES = {
'Mango v3 BTC-PERP Incentive Vault',
'7Gm5zF6FNJpyhqdwKcEdMQw3r5YzitYUGVDKYMPT1cMy': 'Mango V3 Admin Key',
MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac: 'MNGO Token Mint',
H7uqouPsJkeEiLpCEoC1qYVVquDrZan6ZfdPK2gS44zm: 'FORE Token Mint',
[foresightGov.DEVNET_TREASURY.toBase58()]: 'Foresight Devnet Governance',
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: 'USDC Token Mint',

MyHd6a7HWKTMeJMHBkrbMq4hZwZxwn9x7dxXcopQ4Wd: 'OMH Token',
Expand Down
30 changes: 30 additions & 0 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,36 @@ export default function useGovernanceAssets() {
name: 'Solend: Withdraw Funds',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightInitMarket,
name: 'Foresight: Init Market',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightInitMarketList,
name: 'Foresight: Init Market List',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightInitCategory,
name: 'Foresight: Init Category',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightResolveMarket,
name: 'Foresight: Resolve Market',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightAddMarketListToCategory,
name: 'Foresight: Add Market List To Category',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ForesightAddMarketMetadata,
name: 'Foresight: Add Market Metadata',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.ProgramUpgrade,
name: 'Upgrade Program',
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@cardinal/namespaces-components": "^2.5.5",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@foresight-tmp/foresight-sdk": "^0.1.38",
"@friktion-labs/friktion-sdk": "^1.1.25",
"@headlessui/react": "^1.5.0",
"@heroicons/react": "^1.0.1",
Expand Down Expand Up @@ -58,20 +59,20 @@
"classnames": "^2.3.1",
"dayjs": "^1.10.7",
"immer": "^9.0.12",
"next": "^12.1.4",
"next": "^12.1.5",
"next-themes": "^0.1.1",
"next-transpile-modules": "^8.0.0",
"node-fetch": "^2.6.1",
"rc-slider": "^9.7.5",
"react": "^18.0.0",
"react": "^18.1.0",
"react-dom": "^18.0.0",
"react-headless-pagination": "^0.1.0",
"react-markdown": "^7.0.0",
"react-portal": "^4.2.2",
"remark-gfm": "^3.0.1",
"superstruct": "^0.15.4",
"ts-node": "^10.5.0",
"tsconfig-paths": "^3.12.0",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.1",
"yup": "^0.32.11",
"zustand": "^3.7.2"
},
Expand All @@ -82,7 +83,7 @@
"@types/jest": "^27.4.1",
"@types/node": "^14.14.25",
"@types/react": "^17.0.44",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.18.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { ForesightMakeAddMarketListToCategoryParams } from '@utils/uiTypes/proposalCreationTypes'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import {
governance as foresightGov,
consts,
} from '@foresight-tmp/foresight-sdk'
import {
commonAssets,
ForesightCategoryIdInput,
ForesightMarketListIdInput,
} from '@utils/Foresight'
import { PublicKey } from '@solana/web3.js'

function MakeAddMarketListToCategoryParams({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) {
const {
inputProps,
effector,
governedAccountSelect,
wallet,
} = commonAssets<ForesightMakeAddMarketListToCategoryParams>(
{ categoryId: '', marketListId: '' },
index,
governance
)
async function ixCreator(form: ForesightMakeAddMarketListToCategoryParams) {
const { ix } = await foresightGov.genAddMarketListToCategoryIx(
Buffer.from(form.categoryId.padEnd(20)),
Buffer.from(form.marketListId.padEnd(20)),
new PublicKey(consts.DEVNET_PID),
wallet!.publicKey!
)
return ix
}
effector(ixCreator)

return (
<>
{governedAccountSelect}
<ForesightCategoryIdInput {...inputProps} />
<ForesightMarketListIdInput {...inputProps} />
</>
)
}

export default MakeAddMarketListToCategoryParams
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { ForesightMakeAddMarketMetadataParams } from '@utils/uiTypes/proposalCreationTypes'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import {
governance as foresightGov,
consts as foresightConsts,
utils,
consts,
} from '@foresight-tmp/foresight-sdk'
import {
commonAssets,
ForesightContentInput,
ForesightMarketIdInput,
ForesightMarketListIdInput,
ForesightMarketMetadataFieldSelect,
} from '@utils/Foresight'
import { PublicKey } from '@solana/web3.js'

export default function MakeAddMarketMetadataParams({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) {
const {
inputProps,
effector,
governedAccountSelect,
wallet,
} = commonAssets<ForesightMakeAddMarketMetadataParams>(
{
marketListId: '',
marketId: 0,
content: '',
field: Object.keys(
foresightConsts.MARKET_METADATA_FIELDS
)[0] as foresightConsts.MarketMetadataFieldName,
},
index,
governance
)
async function ixCreator(form: ForesightMakeAddMarketMetadataParams) {
const field = foresightConsts.MARKET_METADATA_FIELDS[form.field]
const { ix } = await foresightGov.genWriteToFieldMarketMetadataIx(
utils.intToArray(form.marketId, 1),
Buffer.from(form.marketListId.padEnd(20)),
form.content,
new field(),
new PublicKey(consts.DEVNET_PID),
wallet!.publicKey!
)
return ix
}
effector(ixCreator)
return (
<>
{governedAccountSelect}
<ForesightMarketListIdInput {...inputProps} />
<ForesightMarketIdInput {...inputProps} />
<ForesightContentInput {...inputProps} />
<ForesightMarketMetadataFieldSelect {...inputProps} />
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { ForesightHasCategoryId } from '@utils/uiTypes/proposalCreationTypes'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import {
governance as foresightGov,
consts as foresightConsts,
} from '@foresight-tmp/foresight-sdk'
import { commonAssets, ForesightCategoryIdInput } from '@utils/Foresight'
import { PublicKey } from '@solana/web3.js'

const MakeInitCategoryParams = ({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) => {
const {
inputProps,
effector,
governedAccountSelect,
wallet,
} = commonAssets<ForesightHasCategoryId>(
{ categoryId: '' },
index,
governance
)
async function ixCreator(form: ForesightHasCategoryId) {
const { ix } = await foresightGov.genInitCategoryIx(
Buffer.from(form.categoryId.padEnd(20)),
new PublicKey(foresightConsts.DEVNET_PID),
wallet!.publicKey!
)
return ix
}
effector(ixCreator)
return (
<>
{governedAccountSelect}
<ForesightCategoryIdInput {...inputProps} />
</>
)
}

export default MakeInitCategoryParams
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { ForesightHasMarketListId } from '@utils/uiTypes/proposalCreationTypes'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import {
governance as foresightGov,
consts,
} from '@foresight-tmp/foresight-sdk'
import { commonAssets, ForesightMarketListIdInput } from '@utils/Foresight'
import { PublicKey } from '@solana/web3.js'

const MakeInitMarketListParams = ({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) => {
const {
inputProps,
effector,
governedAccountSelect,
wallet,
} = commonAssets<ForesightHasMarketListId>(
{ marketListId: '' },
index,
governance
)
async function ixCreator(form: ForesightHasMarketListId) {
const { ix } = await foresightGov.genInitMarketListIx(
Buffer.from(form.marketListId.padEnd(20)),
new PublicKey(consts.DEVNET_PID),
wallet!.publicKey!,
form.governedAccount.extensions.transferAddress!
)
return ix
}
effector(ixCreator)

return (
<>
{governedAccountSelect}
<ForesightMarketListIdInput {...inputProps} />
</>
)
}

export default MakeInitMarketListParams
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { ForesightHasMarketId } from '@utils/uiTypes/proposalCreationTypes'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import {
governance as foresightGov,
utils,
consts,
} from '@foresight-tmp/foresight-sdk'
import {
commonAssets,
ForesightMarketIdInput,
ForesightMarketListIdInput,
} from '@utils/Foresight'
import { PublicKey } from '@solana/web3.js'

const MakeInitMarketParams = ({
index,
governance,
}: {
index: number
governance: ProgramAccount<Governance> | null
}) => {
const {
inputProps,
effector,
governedAccountSelect,
wallet,
} = commonAssets<ForesightHasMarketId>(
{ marketListId: '', marketId: 0 },
index,
governance
)
async function ixCreator(form: ForesightHasMarketId) {
const { ix } = await foresightGov.genInitMarketIx(
Buffer.from(form.marketListId.padEnd(20)),
utils.intToArray(form.marketId, 1),
new PublicKey(consts.DEVNET_PID),
wallet!.publicKey!
)
return ix
}
effector(ixCreator)

return (
<>
{governedAccountSelect}
<ForesightMarketListIdInput {...inputProps} />
<ForesightMarketIdInput {...inputProps} />
</>
)
}

export default MakeInitMarketParams
Loading

1 comment on commit c53b586

@vercel
Copy link

@vercel vercel bot commented on c53b586 Apr 29, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.