Skip to content

Commit

Permalink
Merge branch 'main' into ois-constitution
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Sep 13, 2024
2 parents 62f5ac3 + 54ef7b6 commit 4d7d58b
Show file tree
Hide file tree
Showing 127 changed files with 28,932 additions and 43,608 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/anchor-idl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Anchor IDL CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18.19.1"
- name: Npm install
run: npm ci
- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.18.16/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Install Anchor
working-directory: ./staking
run: npm i -g @coral-xyz/anchor-cli@0.30.1
- name: Build IDL
working-directory: ./staking
run: anchor build
- name: Check commited idl is up to date
working-directory: ./staking
run: git diff -G".*" --exit-code target/*
13 changes: 5 additions & 8 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.18.16/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Install Anchor
working-directory: ./staking
run: npm i -g @coral-xyz/anchor-cli@0.30.1
- name: Anchor tests
- name: Install Solana Verify CLI
run: |
cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 098551f
- name: Javascript tests
working-directory: ./staking
run: npm run test:ci
# Remove debug folder to avoid hitting space limit in ci
Expand All @@ -35,7 +35,4 @@ jobs:
# Anchor test will build the program, so we can run the tests here
- name: Cargo tests
working-directory: ./staking
run: RUST_MIN_STACK=10485760 cargo test
- name: Check commited idl is up to date
working-directory: ./staking
run: git diff -G".*" --exit-code target/*
run: RUST_MIN_STACK=33554432 cargo test
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18.19.1"
- name: Install Solana Verify CLI
run: |
cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 098551f
- name: Build
working-directory: ./staking
run: solana-verify build
- name: Publish program binaries
uses: svenstaro/upload-release-action@133984371c30d34e38222a64855679a414cb7575
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./staking/target/deploy/*.so
tag: ${{ github.ref }}
file_glob: true
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: end-of-file-fixer
exclude: staking/target
- id: check-added-large-files
exclude: package-lock.json
exclude: package-lock.json|staking/tests/programs
# Hook to format many type of files in the repo
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
Expand Down
38 changes: 35 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
{
"terminal.integrated.env.osx": {
"RUST_MIN_STACK": "10485760"
// 32MB
"RUST_MIN_STACK": "33554432"
},
"terminal.integrated.env.linux": {
"RUST_MIN_STACK": "10485760"
// 32MB
"RUST_MIN_STACK": "33554432"
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.rustfmt.overrideCommand": ["rustfmt", "+nightly"]
"rust-analyzer.rustfmt.overrideCommand": ["rustfmt", "+nightly"],
"cSpell.words": [
"accs",
"blockhash",
"borsh",
"bytemuck",
"delegators",
"funder",
"Keypair",
"keypairs",
"lamports",
"litesvm",
"Merkle",
"Metas",
"PREUNLOCKING",
"Pubkey",
"pubkeys",
"pyth",
"pythnet",
"quickcheck",
"reqwest",
"shellexpand",
"snapshotted",
"solana",
"sysvar",
"Undelegate",
"undelegated",
"UNDELEGATION",
"vaas",
"Zeroable"
]
}
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 41 additions & 18 deletions frontend/pages/approve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NextPage } from 'next'
import Layout from '../components/Layout'
import SEO from '../components/SEO'
import { useAnchorWallet } from '@solana/wallet-adapter-react'
import { StakeAccount } from '@pythnetwork/staking'
import { StakeAccount, StakeConnection } from '@pythnetwork/staking'
import { useEffect, useState } from 'react'
import { PublicKey } from '@solana/web3.js'
import { useRouter } from 'next/router'
Expand All @@ -11,10 +11,32 @@ import { capitalizeFirstLetter } from 'utils/capitalizeFirstLetter'
import { useStakeConnection } from 'hooks/useStakeConnection'
import { useSplitRequest } from 'hooks/useSplitRequest'

export async function getStakeAccountsPubkeys(user: PublicKey, stakeConnection : StakeConnection){
const program = stakeConnection.program;
const res = await stakeConnection.program.provider.connection.getProgramAccounts(
program.programId,
{
encoding: "base64",
filters: [
{
memcmp: program.coder.accounts.memcmp("positionData"),
},
{
memcmp: {
offset: 8,
bytes: user.toBase58(),
},
},
],
}
);

return res.map((account) => new PublicKey(account.pubkey));
}
const ApproveSplit: NextPage = () => {
const anchorWallet = useAnchorWallet()

const [stakeAccounts, setStakeAccounts] = useState<StakeAccount[]>()
const [stakeAccounts, setStakeAccounts] = useState<PublicKey[]>()
const [selectedStakeAccount, setSelectStakeAccount] = useState<StakeAccount>()

const { data: splitRequest } = useSplitRequest(selectedStakeAccount)
Expand All @@ -38,33 +60,34 @@ const ApproveSplit: NextPage = () => {
}, [splitRequest])

const handleSelectStakeAccount = (event: any) => {
for (const stakeAccount of stakeAccounts!) {
if (stakeAccount.address.toString() === event.target.value) {
setSelectStakeAccount(stakeAccount)
break
}
const loadStakeAccount = async () => {
if (stakeAccounts && stakeConnection){
const stakeAccount = stakeAccounts.find(s => s.toString() === event.target.value)
if (stakeAccount) {
setSelectStakeAccount(await stakeConnection.loadStakeAccount(stakeAccount))
}
}
}
loadStakeAccount()
}

useEffect(() => {
const loadStakeAccounts = async () => {
if (stakeConnection && anchorWallet) {
const stakeAccounts = await stakeConnection.getStakeAccounts(
new PublicKey(owner!)
)
if (stakeConnection && anchorWallet && owner) {
const stakeAccounts = await getStakeAccountsPubkeys(new PublicKey(owner), stakeConnection)
setStakeAccounts(stakeAccounts)
if (stakeAccounts.length > 0){
setSelectStakeAccount(await stakeConnection.loadStakeAccount(stakeAccounts[0]))
} else {
setSelectStakeAccount(undefined)
}
} else {
setStakeAccounts(undefined)
}
}
loadStakeAccounts()
}, [stakeConnection])

useEffect(() => {
if (stakeAccounts && stakeAccounts.length > 0)
setSelectStakeAccount(stakeAccounts[0])
}, [stakeAccounts])

const approveSplit = async () => {
if (stakeConnection && selectedStakeAccount && splitRequest) {
try {
Expand Down Expand Up @@ -95,8 +118,8 @@ const ApproveSplit: NextPage = () => {
onChange={handleSelectStakeAccount}
>
{stakeAccounts.map((option, index) => (
<option key={index} value={option.address.toBase58()}>
{option.address.toString()}
<option key={index} value={option.toBase58()}>
{option.toString()}
</option>
))}
</select>
Expand Down
41 changes: 28 additions & 13 deletions frontend/pages/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { PublicKey } from '@solana/web3.js'
import toast from 'react-hot-toast'
import { capitalizeFirstLetter } from 'utils/capitalizeFirstLetter'
import { useStakeConnection } from 'hooks/useStakeConnection'
import { useStakeAccounts } from 'hooks/useStakeAccounts'
import { useSplitRequest } from 'hooks/useSplitRequest'
import { getStakeAccountsPubkeys } from './approve'

const RequestSplit: NextPage = () => {
const [recipient, setRecipient] = useState<PublicKey>()
Expand All @@ -30,7 +30,7 @@ const RequestSplit: NextPage = () => {
}

const { data: stakeConnection } = useStakeConnection()
const { data: stakeAccounts } = useStakeAccounts()
const [stakeAccounts, setStakeAccounts] = useState<PublicKey[]>()
const [selectedStakeAccount, setSelectStakeAccount] = useState<StakeAccount>()
const { data: initialSplitRequest } = useSplitRequest(selectedStakeAccount)

Expand All @@ -46,13 +46,33 @@ const RequestSplit: NextPage = () => {
loadWalletHasTested()
}, [recipient])

useEffect(() => {
const loadStakeAccounts = async () => {
if (stakeConnection) {
const stakeAccounts = await getStakeAccountsPubkeys(stakeConnection.userPublicKey(), stakeConnection)
setStakeAccounts(stakeAccounts)
if (stakeAccounts.length > 0){
setSelectStakeAccount(await stakeConnection.loadStakeAccount(stakeAccounts[0]))
} else {
setSelectStakeAccount(undefined)
}
} else {
setStakeAccounts(undefined)
}
}
loadStakeAccounts()
}, [stakeConnection])

const handleSelectStakeAccount = (event: any) => {
for (const stakeAccount of stakeAccounts!) {
if (stakeAccount.address.toString() === event.target.value) {
setSelectStakeAccount(stakeAccount)
break
const loadStakeAccount = async () => {
if (stakeAccounts && stakeConnection){
const stakeAccount = stakeAccounts.find(s => s.toString() === event.target.value)
if (stakeAccount) {
setSelectStakeAccount(await stakeConnection.loadStakeAccount(stakeAccount))
}
}
}
loadStakeAccount()
}

useEffect(() => {
Expand All @@ -65,11 +85,6 @@ const RequestSplit: NextPage = () => {
}
}, [initialSplitRequest])

useEffect(() => {
if (stakeAccounts && stakeAccounts.length > 0)
setSelectStakeAccount(stakeAccounts[0])
}, [stakeAccounts])

const requestSplit = async () => {
if (stakeConnection && selectedStakeAccount && recipient && balance)
try {
Expand Down Expand Up @@ -102,8 +117,8 @@ const RequestSplit: NextPage = () => {
onChange={handleSelectStakeAccount}
>
{stakeAccounts!.map((option, index) => (
<option key={index} value={option.address.toBase58()}>
{option.address.toString()}
<option key={index} value={option.toBase58()}>
{option.toString()}
</option>
))}
</select>
Expand Down
Loading

0 comments on commit 4d7d58b

Please sign in to comment.