Skip to content

Commit

Permalink
- deploy strategy contract for era using factory
Browse files Browse the repository at this point in the history
- update sdk version
  • Loading branch information
thelostone-mc committed May 21, 2024
1 parent 809d2b3 commit ca0ef26
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
116 changes: 107 additions & 9 deletions packages/common/src/allo/backends/allo-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 =
{
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca0ef26

Please sign in to comment.