From 979f2daad3ff233ed5c4d1585be93da51581eff6 Mon Sep 17 00:00:00 2001 From: emmdim Date: Fri, 1 Mar 2024 19:10:39 +0100 Subject: [PATCH] Version bump @vocdoni/gasless-voting@0.0.1-rc26 solving graqhql issue --- packages/js-client/package.json | 5 +- packages/js-client/src/context.ts | 55 ++++++++++++++++++- packages/js-client/src/internal/constants.ts | 22 +++----- .../src/internal/modules/encoding.ts | 36 ++++++------ 4 files changed, 81 insertions(+), 37 deletions(-) diff --git a/packages/js-client/package.json b/packages/js-client/package.json index 6d93c54b..645fc232 100644 --- a/packages/js-client/package.json +++ b/packages/js-client/package.json @@ -1,7 +1,7 @@ { "name": "@vocdoni/gasless-voting", "author": "Vocdoni Association", - "version": "0.0.1-rc25", + "version": "0.0.1-rc26", "description": "Aragon DAO Gasless Voting Plugin SDK", "license": "AGPL-3.0-or-later", "main": "dist/index.js", @@ -91,7 +91,8 @@ "@vocdoni/sdk": "0.7.5", "axios": "0.27.2", "graphql": "^16.6.0", - "graphql-request": "4.3.0" + "graphql-request": "4.3.0", + "@aragon/osx-commons-configs": "0.2.0" }, "jest": { "preset": "ts-jest", diff --git a/packages/js-client/src/context.ts b/packages/js-client/src/context.ts index 77092ec6..8c1fb223 100644 --- a/packages/js-client/src/context.ts +++ b/packages/js-client/src/context.ts @@ -9,8 +9,22 @@ import { GaslessVotingOverriddenState, } from './types'; import { GaslessVotingContextParams } from './types'; -import { Context, ContextCore } from '@aragon/sdk-client-common'; +import { + getNetworkNameByAlias, + SupportedNetworks, +} from '@aragon/osx-commons-configs'; +import { + Context, + ContextCore, + UnsupportedProtocolError, + UnsupportedNetworkError, +} from '@aragon/sdk-client-common'; +import { GraphQLClient } from 'graphql-request'; +const supportedProtocols = ['https:']; +if (typeof process !== 'undefined' && process?.env?.TESTING) { + supportedProtocols.push('http:'); +} export class GaslessVotingContext extends ContextCore { // This variable keeps track of the state of the context and is an extension of the Base Context State protected state: GaslessVotingContextState = this.state; @@ -54,6 +68,17 @@ export class GaslessVotingContext extends ContextCore { // so we need to call the parent set first super.set(contextParams); + const networkName = getNetworkNameByAlias(this.network.name); + if (!networkName) { + throw new UnsupportedNetworkError(this.network.name); + } + + this.state.graphql = GaslessVotingContext.resolveGraphQL( + GaslessVotingContext.getDefaultGraphqlNodes(networkName) + ); + this.overriden.graphql = true; + this.overriden.graphqlNodes = true; + // set the default values for the new params this.setDefaults(); @@ -94,4 +119,32 @@ export class GaslessVotingContext extends ContextCore { get gaslessVotingBackendUrl(): string { return this.state.gaslessVotingBackendUrl; } + + private static resolveGraphQL(endpoints: { url: string }[]): GraphQLClient[] { + let clients: GraphQLClient[] = []; + endpoints.forEach((endpoint) => { + const url = new URL(endpoint.url); + if (!supportedProtocols.includes(url.protocol)) { + throw new UnsupportedProtocolError(url.protocol); + } + clients.push(new GraphQLClient(url.href)); + }); + return clients; + } + + private static getDefaultGraphqlNodes(network: SupportedNetworks) { + if ( + !(network in DEFAULT_ADDRESSES) || + !('subgraphUrl' in DEFAULT_ADDRESSES[network]) + ) { + throw new UnsupportedNetworkError(network); + } + return [ + { + url: + DEFAULT_ADDRESSES[network].subgraphUrl || + DEFAULT_GASLESS_VOTING_SUBHGRAPH_URL, + }, + ]; + } } diff --git a/packages/js-client/src/internal/constants.ts b/packages/js-client/src/internal/constants.ts index 345ad422..7ee5aead 100644 --- a/packages/js-client/src/internal/constants.ts +++ b/packages/js-client/src/internal/constants.ts @@ -1,13 +1,10 @@ // import { MetadataAbiInput } from './types'; +import { SupportedNetworks } from '@aragon/osx-commons-configs'; import { IERC20MintableUpgradeable__factory, IGovernanceWrappedERC20__factory, } from '@aragon/osx-ethers'; -import { - MetadataAbiInput, - SupportedNetwork, - getInterfaceId, -} from '@aragon/sdk-client-common'; +import { MetadataAbiInput, getInterfaceId } from '@aragon/sdk-client-common'; import { Interface } from '@ethersproject/abi'; import { BigNumber } from '@ethersproject/bignumber'; import { abi as IVOTES_UPGRADEABLE_ABI } from '@openzeppelin/contracts-upgradeable/build/contracts/IVotesUpgradeable.json'; @@ -20,31 +17,32 @@ export const DEFAULT_GASLESS_VOTING_REPO_ADDRESS = export const DEFAULT_GASLESS_VOTING_SUBHGRAPH_URL = 'https://api.studio.thegraph.com/query/56701/vocdoni-gasless-voting-plugin/version/latest'; export const DEFAULT_ADDRESSES: { - [K in SupportedNetwork]: { + [K in SupportedNetworks]: { repoAddress: string; setupAddress: string; subgraphUrl?: string; }; } = { - homestead: { + mainnet: { setupAddress: '', repoAddress: '', + subgraphUrl: '', }, goerli: { setupAddress: '0x6847B82F943D7a761F12878b93a25868408D6cc3', repoAddress: '0x98C60A356f03244f9C33C9cA224d960cD45FD2C1', }, - matic: { + polygon: { setupAddress: '', repoAddress: '', }, - maticmum: { + mumbai: { setupAddress: '0xdb0Ae82868a899c556990C3C818C5521cc13A7B0', repoAddress: '0xfc7a07b6b22c1044a5dF4DF48B52AFAFcD370ECd', subgraphUrl: 'https://api.studio.thegraph.com/query/56701/vocdoni-gasless-voting-mumbai/version/latest', }, - base: { + baseMainnet: { setupAddress: '', repoAddress: '', }, @@ -70,10 +68,6 @@ export const DEFAULT_ADDRESSES: { setupAddress: '', repoAddress: '', }, - arbitrumGoerli: { - setupAddress: '', - repoAddress: '', - }, arbitrumSepolia: { setupAddress: '', repoAddress: '', diff --git a/packages/js-client/src/internal/modules/encoding.ts b/packages/js-client/src/internal/modules/encoding.ts index b934723e..6764efa6 100644 --- a/packages/js-client/src/internal/modules/encoding.ts +++ b/packages/js-client/src/internal/modules/encoding.ts @@ -11,20 +11,20 @@ import { initParamsToContract, gaslessVotingSettingsToContract, } from '../utils'; +import { SupportedNetworks } from '@aragon/osx-commons-configs'; import { IERC20MintableUpgradeable__factory } from '@aragon/osx-ethers'; -import { AddAddressesParams, MintTokenParams, RemoveAddressesParams } from '@aragon/sdk-client'; +import { + AddAddressesParams, + MintTokenParams, + RemoveAddressesParams, +} from '@aragon/sdk-client'; import { DaoAction, getNamedTypesFromMetadata, PluginInstallItem, - SupportedNetwork, - SupportedNetworksArray, hexToBytes, InvalidAddressError, UnsupportedNetworkError, -} from '@aragon/sdk-client-common'; -import { - } from '@aragon/sdk-client-common'; import { defaultAbiCoder } from '@ethersproject/abi'; import { isAddress } from '@ethersproject/address'; @@ -55,8 +55,8 @@ export class GaslessVotingClientEncoding params: GaslessVotingPluginInstall, network: Networkish ): PluginInstallItem { - const networkName = getNetwork(network).name as SupportedNetwork; - if (!SupportedNetworksArray.includes(networkName)) { + const networkName = getNetwork(network).name as SupportedNetworks; + if (!Object.keys(DEFAULT_ADDRESSES).includes(networkName)) { throw new UnsupportedNetworkError(networkName); } const args = initParamsToContract(params); @@ -92,16 +92,14 @@ export class GaslessVotingClientEncoding }; } - /** + /** * Computes the parameters to be given when creating a proposal that updates the governance configuration * * @param {AddAddressesParams} params * @return {*} {DaoAction[]} * @memberof GaslessVotingClientEncoding */ - public addAddressesAction( - params: AddAddressesParams, - ): DaoAction { + public addAddressesAction(params: AddAddressesParams): DaoAction { if (!isAddress(params.pluginAddress)) { throw new InvalidAddressError(); } @@ -114,8 +112,8 @@ export class GaslessVotingClientEncoding const votingInterface = VocdoniVoting__factory.createInterface(); // get hex bytes const hexBytes = votingInterface.encodeFunctionData( - "addExecutionMultisigMembers", - [params.members], + 'addExecutionMultisigMembers', + [params.members] ); return { to: params.pluginAddress, @@ -130,9 +128,7 @@ export class GaslessVotingClientEncoding * @return {*} {DaoAction[]} * @memberof GaslessVotingClientEncoding */ - public removeAddressesAction( - params: RemoveAddressesParams, - ): DaoAction { + public removeAddressesAction(params: RemoveAddressesParams): DaoAction { if (!isAddress(params.pluginAddress)) { throw new InvalidAddressError(); } @@ -145,8 +141,8 @@ export class GaslessVotingClientEncoding const votingInterface = VocdoniVoting__factory.createInterface(); // get hex bytes const hexBytes = votingInterface.encodeFunctionData( - "removeExecutionMultisigMembers", - [params.members], + 'removeExecutionMultisigMembers', + [params.members] ); return { to: params.pluginAddress, @@ -165,7 +161,7 @@ export class GaslessVotingClientEncoding // 'updatePluginSettings((bool,uint16,uint32,uint32,uint64,uint64,address,uint256,string))' // ); const hexBytes = votingInterface.encodeFunctionData( - "updatePluginSettings", + 'updatePluginSettings', [ { onlyExecutionMultisigProposalCreation: args[0],