diff --git a/packages/common/package.json b/packages/common/package.json index 2f2e3ffe7..c6a284e52 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -16,7 +16,7 @@ "test:watch": "vitest watch" }, "dependencies": { - "@allo-team/allo-v2-sdk": "^1.0.72", + "@allo-team/allo-v2-sdk": "^1.0.75", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", "@gitcoinco/passport-sdk-types": "^0.2.0", diff --git a/packages/common/src/allo/backends/allo-v2.ts b/packages/common/src/allo/backends/allo-v2.ts index 99b189ebe..79b28ebef 100644 --- a/packages/common/src/allo/backends/allo-v2.ts +++ b/packages/common/src/allo/backends/allo-v2.ts @@ -9,6 +9,8 @@ import { DonationVotingMerkleDistributionStrategyTypes, Registry, RegistryAbi, + StrategyFactory, + StrategyFactoryDVMDTAbi, TransactionData, } from "@allo-team/allo-v2-sdk"; import MRC_ABI from "../abis/allo-v1/multiRoundCheckout"; @@ -455,6 +457,11 @@ export class AlloV2 implements Allo { let initStrategyDataEncoded: Address; let token: Address = getAddress(NATIVE); + let strategyAddress = getStrategyAddress( + args.roundData.roundCategory, + this.chainId + ); + if (args.roundData.roundCategory === RoundCategory.QuadraticFunding) { const initStrategyData: DonationVotingMerkleDistributionStrategyTypes.InitializeData = { @@ -475,6 +482,48 @@ export class AlloV2 implements Allo { allowedTokens: [], // allow all tokens }; + if ( + [ + ChainId.ZKSYNC_ERA_MAINNET_CHAIN_ID, + ChainId.ZKSYNC_ERA_TESTNET_CHAIN_ID, + ].includes(this.chainId) + ) { + // Deploy Strategy using Factory + const strategyFactory = new StrategyFactory({ + chain: this.chainId, + factoryType: "DVMDT", + }); + + const txData = strategyFactory.getCreateStrategyDataByChainId(this.chainId); + + const txResult = await sendRawTransaction(this.transactionSender, { + to: txData.to, + data: txData.data, + value: BigInt(txData.value), + }); + + if (txResult.type === "error") { + return txResult; + } + + try { + const receipt = await this.transactionSender.wait(txResult.value); + + const strategyCreatedEvent = decodeEventFromReceipt({ + abi: StrategyFactoryDVMDTAbi, + receipt, + event: "StrategyCreated", + }); + + // Update strategy address with the deployed strategy + strategyAddress = strategyCreatedEvent.strategy; + } catch (err) { + const result = new AlloError("Failed to apply to round"); + emit("transactionStatus", error(result)); + return error(result); + } + } + const strategy = new DonationVotingMerkleDistributionStrategy({ chain: this.chainId, }); @@ -498,6 +547,48 @@ export class AlloV2 implements Allo { : UINT64_MAX, // in seconds, must be after registrationStartTime }; + if ( + [ + ChainId.ZKSYNC_ERA_MAINNET_CHAIN_ID, + ChainId.ZKSYNC_ERA_TESTNET_CHAIN_ID, + ].includes(this.chainId) + ) { + // Deploy Strategy using Factory + const strategyFactory = new StrategyFactory({ + chain: this.chainId, + factoryType: "DGL", + }); + + const txData = strategyFactory.getCreateStrategyDataByChainId(this.chainId); + + + const txResult = await sendRawTransaction(this.transactionSender, { + to: txData.to, + data: txData.data, + value: BigInt(txData.value), + }); + + if (txResult.type === "error") { + return txResult; + } + + try { + const receipt = await this.transactionSender.wait(txResult.value); + const strategyCreatedEvent = decodeEventFromReceipt({ + abi: StrategyFactoryDVMDTAbi, + receipt, + event: "StrategyCreated", + }); + + // Update strategy address with the deployed strategy + strategyAddress = strategyCreatedEvent.strategy; + } catch (err) { + const result = new AlloError("Failed to apply to round"); + emit("transactionStatus", error(result)); + return error(result); + } + } + const strategy = new DirectGrantsLiteStrategy({ chain: this.chainId, }); @@ -519,10 +610,7 @@ export class AlloV2 implements Allo { const createPoolArgs: CreatePoolArgs = { profileId: profileId as Hex, - strategy: getStrategyAddress( - args.roundData.roundCategory, - this.chainId - ), + strategy: strategyAddress, initStrategyData: initStrategyDataEncoded, token, amount: 0n, // we send 0 tokens to the pool, we fund it later @@ -532,7 +620,20 @@ export class AlloV2 implements Allo { ), }; - const txData = this.allo.createPool(createPoolArgs); + let txData: TransactionData; + + if ( + [ + ChainId.ZKSYNC_ERA_MAINNET_CHAIN_ID, + ChainId.ZKSYNC_ERA_TESTNET_CHAIN_ID, + ].includes(this.chainId) + ) { + // Deploy Strategy using Factory + txData = this.allo.createPoolWithCustomStrategy(createPoolArgs); + } else { + // Deploy Strategy using Cloning of approved strategies + txData = this.allo.createPool(createPoolArgs); + } const txResult = await sendRawTransaction(this.transactionSender, { to: txData.to, @@ -1224,10 +1325,7 @@ export class AlloV2 implements Allo { poolId: poolId, }); - const txData = strategy.distribute( - recipientIds, - projectsWithMerkleProof, - ); + const txData = strategy.distribute(recipientIds, projectsWithMerkleProof); const txResult = await sendRawTransaction(this.transactionSender, { to: txData.to, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb0a458f6..2800a1a12 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -358,8 +358,8 @@ importers: packages/common: dependencies: '@allo-team/allo-v2-sdk': - specifier: ^1.0.72 - version: 1.0.72(@typechain/ethers-v6@0.5.1)(ethers@5.7.2)(typechain@8.3.2)(typescript@5.4.5)(zod@3.22.4) + specifier: ^1.0.75 + version: 1.0.75(@typechain/ethers-v6@0.5.1)(ethers@5.7.2)(typechain@8.3.2)(typescript@5.4.5)(zod@3.22.4) '@ethersproject/abstract-signer': specifier: ^5.7.0 version: 5.7.0 @@ -1286,8 +1286,8 @@ packages: resolution: {integrity: sha512-UK0bHA7hh9cR39V+4gl2/NnBBjoXIxkuWAPCaY4X7fbH4L/azIi7ilWOCjMUYfpJgraLUAqkRi2BqrjME8Rynw==} dev: false - /@allo-team/allo-v2-sdk@1.0.72(@typechain/ethers-v6@0.5.1)(ethers@5.7.2)(typechain@8.3.2)(typescript@5.4.5)(zod@3.22.4): - resolution: {integrity: sha512-/vQ6DI6X7TlrgsU9vfVCihwkOWJkZjOiOSfyA7LiH3tSo9EVyhgEXtwirNExnbJEgKpI/Mm5wzQMfX3gW+om7A==} + /@allo-team/allo-v2-sdk@1.0.75(@typechain/ethers-v6@0.5.1)(ethers@5.7.2)(typechain@8.3.2)(typescript@5.4.5)(zod@3.22.4): + resolution: {integrity: sha512-QO0WxGb9raCVdocUNC7/keQFQyd3YIMwT3vW9j5LBQNcli73EL4vAnDGyoXp6DOsQK8AnIWHcS6D7X1C56xAeQ==} engines: {node: '>=16.15.0', npm: '>=8.5.5'} dependencies: '@typechain/hardhat': 9.1.0(@typechain/ethers-v6@0.5.1)(ethers@5.7.2)(hardhat@2.22.3)(typechain@8.3.2)