Skip to content

Commit

Permalink
chore: Remove unused components from voting (#10258)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
The focus of this PR is to refactor the voting strategies in the
`Proposals` component and update dependencies.

### Detailed summary
- Removed `SNAPSHOT_VERSION` constant
- Refactored `veCakeBalanceStrategy`
- Updated imports in `helpers.ts`
- Removed unused functions in `strategies.ts`
- Updated `generateMetaData` and `generatePayloadData` functions

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
memoyil authored Sep 6, 2024
1 parent e383390 commit 5eeb7cf
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 194 deletions.
1 change: 0 additions & 1 deletion apps/web/src/views/Voting/components/Proposals/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default as Proposals } from './Proposals'
export { default as ProposalRow } from './ProposalRow'
1 change: 0 additions & 1 deletion apps/web/src/views/Voting/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export const ADMINS = [
'0x4a7b8400AE131feffC42E5Bf39401A094Ed497CA', // CHILI cakevote.eth
].map((address) => address.toLowerCase())
export const IPFS_GATEWAY = 'https://snapshot.4everland.link/ipfs'
export const SNAPSHOT_VERSION = '0.1.3'
export const PANCAKE_SPACE = 'cakevote.eth'
export const VOTE_THRESHOLD = 10 * 1_000
74 changes: 1 addition & 73 deletions apps/web/src/views/Voting/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { cakeVaultV2ABI } from '@pancakeswap/pools'
import { bscTokens } from '@pancakeswap/tokens'
import BigNumber from 'bignumber.js'
import { SNAPSHOT_HUB_API } from 'config/constants/endpoints'
import fromPairs from 'lodash/fromPairs'
import groupBy from 'lodash/groupBy'
import { Proposal, ProposalState, ProposalType, Vote } from 'state/types'
import { getCakeVaultAddress } from 'utils/addressHelpers'
import { Address, createPublicClient, http } from 'viem'
import { bsc } from 'viem/chains'
import { convertSharesToCake } from 'views/Pools/helpers'
import { ADMINS, PANCAKE_SPACE, SNAPSHOT_VERSION } from './config'
import { ADMINS, PANCAKE_SPACE } from './config'
import { getScores } from './getScores'
import * as strategies from './strategies'

Expand Down Expand Up @@ -37,61 +35,11 @@ export const filterProposalsByState = (proposals: Proposal[], state: ProposalSta
return proposals.filter((proposal) => proposal.state === state)
}

export interface Message {
address: string
msg: string
sig: string
}

const STRATEGIES = [
{ name: 'cake', params: { symbol: 'CAKE', address: bscTokens.cake.address, decimals: 18, max: 300 } },
]
const NETWORK = '56'

/**
* Generates metadata required by snapshot to validate payload
*/
export const generateMetaData = () => {
return {
plugins: {},
network: 56,
strategies: STRATEGIES,
}
}

/**
* Returns data that is required on all snapshot payloads
*/
export const generatePayloadData = () => {
return {
version: SNAPSHOT_VERSION,
timestamp: (Date.now() / 1e3).toFixed(),
space: PANCAKE_SPACE,
}
}

/**
* General function to send commands to the snapshot api
*/
export const sendSnapshotData = async (message: Message) => {
const response = await fetch(SNAPSHOT_HUB_API, {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
})

if (!response.ok) {
const error = await response.json()
throw new Error(error?.error_description)
}

const data = await response.json()
return data
}

export const VOTING_POWER_BLOCK = {
v0: 16300686n,
v1: 17137653n,
Expand Down Expand Up @@ -252,23 +200,3 @@ export const getTotalFromVotes = (votes: Vote[]) => {
}
return 0
}

/**
* Get voting power by a list of voters, only total
*/
export async function getVotingPowerByCakeStrategy(voters: string[], blockNumber: number) {
const strategyResponse = await getScores(PANCAKE_SPACE, STRATEGIES, NETWORK, voters, blockNumber)

const result = fromPairs(
voters.map((voter) => {
const defaultTotal = strategyResponse.reduce(
(total: any, scoreList: any) => total + (scoreList[voter] ? scoreList[voter] : 0),
0,
)

return [voter, defaultTotal]
}),
)

return result
}
119 changes: 0 additions & 119 deletions apps/web/src/views/Voting/strategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@ export const votePowerAddress = {
veCake: '0x67Dfbb197602FDB9A9D305cC7A43b95fB63a0A56',
} as const

export const veCakeBalanceStrategy = {
name: 'contract-call',
params: {
address: votePowerAddress.veCake,
decimals: 18,
args: ['%{address}'],
methodABI: {
inputs: [
{
internalType: 'address',
name: '_user',
type: 'address',
},
],
name: 'getVotingPowerWithoutPool',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
},
}

export const cakeBalanceStrategy = (version: 'v0' | 'v1') => ({
name: 'contract-call',
params: {
Expand Down Expand Up @@ -236,94 +208,3 @@ export function createTotalStrategy(poolAddress, version: 'v0' | 'v1') {
},
}
}

export function lockedCakeUser(
cakeVaultAddress,
outputName: 'lockedAmount' | 'lockEndTime' | 'shares' | 'userBoostedShare',
) {
return {
name: 'contract-call',
params: {
address: cakeVaultAddress,
decimals: 0,
output: outputName,
args: ['%{address}'],
methodABI: {
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'userInfo',
outputs: [
{
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'lastDepositedTime',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'cakeAtLastUserAction',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'lastUserActionTime',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'lockStartTime',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'lockEndTime',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'userBoostedShare',
type: 'uint256',
},
{
internalType: 'bool',
name: 'locked',
type: 'bool',
},
{
internalType: 'uint256',
name: 'lockedAmount',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
},
}
}

export function lockedCakeShare(cakeVaultAddress) {
return {
name: 'contract-call',
params: {
address: cakeVaultAddress,
decimals: 0,
methodABI: {
inputs: [],
name: 'getPricePerFullShare',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
},
}
}

0 comments on commit 5eeb7cf

Please sign in to comment.