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

Add new function for strategy Id #18

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dist/strategies/Common/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function getStrategyContractId(chainId: string, strategyContract: string): Promise<{
strategyId: `0x${string}`;
}>;
78 changes: 78 additions & 0 deletions dist/strategies/Common/common.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions dist/strategies/Common/publicClient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare class PublicClient {
chainId: any;
publicClient: any;
constructor(chainId: any);
}
17 changes: 17 additions & 0 deletions dist/strategies/Common/publicClient.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export declare class MicroGrantsStrategy {
getGovAddress(): Promise<`0x${string}`>;
getSnapshotReference(): Promise<bigint>;
getMinimumVotePower(): Promise<bigint>;
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}`>;
Expand Down
63 changes: 63 additions & 0 deletions dist/strategies/MicroGrantsStrategy/MicroGrantsStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"), [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -25,7 +25,7 @@
"dependencies": {
"dotenv": "^16.3.1",
"events": "^3.3.0",
"viem": "^1.19.0"
"viem": "^1.19.9"
},
"repository": {
"type": "git",
Expand Down
Loading
Loading