Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New chain config/common #3454

Closed
wants to merge 15 commits into from
2 changes: 2 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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.39",
"@openzeppelin/merkle-tree": "^1.0.2",
"@rainbow-me/rainbowkit": "^0.12.16",
"@spruceid/didkit-wasm": "0.3.0-alpha0",
Expand All @@ -31,6 +32,7 @@
"eslint-config-gitcoin": "workspace:*",
"ethers": "^5.6.5",
"framer-motion": "^10.12.7",
"gitcoin-chain-data": "link:@types/grants-labs/gitcoin-chain-data",
"markdown-it": "^13.0.1",
"moment-timezone": "^0.5.45",
"react": "^18.2.0",
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 { TToken } 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: TToken,
groupedVotes: Record<string, Hex[]>,
groupedAmounts: Record<string, bigint> | bigint[],
nativeTokenAmount: bigint,
Expand Down
19 changes: 12 additions & 7 deletions packages/common/src/allo/backends/allo-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import {
} from "viem";
import { AnyJson, ChainId, TransactionBuilder } from "../..";
import { parseChainId } from "../../chains";
import { payoutTokens } from "../../payoutTokens";
// import { payoutTokens } from "../../payoutTokens";
import {
RoundCategory,
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 @@ -57,6 +56,8 @@ import MerklePayoutStrategyImplementationABI from "../abis/allo-v1/MerklePayoutS
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 { TToken } from "@grants-labs/gitcoin-chain-data/dist/types";

function createProjectId(args: {
chainId: number;
Expand Down Expand Up @@ -110,7 +111,7 @@ export class AlloV1 implements Allo {
async donate(
publicClient: PublicClient,
chainId: ChainId,
token: VotingToken,
token: TToken,
groupedVotes: Record<string, Hex[]>,
groupedAmounts: Record<string, bigint> | bigint[],
nativeTokenAmount: bigint,
Expand Down Expand Up @@ -491,8 +492,8 @@ export class AlloV1 implements Allo {
args.roundData.applicationsEndTime
? dateToEthereumTimestamp(args.roundData.applicationsEndTime)
: args.roundData.roundEndTime
? dateToEthereumTimestamp(args.roundData.roundEndTime)
: maxUint256,
? dateToEthereumTimestamp(args.roundData.roundEndTime)
: maxUint256,
dateToEthereumTimestamp(args.roundData.roundStartTime),
args.roundData.roundEndTime
? dateToEthereumTimestamp(args.roundData.roundEndTime)
Expand All @@ -505,13 +506,17 @@ export class AlloV1 implements Allo {
if (isQF) {
// Ensure tokenAmount is normalized to token decimals
const tokenAmount = args.roundData.matchingFundsAvailable ?? 0;
const pyToken = payoutTokens.filter(

// Note: uses the new SDK
const tokens = getTokensByChainId(this.chainId);
const payoutTokens = tokens;
const payoutToken = payoutTokens.filter(
(t) =>
t.address.toLowerCase() === args.roundData.token.toLowerCase()
)[0];
parsedTokenAmount = parseUnits(
tokenAmount.toString(),
pyToken.decimal
payoutToken.decimals
);
}

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 { TToken } 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: TToken,
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 { TToken } 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: TToken): PermitType => {
if (/DAI/i.test(token.code) && [1, 137, 11155111].includes(token.chainId)) {
return "dai";
} else {
return "eip2612";
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/chains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,43 @@ import { ChainId } from "./chain-ids";
test("Valid input: number", () => {
const input = 137;
const result = parseChainId(input);

expect(result).toBe(ChainId.POLYGON);
});

test("Valid input: string (number as string)", () => {
const input = "80001";
const result = parseChainId(input);

expect(result).toBe(ChainId.POLYGON_MUMBAI);
});

test("Invalid input: string (non-existent enum name)", () => {
const input = "NON_EXISTENT_CHAIN";

expect(() => parseChainId(input)).toThrow("Invalid chainId " + input);
});

test("Invalid input: string (non-numeric string)", () => {
const input = "invalid";

expect(() => parseChainId(input)).toThrow("Invalid chainId " + input);
});

test("Invalid input: number (non-existent enum value)", () => {
const input = 999;

expect(() => parseChainId(input)).toThrow("Invalid chainId " + input);
});

test("Invalid input: null", () => {
const input = null;

expect(() => parseChainId(input as any)).toThrow("Invalid chainId null");
});

test("Invalid input: undefined", () => {
const input = undefined;

expect(() => parseChainId(input as any)).toThrow("Invalid chainId undefined");
});
Loading
Loading