Skip to content

Commit

Permalink
Version bump @vocdoni/[email protected] solving graqhql issue
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdim committed Mar 1, 2024
1 parent 8238bda commit 979f2da
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 37 deletions.
5 changes: 3 additions & 2 deletions packages/js-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
55 changes: 54 additions & 1 deletion packages/js-client/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
},
];
}
}
22 changes: 8 additions & 14 deletions packages/js-client/src/internal/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: '',
},
Expand All @@ -70,10 +68,6 @@ export const DEFAULT_ADDRESSES: {
setupAddress: '',
repoAddress: '',
},
arbitrumGoerli: {
setupAddress: '',
repoAddress: '',
},
arbitrumSepolia: {
setupAddress: '',
repoAddress: '',
Expand Down
36 changes: 16 additions & 20 deletions packages/js-client/src/internal/modules/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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,
Expand All @@ -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();
}
Expand All @@ -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,
Expand All @@ -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],
Expand Down

0 comments on commit 979f2da

Please sign in to comment.