diff --git a/dist/strategies/Common/common.d.ts b/dist/strategies/Common/common.d.ts new file mode 100644 index 0000000..cd98176 --- /dev/null +++ b/dist/strategies/Common/common.d.ts @@ -0,0 +1,3 @@ +export declare function getStrategyContractId(chainId: string, strategyContract: string): Promise<{ + strategyId: `0x${string}`; +}>; diff --git a/dist/strategies/Common/common.js b/dist/strategies/Common/common.js new file mode 100644 index 0000000..0497a4c --- /dev/null +++ b/dist/strategies/Common/common.js @@ -0,0 +1,78 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getStrategyContractId = void 0; +const publicClient_1 = require("./publicClient"); +function getStrategyContractId(chainId, strategyContract) { + return __awaiter(this, void 0, void 0, function* () { + const abi = [ + { + inputs: [], + name: "getStrategyId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + ]; + // todo: this is hardcoded to goerli in the client... + const client = new publicClient_1.PublicClient(chainId); + const strategyId = yield client.publicClient.readContract({ + address: strategyContract, + abi, + functionName: "getStrategyId", + }); + switch (strategyId) { + case "0x697f0592ebd05466d2d24454477e11d69c475d7a7c4134f15ddc1ea9811bb16f": + return { + strategyId: strategyId, + }; + case "0x741ac1e2f387d83f219f6b5349d35ec34902cf94019d117335e0045d2e0ed912": + return { + strategyId: strategyId, + }; + case "0x5aa24dcfcd55a1e059a172e987b3456736b4856c71e57aaf52e9a965897318dd": + return { + strategyId: strategyId, + }; + case "0xb87f34c0968bd74d43a6a5b72831a5ea733a4783a026b9fc9b1d17adf51214d2": + return { + strategyId: strategyId, + }; + case "0x414f2ea9b91b8ee2e35a380fa0af0e14079832cc93530a61a4893b3dbf0a9aba": + return { + strategyId: strategyId, + }; + case "0xed28ce0387d1786c1a38404047e9eecc4d1dcaeff695b867e912483e36c3d770": + return { + strategyId: strategyId, + }; + case "0xc5263e972c91d7ff40708bc71239a2b6cbc8768704e210ca3069e2e11fc195df": + return { + strategyId: strategyId, + }; + case "0xecc48557f4826bd1181a4495232d6d07f248ef9cc0a650e64520f6c9f7458a8c": + return { + strategyId: strategyId, + }; + default: + return { + strategyId: "0x", + }; + } + }); +} +exports.getStrategyContractId = getStrategyContractId; diff --git a/dist/strategies/Common/publicClient.d.ts b/dist/strategies/Common/publicClient.d.ts new file mode 100644 index 0000000..c0aa496 --- /dev/null +++ b/dist/strategies/Common/publicClient.d.ts @@ -0,0 +1,5 @@ +export declare class PublicClient { + chainId: any; + publicClient: any; + constructor(chainId: any); +} diff --git a/dist/strategies/Common/publicClient.js b/dist/strategies/Common/publicClient.js new file mode 100644 index 0000000..84e79e2 --- /dev/null +++ b/dist/strategies/Common/publicClient.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PublicClient = void 0; +const viem_1 = require("viem"); +const chains_1 = require("viem/chains"); +// todo: sort out the typing of chainId here... +const publicClient = (chainId) => (0, viem_1.createPublicClient)({ + chain: chainId, + transport: (0, viem_1.http)(), +}); +class PublicClient { + constructor(chainId) { + this.chainId = chainId; + this.publicClient = publicClient(chains_1.goerli); + } +} +exports.PublicClient = PublicClient; diff --git a/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.d.ts b/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.d.ts index 4849209..c9dadac 100644 --- a/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.d.ts +++ b/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.d.ts @@ -36,6 +36,9 @@ export declare class MicroGrantsStrategy { getGovAddress(): Promise<`0x${string}`>; getSnapshotReference(): Promise; getMinimumVotePower(): Promise; + getStrategyContractId(strategyContract: string): Promise<{ + strategyId: `0x${string}`; + }>; getInitializeData(params: InitializeParams): Promise<`0x${string}`>; getInitializeDataHats(params: InitializeParamsHats): Promise<`0x${string}`>; getInitializeDataGov(params: InitializeParamsGov): Promise<`0x${string}`>; diff --git a/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.js b/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.js index c4b61dd..290a86e 100644 --- a/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.js +++ b/dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.js @@ -262,6 +262,69 @@ class MicroGrantsStrategy { return votePower; }); } + getStrategyContractId(strategyContract) { + return __awaiter(this, void 0, void 0, function* () { + const abi = [ + { + inputs: [], + name: "getStrategyId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + ]; + const contractReader = (0, viem_1.getContract)({ + address: strategyContract, + abi: microGrantsGov_config_1.abi, + publicClient: this.client, + }); + const strategyId = yield contractReader.read.getStrategyId(); + switch (strategyId) { + case "0x697f0592ebd05466d2d24454477e11d69c475d7a7c4134f15ddc1ea9811bb16f": + return { + strategyId: strategyId, + }; + case "0x741ac1e2f387d83f219f6b5349d35ec34902cf94019d117335e0045d2e0ed912": + return { + strategyId: strategyId, + }; + case "0x5aa24dcfcd55a1e059a172e987b3456736b4856c71e57aaf52e9a965897318dd": + return { + strategyId: strategyId, + }; + case "0xb87f34c0968bd74d43a6a5b72831a5ea733a4783a026b9fc9b1d17adf51214d2": + return { + strategyId: strategyId, + }; + case "0x414f2ea9b91b8ee2e35a380fa0af0e14079832cc93530a61a4893b3dbf0a9aba": + return { + strategyId: strategyId, + }; + case "0xed28ce0387d1786c1a38404047e9eecc4d1dcaeff695b867e912483e36c3d770": + return { + strategyId: strategyId, + }; + case "0xc5263e972c91d7ff40708bc71239a2b6cbc8768704e210ca3069e2e11fc195df": + return { + strategyId: strategyId, + }; + case "0xecc48557f4826bd1181a4495232d6d07f248ef9cc0a650e64520f6c9f7458a8c": + return { + strategyId: strategyId, + }; + default: + return { + strategyId: "0x", + }; + } + }); + } getInitializeData(params) { return __awaiter(this, void 0, void 0, function* () { const encoded = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)("bool, uint64, uint64, uint256, uint256"), [ diff --git a/package.json b/package.json index c81d51a..8d7967c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@allo-team/allo-v2-sdk", - "version": "1.0.30", + "version": "1.0.33", "description": "sdk for allo v2", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -25,7 +25,7 @@ "dependencies": { "dotenv": "^16.3.1", "events": "^3.3.0", - "viem": "^1.19.0" + "viem": "^1.19.9" }, "repository": { "type": "git", diff --git a/src/strategies/MicroGrantsStrategy/MicroGrantsStrategy.ts b/src/strategies/MicroGrantsStrategy/MicroGrantsStrategy.ts index 30b5165..beb0986 100644 --- a/src/strategies/MicroGrantsStrategy/MicroGrantsStrategy.ts +++ b/src/strategies/MicroGrantsStrategy/MicroGrantsStrategy.ts @@ -95,14 +95,14 @@ export class MicroGrantsStrategy { private checkPoolId(): void { if (this.poolId === -1) throw new Error( - "MicroGrantsStrategy: No poolId provided. Please call `setPoolId` first.", + "MicroGrantsStrategy: No poolId provided. Please call `setPoolId` first." ); } private checkStrategy(): void { if (!this.strategy) throw new Error( - "MicroGrantsStrategy: No strategy address provided. Please call `setContract` first.", + "MicroGrantsStrategy: No strategy address provided. Please call `setContract` first." ); } @@ -122,7 +122,7 @@ export class MicroGrantsStrategy { public async allocated( allocatorAddress: string, - recipientAddress: string, + recipientAddress: string ): Promise { this.checkStrategy(); @@ -242,7 +242,7 @@ export class MicroGrantsStrategy { public async recipientAllocations( recipientId: string, - status: Status, + status: Status ): Promise { this.checkStrategy(); @@ -344,8 +344,83 @@ export class MicroGrantsStrategy { return votePower; } + public async getStrategyContractId( + strategyContract: string + ): Promise<{ strategyId: `0x${string}` }> { + const abi = [ + { + inputs: [], + name: "getStrategyId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + ]; + + const contractReader = getContract({ + address: strategyContract as `0x${string}`, + abi: microGrantsGovAbi, + publicClient: this.client, + }); + + const strategyId = await contractReader.read.getStrategyId(); + + switch (strategyId) { + case "0x697f0592ebd05466d2d24454477e11d69c475d7a7c4134f15ddc1ea9811bb16f": + return { + strategyId: strategyId, + }; + + case "0x741ac1e2f387d83f219f6b5349d35ec34902cf94019d117335e0045d2e0ed912": + return { + strategyId: strategyId, + }; + + case "0x5aa24dcfcd55a1e059a172e987b3456736b4856c71e57aaf52e9a965897318dd": + return { + strategyId: strategyId, + }; + + case "0xb87f34c0968bd74d43a6a5b72831a5ea733a4783a026b9fc9b1d17adf51214d2": + return { + strategyId: strategyId, + }; + + case "0x414f2ea9b91b8ee2e35a380fa0af0e14079832cc93530a61a4893b3dbf0a9aba": + return { + strategyId: strategyId, + }; + + case "0xed28ce0387d1786c1a38404047e9eecc4d1dcaeff695b867e912483e36c3d770": + return { + strategyId: strategyId, + }; + + case "0xc5263e972c91d7ff40708bc71239a2b6cbc8768704e210ca3069e2e11fc195df": + return { + strategyId: strategyId, + }; + + case "0xecc48557f4826bd1181a4495232d6d07f248ef9cc0a650e64520f6c9f7458a8c": + return { + strategyId: strategyId, + }; + + default: + return { + strategyId: "0x", + }; + } + } + public async getInitializeData( - params: InitializeParams, + params: InitializeParams ): Promise<`0x${string}`> { const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters("bool, uint64, uint64, uint256, uint256"), @@ -355,18 +430,18 @@ export class MicroGrantsStrategy { params.allocationEndTime, params.approvalThreshold, params.maxRequestedAmount, - ], + ] ); return encoded; } public async getInitializeDataHats( - params: InitializeParamsHats, + params: InitializeParamsHats ): Promise<`0x${string}`> { const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters( - "(bool, uint64, uint64, uint256, uint256), address, uint256", + "(bool, uint64, uint64, uint256, uint256), address, uint256" ), [ [ @@ -378,18 +453,18 @@ export class MicroGrantsStrategy { ], params.hats, params.hatId, - ], + ] ); return encoded; } public async getInitializeDataGov( - params: InitializeParamsGov, + params: InitializeParamsGov ): Promise<`0x${string}`> { const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters( - "bool, uint64, uint64, uint256, uint256, address, uint256, uint256", + "bool, uint64, uint64, uint256, uint256, address, uint256, uint256" ), [ params.useRegistryAnchor, @@ -400,7 +475,7 @@ export class MicroGrantsStrategy { params.gov, params.snapshotReference, params.minVotePower, - ], + ] ); console.log(params); @@ -411,7 +486,7 @@ export class MicroGrantsStrategy { public getDeployParams(strategyType: string): DeployParams { const constructorArgs: `0x${string}` = encodeAbiParameters( parseAbiParameters("address, string"), - [this.allo.address(), strategyType], + [this.allo.address(), strategyType] ); const constructorArgsNo0x = constructorArgs.slice(2); @@ -443,7 +518,7 @@ export class MicroGrantsStrategy { allocations.forEach((allocation) => { const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters("address, uint8"), - [allocation.recipientId, allocation.status], + [allocation.recipientId, allocation.status] ); encodedParams.push(encoded); @@ -466,12 +541,12 @@ export class MicroGrantsStrategy { public getAllocationData( recipientId: `0x${string}`, - status: Status, + status: Status ): TransactionData { this.checkPoolId(); const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters("address, uint8"), - [recipientId, status], + [recipientId, status] ); const encodedData = encodeFunctionData({ @@ -496,7 +571,7 @@ export class MicroGrantsStrategy { data.recipientAddress, data.requestedAmount, [data.metadata.protocol, data.metadata.pointer], - ], + ] ); const encodedData = encodeFunctionData({ @@ -524,7 +599,7 @@ export class MicroGrantsStrategy { registerData.recipientAddress, registerData.requestedAmount, [registerData.metadata.protocol, registerData.metadata.pointer], - ], + ] ); encodedParams.push(encoded); @@ -550,7 +625,7 @@ export class MicroGrantsStrategy { const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters("uint256"), - [amount], + [amount] ); const encodedData = encodeFunctionData({ @@ -608,13 +683,13 @@ export class MicroGrantsStrategy { public getUpdatePoolTimestampsData( allocationStartTime: bigint, - allocationEndTime: bigint, + allocationEndTime: bigint ): TransactionData { this.checkStrategy(); const encoded: `0x${string}` = encodeAbiParameters( parseAbiParameters("uint64, uint64"), - [allocationStartTime, allocationEndTime], + [allocationStartTime, allocationEndTime] ); const encodedData = encodeFunctionData({