Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into cohort/spaghetteth
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jul 4, 2023
2 parents 793f24f + a610bfa commit 5f301c5
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 81 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clrfund/contracts",
"version": "4.2.2",
"version": "4.2.3",
"license": "GPL-3.0",
"scripts": {
"hardhat": "hardhat",
Expand Down
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clrfund/subgraph",
"version": "4.2.2",
"version": "4.2.3",
"repository": "https://github.com/clrfund/monorepo/subgraph",
"keywords": [
"clr.fund",
Expand Down
30 changes: 15 additions & 15 deletions subgraph/src/MACIMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,24 @@ export function handleSignUp(event: SignUp): void {

//NOTE: If the public keys aren't being tracked initialize them
if (publicKey == null) {
let publicKey = new PublicKey(publicKeyId)
publicKey.x = event.params._userPubKey.x
publicKey.y = event.params._userPubKey.y
publicKey.stateIndex = event.params._stateIndex

publicKey.voiceCreditBalance = event.params._voiceCreditBalance
publicKey = new PublicKey(publicKeyId)
}
publicKey.x = event.params._userPubKey.x
publicKey.y = event.params._userPubKey.y
publicKey.stateIndex = event.params._stateIndex

let fundingRoundAddress = event.transaction.to!
let fundingRoundId = fundingRoundAddress.toHex()
let fundingRound = FundingRound.load(fundingRoundId)
if (fundingRound == null) {
log.error('Error: handleSignUp failed, fundingRound not registered', [])
return
}
publicKey.voiceCreditBalance = event.params._voiceCreditBalance

publicKey.fundingRound = fundingRoundId
publicKey.save()
let fundingRoundAddress = event.transaction.to!
let fundingRoundId = fundingRoundAddress.toHex()
let fundingRound = FundingRound.load(fundingRoundId)
if (fundingRound == null) {
log.error('Error: handleSignUp failed, fundingRound not registered', [])
return
}

publicKey.fundingRound = fundingRoundId
publicKey.save()

log.info('SignUp', [])
}
2 changes: 1 addition & 1 deletion vue-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clrfund/vue-app",
"version": "4.2.2",
"version": "4.2.3",
"private": true,
"license": "GPL-3.0",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions vue-app/src/api/claims.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, FixedNumber } from 'ethers'
import { Contract, BigNumber } from 'ethers'
import sdk from '@/graphql/sdk'

import { FundingRound } from './abi'
Expand All @@ -9,10 +9,10 @@ export async function getAllocatedAmount(
tokenDecimals: number,
result: string,
spent: string,
): Promise<FixedNumber> {
): Promise<BigNumber> {
const fundingRound = new Contract(fundingRoundAddress, FundingRound, provider)
const allocatedAmount = await fundingRound.getAllocatedAmount(result, spent)
return FixedNumber.fromValue(allocatedAmount, tokenDecimals)
return allocatedAmount
}

export async function isFundsClaimed(
Expand Down
6 changes: 5 additions & 1 deletion vue-app/src/api/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ export async function getContributorIndex(fundingRoundAddress: string, pubKey: P
publicKeyId: id,
})

return data.publicKey?.stateIndex ? Number(data.publicKey.stateIndex) : null
if (data.publicKeys.length === 0) {
return null
}

return Number(data.publicKeys[0].stateIndex)
}

/**
Expand Down
12 changes: 6 additions & 6 deletions vue-app/src/api/factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FixedNumber } from 'ethers'
import { BigNumber } from 'ethers'
import { factory } from './core'
import sdk from '@/graphql/sdk'

Expand All @@ -8,14 +8,14 @@ export interface Factory {
nativeTokenSymbol: string
nativeTokenDecimals: number
userRegistryAddress: string
matchingPool: FixedNumber
matchingPool: BigNumber
}

export async function getFactoryInfo() {
let nativeTokenAddress = ''
let nativeTokenSymbol = ''
let nativeTokenDecimals = 0
let matchingPool = FixedNumber.from(0)
let matchingPool = BigNumber.from(0)
let userRegistryAddress = ''
let recipientRegistryAddress = ''

Expand All @@ -39,7 +39,7 @@ export async function getFactoryInfo() {
}

try {
matchingPool = await getMatchingFunds(nativeTokenAddress, nativeTokenDecimals)
matchingPool = await getMatchingFunds(nativeTokenAddress)
} catch (err) {
/* eslint-disable-next-line no-console */
console.error('Failed to get matching pool', err)
Expand All @@ -56,7 +56,7 @@ export async function getFactoryInfo() {
}
}

export async function getMatchingFunds(nativeTokenAddress: string, nativeTokenDecimals: number): Promise<FixedNumber> {
export async function getMatchingFunds(nativeTokenAddress: string): Promise<BigNumber> {
const matchingFunds = await factory.getMatchingFunds(nativeTokenAddress)
return FixedNumber.fromValue(matchingFunds, nativeTokenDecimals)
return matchingFunds
}
20 changes: 10 additions & 10 deletions vue-app/src/api/round.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, Contract, utils, FixedNumber } from 'ethers'
import { BigNumber, Contract, utils } from 'ethers'
import { DateTime } from 'luxon'
import { PubKey } from '@clrfund/maci-utils'

Expand Down Expand Up @@ -30,9 +30,9 @@ export interface RoundInfo {
startTime: DateTime
signUpDeadline: DateTime
votingDeadline: DateTime
totalFunds: FixedNumber
matchingPool: FixedNumber
contributions: FixedNumber
totalFunds: BigNumber
matchingPool: BigNumber
contributions: BigNumber
contributors: number
messages: number
blogUrl?: string
Expand Down Expand Up @@ -103,9 +103,9 @@ function toRoundInfo(data: any, network: string): RoundInfo {
startTime: DateTime.fromSeconds(data.startTime),
signUpDeadline: DateTime.fromSeconds(Number(data.startTime) + Number(data.signUpDuration)),
votingDeadline: DateTime.fromSeconds(Number(data.startTime) + Number(data.votingDuration)),
totalFunds: FixedNumber.fromValue(totalFunds, nativeTokenDecimals),
matchingPool: FixedNumber.fromValue(matchingPool, nativeTokenDecimals),
contributions: FixedNumber.fromValue(contributions, nativeTokenDecimals),
totalFunds,
matchingPool,
contributions,
contributors: data.contributorCount,
messages: Number(data.messages),
blogUrl: data.blogUrl,
Expand Down Expand Up @@ -240,9 +240,9 @@ export async function getRoundInfo(
startTime,
signUpDeadline,
votingDeadline,
totalFunds: FixedNumber.fromValue(totalFunds, nativeTokenDecimals),
matchingPool: FixedNumber.fromValue(matchingPool, nativeTokenDecimals),
contributions: FixedNumber.fromValue(contributions, nativeTokenDecimals),
totalFunds,
matchingPool,
contributions,
contributors,
messages: messages.toNumber(),
}
Expand Down
2 changes: 1 addition & 1 deletion vue-app/src/components/Cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ const contribution = computed(() => appStore.contribution || BigNumber.from(0))
const filteredCart = computed<CartItem[]>(() => {
// Once reallocation phase ends, use committedCart for cart items
if (hasReallocationPhaseEnded.value) {
return committedCart.value
return committedCart.value.filter(item => !item.isCleared)
}
// Hide cleared items
return cart.value.filter(item => !item.isCleared)
Expand Down
7 changes: 3 additions & 4 deletions vue-app/src/components/ClaimButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@

<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue'
import type { FixedNumber } from 'ethers'
import type { BigNumber } from 'ethers'
import { getAllocatedAmount, isFundsClaimed } from '@/api/claims'
import type { Project } from '@/api/projects'
import { RoundStatus } from '@/api/round'
import { formatAmount as _formatAmount } from '@/utils/amounts'
import { markdown } from '@/utils/markdown'
import ClaimModal from '@/components/ClaimModal.vue'
import Loader from '@/components/Loader.vue'
Expand All @@ -52,7 +51,7 @@ interface Props {
const props = defineProps<Props>()
const allocatedAmount = ref<FixedNumber | null>(null)
const allocatedAmount = ref<BigNumber | null>(null)
const claimed = ref<boolean | null>(null)
const isLoading = ref(true)
Expand Down Expand Up @@ -118,7 +117,7 @@ function canClaim(): boolean {
return hasClaimBtn() && !!currentUser.value && !claimed.value
}
function formatAmount(value: FixedNumber): string {
function formatAmount(value: BigNumber): string {
const maxDecimals = 6
const { nativeTokenDecimals } = currentRound.value!
return _formatAmount(value, nativeTokenDecimals, null, maxDecimals)
Expand Down
2 changes: 1 addition & 1 deletion vue-app/src/components/MatchingFundsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const balance = computed<string | null>(() => {
if (balance === null || typeof balance === 'undefined') {
return null
}
return formatUnits(balance, 18)
return formatUnits(balance, nativeTokenDecimals.value)
})
const renderBalance = computed<string | null>(() => {
const balance: BigNumber | null | undefined = userStore.currentUser?.balance
Expand Down
4 changes: 2 additions & 2 deletions vue-app/src/components/RoundInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const formatTotalInRound = computed(() => {
}
const { contributions, matchingPool } = roundInfo.value
const totalInRound = contributions.addUnsafe(matchingPool)
const totalInRound = contributions.add(matchingPool)
return formatAmount(totalInRound)
})
Expand Down Expand Up @@ -388,7 +388,7 @@ function formatDate(value: DateTime): string {
return value.toLocaleString(DateTime.DATETIME_SHORT) || ''
}
function formatAmount(value: BigNumber | FixedNumber | string): string {
function formatAmount(value: BigNumber | string): string {
if (!nativeTokenDecimals.value) {
return ''
}
Expand Down
25 changes: 4 additions & 21 deletions vue-app/src/graphql/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3146,12 +3146,12 @@ export type GetContributionsAmountQueryVariables = Exact<{
export type GetContributionsAmountQuery = { __typename?: 'Query', contributions: Array<{ __typename?: 'Contribution', amount: any | null }> };

export type GetContributorIndexQueryVariables = Exact<{
fundingRoundAddress: Scalars['ID'];
fundingRoundAddress: Scalars['String'];
publicKeyId: Scalars['ID'];
}>;


export type GetContributorIndexQuery = { __typename?: 'Query', publicKey: { __typename?: 'PublicKey', id: string, stateIndex: any | null } | null };
export type GetContributorIndexQuery = { __typename?: 'Query', publicKeys: Array<{ __typename?: 'PublicKey', id: string, stateIndex: any | null }> };

export type GetContributorMessagesQueryVariables = Exact<{
fundingRoundAddress: Scalars['String'];
Expand Down Expand Up @@ -3196,13 +3196,6 @@ export type GetProjectQueryVariables = Exact<{

export type GetProjectQuery = { __typename?: 'Query', recipients: Array<{ __typename?: 'Recipient', id: string, requestType: string | null, recipientAddress: any | null, recipientMetadata: string | null, recipientIndex: any | null, submissionTime: string | null, rejected: boolean | null, verified: boolean | null }> };

export type GetPublicKeyQueryVariables = Exact<{
pubKey: Scalars['ID'];
}>;


export type GetPublicKeyQuery = { __typename?: 'Query', publicKey: { __typename?: 'PublicKey', id: string } | null };

export type GetRecipientQueryVariables = Exact<{
registryAddress: Scalars['ID'];
recipientId: Scalars['ID'];
Expand Down Expand Up @@ -3286,8 +3279,8 @@ export const GetContributionsAmountDocument = gql`
}
`;
export const GetContributorIndexDocument = gql`
query GetContributorIndex($fundingRoundAddress: ID!, $publicKeyId: ID!) {
publicKey(id: $publicKeyId) {
query GetContributorIndex($fundingRoundAddress: String!, $publicKeyId: ID!) {
publicKeys(where: {id: $publicKeyId, fundingRound: $fundingRoundAddress}) {
id
stateIndex
}
Expand Down Expand Up @@ -3367,13 +3360,6 @@ export const GetProjectDocument = gql`
}
}
`;
export const GetPublicKeyDocument = gql`
query GetPublicKey($pubKey: ID!) {
publicKey(id: $pubKey) {
id
}
}
`;
export const GetRecipientDocument = gql`
query GetRecipient($registryAddress: ID!, $recipientId: ID!) {
recipientRegistry(id: $registryAddress) {
Expand Down Expand Up @@ -3540,9 +3526,6 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
GetProject(variables: GetProjectQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetProjectQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetProjectQuery>(GetProjectDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'GetProject', 'query');
},
GetPublicKey(variables: GetPublicKeyQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetPublicKeyQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetPublicKeyQuery>(GetPublicKeyDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'GetPublicKey', 'query');
},
GetRecipient(variables: GetRecipientQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetRecipientQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetRecipientQuery>(GetRecipientDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'GetRecipient', 'query');
},
Expand Down
4 changes: 2 additions & 2 deletions vue-app/src/graphql/queries/GetContributorIndex.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
query GetContributorIndex(
$fundingRoundAddress: ID!
$fundingRoundAddress: String!
$publicKeyId: ID!
) {
publicKey(id: $publicKeyId) {
publicKeys(where: {id: $publicKeyId, fundingRound: $fundingRoundAddress}) {
id
stateIndex
}
Expand Down
5 changes: 0 additions & 5 deletions vue-app/src/graphql/queries/GetPublicKey.graphql

This file was deleted.

6 changes: 3 additions & 3 deletions vue-app/src/stores/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import { FixedNumber, type BigNumber } from 'ethers'
import { BigNumber } from 'ethers'
import {
type CartItem,
type Contributor,
Expand Down Expand Up @@ -152,10 +152,10 @@ export const useAppStore = defineStore('app', {
return factory.userRegistryAddress
}
},
matchingPool: (state): FixedNumber => {
matchingPool: (state): BigNumber => {
const { currentRound, factory } = state

let matchingPool = FixedNumber.from(0)
let matchingPool = BigNumber.from(0)

if (factory) {
matchingPool = factory.matchingPool
Expand Down
4 changes: 2 additions & 2 deletions vue-app/src/utils/amounts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { BigNumber, BigNumberish, FixedNumber } from 'ethers'
import type { BigNumber, BigNumberish } from 'ethers'
import { commify, formatUnits } from '@ethersproject/units'

export function formatAmount(
_value: BigNumber | FixedNumber | string,
_value: BigNumber | string,
units: BigNumberish = 18,
maximumSignificantDigits?: number | null,
maxDecimals?: number | null,
Expand Down
6 changes: 4 additions & 2 deletions vue-app/src/views/TransactionSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ import { useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const appStore = useAppStore()
const { contribution, currentRound } = storeToRefs(appStore)
const { contribution, currentRound, nativeTokenDecimals } = storeToRefs(appStore)

const formatContribution = computed(() => (contribution.value ? formatAmount(contribution.value, 18) : ''))
const formatContribution = computed(() =>
contribution.value ? formatAmount(contribution.value, nativeTokenDecimals.value) : '',
)
const hash = computed(() => route.params.hash as string)
function redirectToProjects() {
router.push({ name: 'projects' })
Expand Down

0 comments on commit 5f301c5

Please sign in to comment.