Skip to content

Commit

Permalink
more updates/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
codenamejason committed May 19, 2024
1 parent 11b052f commit 28c4102
Show file tree
Hide file tree
Showing 11 changed files with 2,504 additions and 268 deletions.
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@gitcoinco/passport-sdk-types": "^0.2.0",
"@grants-labs/gitcoin-chain-data": "^1.0.11",
"@grants-labs/gitcoin-chain-data": "1.0.20",
"@openzeppelin/merkle-tree": "^1.0.2",
"@rainbow-me/rainbowkit": "^0.12.16",
"@spruceid/didkit-wasm": "0.3.0-alpha0",
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/allo/allo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
RoundCategory,
UpdateRoundParams,
MatchingStatsData,
VotingToken,
} from "../types";
import { Result } from "./common";
import { AlloOperation } from "./operation";
import { TransactionReceipt } from "./transaction-sender";
import { PermitSignature } from "./voting";
import { TDonationToken } from "@grants-labs/gitcoin-chain-data";

export type CreateRoundArguments = {
roundData: {
Expand Down Expand Up @@ -114,7 +114,7 @@ export interface Allo {
donate: (
publicClient: PublicClient,
chainId: ChainId,
token: VotingToken,
token: TDonationToken,
groupedVotes: Record<string, Hex[]>,
groupedAmounts: Record<string, bigint> | bigint[],
nativeTokenAmount: bigint,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/allo/backends/allo-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
UpdateAction,
UpdateRoundParams,
MatchingStatsData,
VotingToken,
} from "../../types";
import ProgramFactoryABI from "../abis/allo-v1/ProgramFactory";
import MRC_ABI from "../abis/allo-v1/multiRoundCheckout";
Expand Down Expand Up @@ -58,6 +57,7 @@ import { BigNumber } from "ethers";
import DirectPayoutStrategyImplementation from "../abis/allo-v1/DirectPayoutStrategyImplementation";
import { hexZeroPad } from "ethers/lib/utils.js";
import { getTokensByChainId } from "@grants-labs/gitcoin-chain-data";
import { TDonationToken } from "@grants-labs/gitcoin-chain-data/dist/types";

function createProjectId(args: {
chainId: number;
Expand Down Expand Up @@ -111,7 +111,7 @@ export class AlloV1 implements Allo {
async donate(
publicClient: PublicClient,
chainId: ChainId,
token: VotingToken,
token: TDonationToken,
groupedVotes: Record<string, Hex[]>,
groupedAmounts: Record<string, bigint> | bigint[],
nativeTokenAmount: bigint,
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/allo/backends/allo-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "data-layer";
import { Abi, Address, Hex, PublicClient, getAddress, zeroAddress } from "viem";
import { AnyJson, ChainId } from "../..";
import { UpdateRoundParams, MatchingStatsData, VotingToken } from "../../types";
import { UpdateRoundParams, MatchingStatsData } from "../../types";
import { Allo, AlloError, AlloOperation, CreateRoundArguments } from "../allo";
import {
Result,
Expand All @@ -46,6 +46,7 @@ import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { buildUpdatedRowsOfApplicationStatuses } from "../application";
import { BigNumber, utils } from "ethers";
import { Distribution } from "@allo-team/allo-v2-sdk/dist/strategies/DonationVotingMerkleDistributionStrategy/types";
import { TDonationToken } from "@grants-labs/gitcoin-chain-data/dist/types";

function getStrategyAddress(strategy: RoundCategory, chainId: ChainId): string {
let strategyAddresses;
Expand Down Expand Up @@ -151,7 +152,7 @@ export class AlloV2 implements Allo {
async donate(
publicClient: PublicClient,
chainId: ChainId,
token: VotingToken,
token: TDonationToken,
groupedVotes: Record<string, Hex[]>,
groupedAmounts: Record<string, bigint> | bigint[],
nativeTokenAmount: bigint,
Expand Down
9 changes: 3 additions & 6 deletions packages/common/src/allo/voting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VotingToken } from "../types";
import { TDonationToken } from "@grants-labs/gitcoin-chain-data/dist/types";

export type PermitSignature = {
v: number;
Expand All @@ -11,11 +11,8 @@ export type PermitSignature = {
*
* Old DAI permit type is only implemented on Ethereum and Polygon PoS. Check /docs/DAI.md for more info.
* */
export const getPermitType = (token: VotingToken): PermitType => {
if (
/DAI/i.test(token.name) &&
([1, 137, 11155111].includes(token.chainId))
) {
export const getPermitType = (token: TDonationToken): PermitType => {
if (/DAI/i.test(token.name) && [1, 137, 11155111].includes(token.chainId)) {
return "dai";
} else {
return "eip2612";
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/payoutTokens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ChainId, RedstoneTokenIds } from "./chain-ids";
import { ethers } from "ethers";
import { Address, sepolia } from "wagmi";
import { getChain, getTokensByChainId } from "@grants-labs/gitcoin-chain-data";
import { TTokenRecord } from "@grants-labs/gitcoin-chain-data/dist/types";
import { get } from "http";
import { Address } from "wagmi";
import { getTokensByChainId } from "@grants-labs/gitcoin-chain-data";

export type PayoutToken = {
name: string;
Expand Down
1 change: 1 addition & 0 deletions packages/grant-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@emotion/styled": "^11",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@grants-labs/gitcoin-chain-data": "^1.0.20",
"@headlessui/react": "^1.7.4",
"@heroicons/react": "^2.0.13",
"@playwright/test": "^1.41.1",
Expand Down
22 changes: 14 additions & 8 deletions packages/grant-explorer/src/checkoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { getPermitType } from "common/dist/allo/voting";
import { MRC_CONTRACTS } from "common/dist/allo/addresses/mrc";
import { getConfig } from "common/src/config";
import { DataLayer } from "data-layer";
import {
TDonationToken,
getTokensByChainId,
} from "@grants-labs/gitcoin-chain-data";

type ChainMap<T> = Record<ChainId, T>;

Expand Down Expand Up @@ -117,8 +121,14 @@ export const useCheckoutStore = create<CheckoutState>()(
[chain: number]: CartProject[];
};

const getVotingTokenForChain =
useCartStorage.getState().getVotingTokenForChain;
// : TDonationToken
const getVotingTokenForChain = async (chainId: number) =>
(await getTokensByChainId(chainId)).donation[0] as TDonationToken;

// fixme: this is a hack to get the token for mainnet/ update to use actual chainId
const donationToken = await getVotingTokenForChain(Number(1) as number);

// useCartStorage.getState().getVotingTokenForChain;

const totalDonationPerChain = Object.fromEntries(
Object.entries(projectsByChain).map(([key, value]) => [
Expand All @@ -127,11 +137,7 @@ export const useCheckoutStore = create<CheckoutState>()(
.map((project) => project.amount)
.reduce(
(acc, amount) =>
acc +
parseUnits(
amount ? amount : "0",
getVotingTokenForChain(Number(key) as ChainId).decimal
),
acc + parseUnits(amount ? amount : "0", donationToken.decimal),
0n
),
])
Expand All @@ -150,7 +156,7 @@ export const useCheckoutStore = create<CheckoutState>()(
/* Switch to the current chain */
await switchToChain(chainId, walletClient, get);

const token = getVotingTokenForChain(chainId);
const token = await getVotingTokenForChain(chainId);

let sig;
let nonce;
Expand Down
2 changes: 1 addition & 1 deletion packages/round-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@ethersproject/abi": "5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@grants-labs/gitcoin-chain-data": "^1.0.11",
"@grants-labs/gitcoin-chain-data": "^1.0.20",
"@headlessui/react": "^1.6.6",
"@heroicons/react": "^1.0.6",
"@hookform/resolvers": "^2.9.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {
} from "../../../test-utils";
import { ProgressStatus, Round } from "../../api/types";
import ViewRoundPage from "../ViewRoundPage";
import {
getTokensByChainId,
TPayoutToken,
} from "@grants-labs/gitcoin-chain-data";
import { useContractAmountFunded } from "../FundContract";
import { getTokensByChainId } from "@grants-labs/gitcoin-chain-data";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextDecoder } = require("util");
Expand Down Expand Up @@ -81,7 +77,7 @@ describe("fund contract tab", () => {
(useParams as jest.Mock).mockImplementation(() => {
return {
id: mockRoundData.id,
payoutToken: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
payoutToken: "0x0000000000000000000000000000000000000000",
};
});

Expand All @@ -92,7 +88,7 @@ describe("fund contract tab", () => {
it("displays fund contract tab", async () => {
mockRoundData = makeRoundData({
// Ensure the token address matches the mocked token data
token: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
token: "0x0000000000000000000000000000000000000000",
chainId: 1,
});

Expand Down Expand Up @@ -123,12 +119,11 @@ describe("fund contract tab", () => {
return {
data: [
{
name: "USDC",
name: "ETH",
chainId: 1,
address: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
redstoneTokenId: "USDC",
decimal: 6,
logo: "path/to/usdc/logo.png",
address: "0x0000000000000000000000000000000000000000",
redstoneTokenId: "ETH",
decimal: 18,
},
],
};
Expand Down
Loading

0 comments on commit 28c4102

Please sign in to comment.