Skip to content

Commit

Permalink
Merge pull request #1 from AdrenaFoundation/adrena-instructions
Browse files Browse the repository at this point in the history
Adrena instructions first batch
  • Loading branch information
adrena-orex authored Sep 13, 2024
2 parents 30e8545 + 9726058 commit cb1253a
Show file tree
Hide file tree
Showing 22 changed files with 38,679 additions and 1 deletion.
119 changes: 119 additions & 0 deletions components/instructions/programs/adrena.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Connection } from '@solana/web3.js'

const INSTRUCTIONS = {
100: {
name: 'Add Vest',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
101: {
name: 'Mint Lm Tokens From Bucket',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
102: {
name: 'Set Custody Allow Swap',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
103: {
name: 'Set Custody Allow Trade',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
104: {
name: 'Set Custody Max Cumulative Short Size USD',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
105: {
name: 'Set Pool Allow Swap',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
106: {
name: 'Set Pool Allow Trade',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
107: {
name: 'Set Pool Aum Soft Cap USD',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
108: {
name: 'Set Pool Liquidity State',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
109: {
name: 'Set Staking Lm Emission Potentiometers',
accounts: [],
getDataUI: async (_connection: Connection, data: Uint8Array) => {
return (
<>
<div>{JSON.stringify(data)}</div>
</>
)
},
},
}

export const ADRENA_INSTRUCTIONS = {
// TODO: Replace with the correct program id
SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f: INSTRUCTIONS,
}
32 changes: 32 additions & 0 deletions hooks/useAdrenaClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from 'react'
import { PublicKey } from '@solana/web3.js'

import { useConnection } from '@solana/wallet-adapter-react'
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
import useWalletOnePointOh from './useWalletOnePointOh'
import AdrenaClient from '@tools/sdk/adrena/Adrena'

export default function useAdrenaClient(
programId: PublicKey | null
): AdrenaClient | null {
const { connection } = useConnection()
const wallet = useWalletOnePointOh()
const [adrenaClient, setAdrenaClient] = useState<AdrenaClient | null>(null)

useEffect(() => {
if (!programId) return setAdrenaClient(null)

setAdrenaClient(
new AdrenaClient(
// The wallet type is compatible with the anchor provider, force typing
new AnchorProvider(connection, (wallet as unknown) as Wallet, {
commitment: 'processed',
skipPreflight: true,
}),
programId
)
)
}, [connection, wallet, programId])

return adrenaClient
}
23 changes: 23 additions & 0 deletions hooks/useAdrenaCustodies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useState } from 'react'

import AdrenaClient, {
CustodyWithPubkey,
PoolWithPubkey,
} from '@tools/sdk/adrena/Adrena'

export default function useAdrenaCustodies(
adrenaClient: AdrenaClient | null,
pool: PoolWithPubkey | null
) {
const [custodies, setCustodies] = useState<CustodyWithPubkey[] | null>(null)

useEffect(() => {
;(async () => {
if (adrenaClient === null || pool === null) return setCustodies(null)

setCustodies(await adrenaClient.getCustodies(pool))
})()
}, [adrenaClient, pool])

return custodies
}
17 changes: 17 additions & 0 deletions hooks/useAdrenaPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react'

import AdrenaClient, { PoolWithPubkey } from '@tools/sdk/adrena/Adrena'

export default function useAdrenaPools(adrenaClient: AdrenaClient | null) {
const [pools, setPools] = useState<PoolWithPubkey[] | null>(null)

useEffect(() => {
;(async () => {
if (!adrenaClient) return setPools(null)

setPools(await adrenaClient.getPools())
})()
}, [adrenaClient])

return pools
}
17 changes: 17 additions & 0 deletions hooks/useAdrenaStakings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react'

import AdrenaClient, { StakingWithPubkey } from '@tools/sdk/adrena/Adrena'

export default function useAdrenaStakings(adrenaClient: AdrenaClient | null) {
const [stakings, setStakings] = useState<StakingWithPubkey[] | null>(null)

useEffect(() => {
;(async () => {
if (!adrenaClient) return setStakings(null)

setStakings(await adrenaClient.getStakings())
})()
}, [adrenaClient])

return stakings
}
52 changes: 52 additions & 0 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default function useGovernanceAssets() {
//
// Packages are visible by default
const packages: Packages = {
[PackageEnum.Adrena]: {
name: 'Adrena',
image: '/img/adrena.svg',
},
[PackageEnum.Common]: {
name: 'Common',
},
Expand Down Expand Up @@ -217,6 +221,54 @@ export default function useGovernanceAssets() {
//
// If isVisible is not set, it is equal to canUseAnyInstruction
const instructionsMap: InstructionsMap = {
/*
█████ ██████ ██████ ███████ ███ ██ █████
██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
███████ ██ ██ ██████ █████ ██ ██ ██ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██ ██ ███████ ██ ████ ██ ██
*/
[Instructions.AdrenaAddVest]: {
name: 'Add Vest',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaMintLmTokensFromBucket]: {
name: 'Mint LM Tokens from Bucket',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetCustodyAllowSwap]: {
name: 'Set Custody Allow Swap',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetCustodyAllowTrade]: {
name: 'Set Custody Allow Trade',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetCustodyMaxCumulativeShortSizeUsd]: {
name: 'Set Custody Max Cumulative Short Size Usd',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetPoolAllowSwap]: {
name: 'Set Pool Allow Swap',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetPoolAllowTrade]: {
name: 'Set Pool Allow Trade',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetPoolAumSoftCapUsd]: {
name: 'Set Pool Aum Soft Cap Usd',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetPoolLiquidityState]: {
name: 'Set Pool Liquidity State',
packageId: PackageEnum.Adrena,
},
[Instructions.AdrenaSetStakingLmEmissionPotentiometers]: {
name: 'Set Staking LM Emission Potentiometers',
packageId: PackageEnum.Adrena,
},

/*
██████ ██████ ███ ███ ███ ███ ██████ ███ ██
██ ██ ██ ████ ████ ████ ████ ██ ██ ████ ██
Expand Down
Loading

0 comments on commit cb1253a

Please sign in to comment.