@reyaxyz/community-sdk 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/client/index.js +10 -13
  2. package/dist/client/index.js.map +1 -1
  3. package/dist/index.js +0 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/modules/twitter/services/get-auth-url/index.js +1 -1
  6. package/dist/modules/twitter/services/get-auth-url/index.js.map +1 -1
  7. package/dist/modules/vote/index.js +33 -10
  8. package/dist/modules/vote/index.js.map +1 -1
  9. package/dist/modules/vote/services/executeTransaction.js +99 -0
  10. package/dist/modules/vote/services/executeTransaction.js.map +1 -0
  11. package/dist/modules/vote/services/get-vote-details/index.js.map +1 -1
  12. package/dist/modules/vote/services/get-vote-status/index.js.map +1 -1
  13. package/dist/modules/vote/services/index.js +0 -3
  14. package/dist/modules/vote/services/index.js.map +1 -1
  15. package/dist/modules/vote/services/vote/encode.js +14 -0
  16. package/dist/modules/vote/services/vote/encode.js.map +1 -0
  17. package/dist/modules/vote/services/vote/index.js +22 -21
  18. package/dist/modules/vote/services/vote/index.js.map +1 -1
  19. package/dist/modules/vote/types.js.map +1 -0
  20. package/dist/types/client/index.d.ts +2 -5
  21. package/dist/types/client/index.d.ts.map +1 -1
  22. package/dist/types/index.d.ts +0 -4
  23. package/dist/types/index.d.ts.map +1 -1
  24. package/dist/types/modules/twitter/services/get-auth-url/index.d.ts.map +1 -1
  25. package/dist/types/modules/vote/index.d.ts +6 -8
  26. package/dist/types/modules/vote/index.d.ts.map +1 -1
  27. package/dist/types/modules/vote/services/executeTransaction.d.ts +13 -0
  28. package/dist/types/modules/vote/services/executeTransaction.d.ts.map +1 -0
  29. package/dist/types/modules/vote/services/get-vote-details/index.d.ts +1 -1
  30. package/dist/types/modules/vote/services/get-vote-details/index.d.ts.map +1 -1
  31. package/dist/types/modules/vote/services/get-vote-status/index.d.ts +1 -1
  32. package/dist/types/modules/vote/services/get-vote-status/index.d.ts.map +1 -1
  33. package/dist/types/modules/vote/services/index.d.ts +0 -3
  34. package/dist/types/modules/vote/services/index.d.ts.map +1 -1
  35. package/dist/types/modules/vote/services/vote/encode.d.ts +3 -0
  36. package/dist/types/modules/vote/services/vote/encode.d.ts.map +1 -0
  37. package/dist/types/modules/vote/services/vote/index.d.ts +2 -2
  38. package/dist/types/modules/vote/services/vote/index.d.ts.map +1 -1
  39. package/dist/types/modules/vote/types.d.ts +20 -0
  40. package/dist/types/modules/vote/types.d.ts.map +1 -0
  41. package/dist/types/utils/action.d.ts +11 -0
  42. package/dist/types/utils/action.d.ts.map +1 -0
  43. package/dist/types/utils/contractAddresses.d.ts +7 -0
  44. package/dist/types/utils/contractAddresses.d.ts.map +1 -0
  45. package/dist/{modules/vote/services/get-vote-status/types.js → utils/action.js} +1 -1
  46. package/dist/utils/action.js.map +1 -0
  47. package/dist/utils/contractAddresses.js +39 -0
  48. package/dist/utils/contractAddresses.js.map +1 -0
  49. package/package.json +4 -3
  50. package/src/client/index.ts +11 -21
  51. package/src/index.ts +0 -4
  52. package/src/modules/twitter/services/get-auth-url/index.ts +3 -1
  53. package/src/modules/vote/index.ts +13 -19
  54. package/src/modules/vote/services/executeTransaction.ts +58 -0
  55. package/src/modules/vote/services/get-vote-details/index.ts +2 -2
  56. package/src/modules/vote/services/get-vote-status/index.ts +2 -2
  57. package/src/modules/vote/services/index.ts +0 -3
  58. package/src/modules/vote/services/vote/encode.ts +12 -0
  59. package/src/modules/vote/services/vote/index.ts +21 -17
  60. package/src/modules/vote/types.ts +23 -0
  61. package/src/utils/action.ts +10 -0
  62. package/src/utils/contractAddresses.ts +43 -0
  63. package/dist/client/constants.js +0 -24
  64. package/dist/client/constants.js.map +0 -1
  65. package/dist/modules/vote/services/get-vote-details/types.js.map +0 -1
  66. package/dist/modules/vote/services/get-vote-status/types.js.map +0 -1
  67. package/dist/modules/vote/services/vote/types.js +0 -3
  68. package/dist/modules/vote/services/vote/types.js.map +0 -1
  69. package/dist/types/client/constants.d.ts +0 -12
  70. package/dist/types/client/constants.d.ts.map +0 -1
  71. package/dist/types/modules/vote/services/get-vote-details/types.d.ts +0 -6
  72. package/dist/types/modules/vote/services/get-vote-details/types.d.ts.map +0 -1
  73. package/dist/types/modules/vote/services/get-vote-status/types.d.ts +0 -7
  74. package/dist/types/modules/vote/services/get-vote-status/types.d.ts.map +0 -1
  75. package/dist/types/modules/vote/services/vote/types.d.ts +0 -11
  76. package/dist/types/modules/vote/services/vote/types.d.ts.map +0 -1
  77. package/dist/types/types.d.ts +0 -13
  78. package/dist/types/types.d.ts.map +0 -1
  79. package/dist/types.js +0 -3
  80. package/dist/types.js.map +0 -1
  81. package/src/client/constants.ts +0 -34
  82. package/src/modules/vote/services/get-vote-details/types.ts +0 -6
  83. package/src/modules/vote/services/get-vote-status/types.ts +0 -7
  84. package/src/modules/vote/services/vote/types.ts +0 -11
  85. package/src/types.ts +0 -13
  86. /package/dist/modules/vote/{services/get-vote-details/types.js → types.js} +0 -0
@@ -0,0 +1,20 @@
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
+ import { VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
3
+ export type VoteResult = {
4
+ transactionHash: string | null;
5
+ };
6
+ export type GetVoteDetailsParams = {
7
+ id: VoteDetailsEntity['id'];
8
+ };
9
+ export type GetVoteDetailsResult = VoteDetailsEntity;
10
+ export type VoteParams = {
11
+ id: VoteDetailsEntity['id'];
12
+ voted: 'yes' | 'no';
13
+ signer: Signer | JsonRpcSigner;
14
+ };
15
+ export type GetVoteStatusParams = {
16
+ address: string;
17
+ id: VoteDetailsEntity['id'];
18
+ };
19
+ export type GetVoteStatusResult = VoteStatusEntity;
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type MethodParameters = {
2
+ /**
3
+ * The hex encoded calldata to perform the given operation
4
+ */
5
+ calldata: string;
6
+ /**
7
+ * The amount of ether (wei) to send in hex.
8
+ */
9
+ value: string;
10
+ };
11
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"/","sources":["utils/action.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type Address = Lowercase<string>;
2
+ export declare enum ContractType {
3
+ COMMUNITY_DEPLOYER = "community_deployer",
4
+ RANKS_PROXY = "ranks_proxy"
5
+ }
6
+ export declare const getAddress: (chainId: number, contractName: ContractType) => string;
7
+ //# sourceMappingURL=contractAddresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contractAddresses.d.ts","sourceRoot":"/","sources":["utils/contractAddresses.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAIxC,oBAAY,YAAY;IACtB,kBAAkB,uBAAuB;IACzC,WAAW,gBAAgB;CAC5B;AAmBD,eAAO,MAAM,UAAU,YACZ,MAAM,gBACD,YAAY,KACzB,MAaF,CAAC"}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
3
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","sourceRoot":"/","sources":["utils/action.ts"],"names":[],"mappings":"","sourcesContent":["export type MethodParameters = {\n /**\n * The hex encoded calldata to perform the given operation\n */\n calldata: string;\n /**\n * The amount of ether (wei) to send in hex.\n */\n value: string;\n};\n"]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var _a, _b, _c, _d;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getAddress = exports.ContractType = void 0;
5
+ // @todo update with proper chainId for mainnet
6
+ var common_1 = require("@reyaxyz/common");
7
+ var ContractType;
8
+ (function (ContractType) {
9
+ ContractType["COMMUNITY_DEPLOYER"] = "community_deployer";
10
+ ContractType["RANKS_PROXY"] = "ranks_proxy";
11
+ })(ContractType || (exports.ContractType = ContractType = {}));
12
+ var addresses = (_a = {},
13
+ _a[common_1.ReyaChainId.polygonMumbai] = (_b = {},
14
+ // todo replace with mapping from id to contract address
15
+ _b[ContractType.COMMUNITY_DEPLOYER] = '0x69b480a57eb3ab98d68c5d5590ad63bf4d5eb3f7',
16
+ _b[ContractType.RANKS_PROXY] = '0xf2a1fca4f1e08f84eef135395b6e8df7cb02d59f',
17
+ _b),
18
+ _a[common_1.ReyaChainId.reyaCronos] = (_c = {},
19
+ _c[ContractType.COMMUNITY_DEPLOYER] = 'todo',
20
+ _c[ContractType.RANKS_PROXY] = 'todo',
21
+ _c),
22
+ _a[common_1.ReyaChainId.reyaNetwork] = (_d = {},
23
+ _d[ContractType.COMMUNITY_DEPLOYER] = 'todo',
24
+ _d[ContractType.RANKS_PROXY] = 'todo',
25
+ _d),
26
+ _a);
27
+ var getAddress = function (chainId, contractName) {
28
+ var keyChainId = chainId.toString();
29
+ if (!Object.keys(addresses).includes(keyChainId)) {
30
+ return "Unspecified addresses for chain id ".concat(keyChainId);
31
+ }
32
+ var networkAddresses = addresses[chainId];
33
+ if (!Object.keys(networkAddresses).includes(contractName)) {
34
+ return "Unspecified address for ".concat(contractName, " contract");
35
+ }
36
+ return networkAddresses[contractName];
37
+ };
38
+ exports.getAddress = getAddress;
39
+ //# sourceMappingURL=contractAddresses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contractAddresses.js","sourceRoot":"/","sources":["utils/contractAddresses.ts"],"names":[],"mappings":";;;;AACA,+CAA+C;AAC/C,0CAA8C;AAE9C,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,yDAAyC,CAAA;IACzC,2CAA2B,CAAA;AAC7B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAM,SAAS;IACb,GAAC,oBAAW,CAAC,aAAa;QACxB,wDAAwD;QACxD,GAAC,YAAY,CAAC,kBAAkB,IAC9B,4CAA4C;QAC9C,GAAC,YAAY,CAAC,WAAW,IAAG,4CAA4C;WACzE;IACD,GAAC,oBAAW,CAAC,UAAU;QACrB,GAAC,YAAY,CAAC,kBAAkB,IAAG,MAAM;QACzC,GAAC,YAAY,CAAC,WAAW,IAAG,MAAM;WACnC;IACD,GAAC,oBAAW,CAAC,WAAW;QACtB,GAAC,YAAY,CAAC,kBAAkB,IAAG,MAAM;QACzC,GAAC,YAAY,CAAC,WAAW,IAAG,MAAM;WACnC;OACF,CAAC;AAEK,IAAM,UAAU,GAAG,UACxB,OAAe,EACf,YAA0B;IAE1B,IAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAEtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACjD,OAAO,6CAAsC,UAAU,CAAE,CAAC;IAC5D,CAAC;IAED,IAAM,gBAAgB,GAAG,SAAS,CAAC,OAAsB,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1D,OAAO,kCAA2B,YAAY,cAAW,CAAC;IAC5D,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB","sourcesContent":["export type Address = Lowercase<string>;\n// @todo update with proper chainId for mainnet\nimport { ReyaChainId } from '@reyaxyz/common';\n\nexport enum ContractType {\n COMMUNITY_DEPLOYER = 'community_deployer',\n RANKS_PROXY = 'ranks_proxy',\n}\n\nconst addresses: Record<ReyaChainId, Record<ContractType, Address>> = {\n [ReyaChainId.polygonMumbai]: {\n // todo replace with mapping from id to contract address\n [ContractType.COMMUNITY_DEPLOYER]:\n '0x69b480a57eb3ab98d68c5d5590ad63bf4d5eb3f7',\n [ContractType.RANKS_PROXY]: '0xf2a1fca4f1e08f84eef135395b6e8df7cb02d59f',\n },\n [ReyaChainId.reyaCronos]: {\n [ContractType.COMMUNITY_DEPLOYER]: 'todo',\n [ContractType.RANKS_PROXY]: 'todo',\n },\n [ReyaChainId.reyaNetwork]: {\n [ContractType.COMMUNITY_DEPLOYER]: 'todo',\n [ContractType.RANKS_PROXY]: 'todo',\n },\n};\n\nexport const getAddress = (\n chainId: number,\n contractName: ContractType,\n): string => {\n const keyChainId = chainId.toString();\n\n if (!Object.keys(addresses).includes(keyChainId)) {\n return `Unspecified addresses for chain id ${keyChainId}`;\n }\n\n const networkAddresses = addresses[chainId as ReyaChainId];\n if (!Object.keys(networkAddresses).includes(contractName)) {\n return `Unspecified address for ${contractName} contract`;\n }\n\n return networkAddresses[contractName];\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/community-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -10,7 +10,8 @@
10
10
  "url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
11
11
  },
12
12
  "dependencies": {
13
- "@reyaxyz/common": "0.31.0",
13
+ "@reyaxyz/common": "0.32.0",
14
+ "@reyaxyz/sdk": "0.28.3",
14
15
  "ethers": "6.9.0"
15
16
  },
16
17
  "main": "dist/index.js",
@@ -37,5 +38,5 @@
37
38
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
38
39
  },
39
40
  "packageManager": "pnpm@8.10.4",
40
- "gitHead": "03560eb9a08e7255cd37ac46825ceba99559c654"
41
+ "gitHead": "02adcc4ee5dca3ee79d437dbb92ae583cb55ee96"
41
42
  }
@@ -1,42 +1,32 @@
1
- import { SERVICE_CONFIG, ServiceConfig } from './constants';
1
+ import { API_CLIENT_CONFIGS, ServiceConfig } from '@reyaxyz/common';
2
2
  import VoteModule from '../modules/vote';
3
3
  import LGEModule from '../modules/lge';
4
4
  import TwitterModule from '../modules/twitter';
5
5
 
6
- export type ConfigureParams = {
7
- environment: ServiceConfig['environment'];
8
- };
9
-
10
6
  /**
11
7
  * @description Client for Community SDK
12
8
  */
13
9
  export class CommunityClient {
14
10
  private static instance: CommunityClient;
15
- private static config: ServiceConfig = SERVICE_CONFIG['test'];
11
+ private static config: ServiceConfig = API_CLIENT_CONFIGS['test'];
12
+
16
13
  private readonly _vote: VoteModule;
17
14
  private readonly _LGE: LGEModule;
18
15
  private readonly _twitter: TwitterModule;
19
16
 
20
- private constructor(params: ConfigureParams) {
21
- CommunityClient.config = SERVICE_CONFIG[params.environment];
22
- this._vote = new VoteModule(CommunityClient.config.chainId);
23
- this._LGE = new LGEModule(CommunityClient.config.chainId);
17
+ private constructor() {
18
+ this._vote = new VoteModule(CommunityClient.config.apiEndpoint);
19
+ this._LGE = new LGEModule(CommunityClient.config.chain);
24
20
  this._twitter = new TwitterModule(
25
21
  CommunityClient.config.twitter.redirectURI,
26
22
  CommunityClient.config.twitter.clientId,
27
23
  );
28
24
  }
29
25
 
30
- public static configure(params: ConfigureParams): void {
31
- if (
32
- !params.environment ||
33
- ['test', 'production'].indexOf(params.environment) === -1
34
- ) {
35
- throw new Error(
36
- 'Client environment is incorrect or not provided. Consult the docs about ConfigureParams.',
37
- );
38
- }
39
- CommunityClient.instance = new CommunityClient(params);
26
+ public static configure(environment: ServiceConfig['environment']): void {
27
+ CommunityClient.config =
28
+ API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];
29
+ CommunityClient.instance = new CommunityClient();
40
30
  }
41
31
 
42
32
  private static getInstance(): CommunityClient {
@@ -82,6 +72,6 @@ export class CommunityClient {
82
72
  }
83
73
 
84
74
  public static get supportedChain(): number {
85
- return CommunityClient.config.chainId;
75
+ return CommunityClient.config.chain;
86
76
  }
87
77
  }
package/src/index.ts CHANGED
@@ -1,8 +1,4 @@
1
- export * from './types';
2
1
  export * from './client';
3
- export * from './modules/vote/services/get-vote-details/types';
4
- export * from './modules/vote/services/get-vote-status/types';
5
- export * from './modules/vote/services/vote/types';
6
2
  export * from './modules/lge/services/get-account-lge-status/types';
7
3
  export * from './modules/lge/services/get-lge-boost-rate/types';
8
4
  export * from './modules/twitter/services/get-auth-url/types';
@@ -14,7 +14,9 @@ export function getTwitterOauthUrl({
14
14
  response_type: 'code',
15
15
  code_challenge: 'challenge',
16
16
  code_challenge_method: 'plain',
17
- scope: ['users.read', 'tweet.write'].join(' '),
17
+ scope: ['users.read', 'tweet.write', 'tweet.read', 'follows.read'].join(
18
+ ' ',
19
+ ),
18
20
  };
19
21
  const qs = new URLSearchParams(options).toString();
20
22
  return `${rootUrl}?${qs}`;
@@ -1,29 +1,23 @@
1
- import { ReyaChainId } from '@reyaxyz/common';
2
- import {
3
- getVoteDetails,
4
- GetVoteDetailsParams,
5
- getVoteStatus,
6
- GetVoteStatusParams,
7
- vote,
8
- VoteParams,
9
- } from './services';
1
+ import { RestClient } from '@reyaxyz/common';
2
+ import { GetVoteDetailsParams, GetVoteStatusParams, VoteParams } from './types';
3
+ import { vote } from './services';
10
4
 
11
- export default class VoteModule {
12
- private chainId: ReyaChainId;
5
+ export default class VoteModule extends RestClient {
6
+ // WRITE
13
7
 
14
- constructor(chainId: ReyaChainId) {
15
- this.chainId = chainId;
8
+ async vote(params: VoteParams) {
9
+ return vote(params);
16
10
  }
17
11
 
12
+ // READ
13
+
18
14
  async getVoteDetails(params: GetVoteDetailsParams) {
19
- return getVoteDetails(params);
15
+ const uri = `/api/vote/${params.id}`;
16
+ return this.get(uri);
20
17
  }
21
18
 
22
19
  async getVoteStatus(params: GetVoteStatusParams) {
23
- return getVoteStatus(params);
24
- }
25
-
26
- async vote(params: VoteParams) {
27
- return vote(params);
20
+ const uri = `/api/vote/${params.id}/user/${params.address}`;
21
+ return this.get(uri);
28
22
  }
29
23
  }
@@ -0,0 +1,58 @@
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
+ import { ContractType, getAddress } from '../../../utils/contractAddresses';
3
+
4
+ export type Transaction = {
5
+ from: string;
6
+ to: string;
7
+ data: string;
8
+ value?: string;
9
+ };
10
+
11
+ export async function estimateGas(
12
+ signer: Signer | JsonRpcSigner,
13
+ data: string,
14
+ value: string,
15
+ chainId: number,
16
+ targetContract: ContractType | string,
17
+ ): Promise<Transaction & { gasLimit: bigint }> {
18
+ const accountAddress = await signer.getAddress();
19
+ const contractAddress = Object.values(ContractType).includes(
20
+ targetContract as ContractType,
21
+ )
22
+ ? getAddress(chainId, targetContract as ContractType)
23
+ : targetContract;
24
+ const tx = {
25
+ from: accountAddress,
26
+ to: contractAddress,
27
+ data,
28
+ ...(value && value !== '0' ? { value: value } : {}),
29
+ };
30
+
31
+ const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit
32
+ return { ...tx, gasLimit };
33
+ }
34
+
35
+ export async function executeTransaction(
36
+ signer: Signer | JsonRpcSigner,
37
+ data: string,
38
+ value: string,
39
+ chainId: number,
40
+ targetContract: ContractType | string,
41
+ ) {
42
+ const txData = await estimateGas(
43
+ signer,
44
+ data,
45
+ value,
46
+ chainId,
47
+ targetContract,
48
+ );
49
+
50
+ try {
51
+ const txResponse = await signer.sendTransaction(txData);
52
+ const txReceipt = await txResponse.wait();
53
+ return txReceipt;
54
+ } catch (error) {
55
+ console.warn(error);
56
+ throw new Error('Transaction Execution Error');
57
+ }
58
+ }
@@ -1,5 +1,5 @@
1
- import { VoteDetailsEntity } from '../../../../types';
2
- import { GetVoteDetailsParams, GetVoteDetailsResult } from './types';
1
+ import { VoteDetailsEntity } from '@reyaxyz/common';
2
+ import { GetVoteDetailsParams, GetVoteDetailsResult } from '../../types';
3
3
 
4
4
  function mockVoteEntity(id: number): VoteDetailsEntity {
5
5
  const daysToAdd = Math.floor(Math.random() * (30 - 14 + 1)) + 14; // Random days between 14 and 30
@@ -1,5 +1,5 @@
1
- import { VoteStatusEntity } from '../../../../types';
2
- import { GetVoteStatusParams, GetVoteStatusResult } from './types';
1
+ import { VoteStatusEntity } from '@reyaxyz/common';
2
+ import { GetVoteStatusParams, GetVoteStatusResult } from '../../types';
3
3
 
4
4
  function mockVoteStatusEntity(): VoteStatusEntity {
5
5
  return {
@@ -1,6 +1,3 @@
1
1
  export * from './get-vote-details';
2
2
  export * from './get-vote-status';
3
3
  export * from './vote';
4
- export * from './get-vote-details/types';
5
- export * from './get-vote-status/types';
6
- export * from './vote/types';
@@ -0,0 +1,12 @@
1
+ import { Interface } from 'ethers';
2
+ import { MethodParameters } from '../../../../utils/action';
3
+
4
+ const castVoteabi = ['function castVote(bool yesVote)'];
5
+
6
+ export const encodeCastVote = (yesVote: boolean): MethodParameters => {
7
+ const functionSignature = 'castVote';
8
+ const parameters = [yesVote];
9
+ const INTERFACE = new Interface(castVoteabi);
10
+ const calldata = INTERFACE.encodeFunctionData(functionSignature, parameters);
11
+ return { calldata: calldata, value: BigInt(0).toString(10) };
12
+ };
@@ -1,19 +1,23 @@
1
- import { VoteParams, VoteResult } from './types';
1
+ import { ContractType } from '../../../../utils/contractAddresses';
2
+ import { executeTransaction } from '../executeTransaction';
3
+ import { encodeCastVote } from './encode';
4
+ import { VoteParams, VoteResult } from '../../types';
2
5
 
3
- // TODO: Write proper implementation
4
- export const vote = async ({ id }: VoteParams): Promise<VoteResult> => {
5
- return await new Promise((resolve, reject) => {
6
- setTimeout(
7
- () => {
8
- const error = Math.random() * 100 > 50;
9
- if (error) {
10
- reject(new Error(`Vote ${id} error`));
11
- }
12
- resolve({
13
- transactionHash: '0x123fake',
14
- });
15
- },
16
- Math.random() * 100 + 1000,
17
- );
18
- });
6
+ export const vote = async (params: VoteParams): Promise<VoteResult> => {
7
+ const { calldata: data, value } = encodeCastVote(params.voted == 'yes');
8
+
9
+ const network = await params.signer.provider?.getNetwork();
10
+ const chainId = Number(network?.chainId);
11
+
12
+ const result = await executeTransaction(
13
+ params.signer,
14
+ data,
15
+ value,
16
+ chainId,
17
+ ContractType.COMMUNITY_DEPLOYER,
18
+ );
19
+
20
+ return {
21
+ transactionHash: result?.hash || null,
22
+ };
19
23
  };
@@ -0,0 +1,23 @@
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
+ import { VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
3
+
4
+ export type VoteResult = {
5
+ transactionHash: string | null;
6
+ };
7
+
8
+ export type GetVoteDetailsParams = {
9
+ id: VoteDetailsEntity['id'];
10
+ };
11
+ export type GetVoteDetailsResult = VoteDetailsEntity;
12
+
13
+ export type VoteParams = {
14
+ id: VoteDetailsEntity['id'];
15
+ voted: 'yes' | 'no';
16
+ signer: Signer | JsonRpcSigner;
17
+ };
18
+
19
+ export type GetVoteStatusParams = {
20
+ address: string;
21
+ id: VoteDetailsEntity['id'];
22
+ };
23
+ export type GetVoteStatusResult = VoteStatusEntity;
@@ -0,0 +1,10 @@
1
+ export type MethodParameters = {
2
+ /**
3
+ * The hex encoded calldata to perform the given operation
4
+ */
5
+ calldata: string;
6
+ /**
7
+ * The amount of ether (wei) to send in hex.
8
+ */
9
+ value: string;
10
+ };
@@ -0,0 +1,43 @@
1
+ export type Address = Lowercase<string>;
2
+ // @todo update with proper chainId for mainnet
3
+ import { ReyaChainId } from '@reyaxyz/common';
4
+
5
+ export enum ContractType {
6
+ COMMUNITY_DEPLOYER = 'community_deployer',
7
+ RANKS_PROXY = 'ranks_proxy',
8
+ }
9
+
10
+ const addresses: Record<ReyaChainId, Record<ContractType, Address>> = {
11
+ [ReyaChainId.polygonMumbai]: {
12
+ // todo replace with mapping from id to contract address
13
+ [ContractType.COMMUNITY_DEPLOYER]:
14
+ '0x69b480a57eb3ab98d68c5d5590ad63bf4d5eb3f7',
15
+ [ContractType.RANKS_PROXY]: '0xf2a1fca4f1e08f84eef135395b6e8df7cb02d59f',
16
+ },
17
+ [ReyaChainId.reyaCronos]: {
18
+ [ContractType.COMMUNITY_DEPLOYER]: 'todo',
19
+ [ContractType.RANKS_PROXY]: 'todo',
20
+ },
21
+ [ReyaChainId.reyaNetwork]: {
22
+ [ContractType.COMMUNITY_DEPLOYER]: 'todo',
23
+ [ContractType.RANKS_PROXY]: 'todo',
24
+ },
25
+ };
26
+
27
+ export const getAddress = (
28
+ chainId: number,
29
+ contractName: ContractType,
30
+ ): string => {
31
+ const keyChainId = chainId.toString();
32
+
33
+ if (!Object.keys(addresses).includes(keyChainId)) {
34
+ return `Unspecified addresses for chain id ${keyChainId}`;
35
+ }
36
+
37
+ const networkAddresses = addresses[chainId as ReyaChainId];
38
+ if (!Object.keys(networkAddresses).includes(contractName)) {
39
+ return `Unspecified address for ${contractName} contract`;
40
+ }
41
+
42
+ return networkAddresses[contractName];
43
+ };
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SERVICE_CONFIG = void 0;
4
- var common_1 = require("@reyaxyz/common");
5
- exports.SERVICE_CONFIG = {
6
- production: {
7
- environment: 'production',
8
- chainId: common_1.ReyaChainId.reyaNetwork,
9
- // todo: change to production creds when new app is created
10
- twitter: {
11
- clientId: 'LTBKa25VWkpjaEtSMzRGVEZaYmU6MTpjaQ',
12
- redirectURI: 'https://m8mjgmqmte.eu-central-1.awsapprunner.com/api/twitter/share',
13
- },
14
- },
15
- test: {
16
- environment: 'test',
17
- chainId: common_1.ReyaChainId.reyaCronos,
18
- twitter: {
19
- clientId: 'LTBKa25VWkpjaEtSMzRGVEZaYmU6MTpjaQ',
20
- redirectURI: 'https://m8mjgmqmte.eu-central-1.awsapprunner.com/api/twitter/share',
21
- },
22
- },
23
- };
24
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"/","sources":["client/constants.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAajC,QAAA,cAAc,GAA8C;IACvE,UAAU,EAAE;QACV,WAAW,EAAE,YAAY;QACzB,OAAO,EAAE,oBAAW,CAAC,WAAW;QAChC,2DAA2D;QAC3D,OAAO,EAAE;YACP,QAAQ,EAAE,oCAAoC;YAC9C,WAAW,EACT,oEAAoE;SACvE;KACF;IACD,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM;QACnB,OAAO,EAAE,oBAAW,CAAC,UAAU;QAC/B,OAAO,EAAE;YACP,QAAQ,EAAE,oCAAoC;YAC9C,WAAW,EACT,oEAAoE;SACvE;KACF;CACF,CAAC","sourcesContent":["import { ReyaChainId } from '@reyaxyz/common';\n\nexport type ServiceEnvironment = 'production' | 'test';\n\nexport type ServiceConfig = {\n chainId: ReyaChainId;\n twitter: {\n clientId: string;\n redirectURI: string;\n };\n environment: ServiceEnvironment;\n};\n\nexport const SERVICE_CONFIG: Record<ServiceEnvironment, ServiceConfig> = {\n production: {\n environment: 'production',\n chainId: ReyaChainId.reyaNetwork,\n // todo: change to production creds when new app is created\n twitter: {\n clientId: 'LTBKa25VWkpjaEtSMzRGVEZaYmU6MTpjaQ',\n redirectURI:\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com/api/twitter/share',\n },\n },\n test: {\n environment: 'test',\n chainId: ReyaChainId.reyaCronos,\n twitter: {\n clientId: 'LTBKa25VWkpjaEtSMzRGVEZaYmU6MTpjaQ',\n redirectURI:\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com/api/twitter/share',\n },\n },\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/services/get-vote-details/types.ts"],"names":[],"mappings":"","sourcesContent":["import { VoteDetailsEntity } from '../../../../types';\n\nexport type GetVoteDetailsParams = {\n id: VoteDetailsEntity['id'];\n};\nexport type GetVoteDetailsResult = VoteDetailsEntity;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/services/get-vote-status/types.ts"],"names":[],"mappings":"","sourcesContent":["import { VoteDetailsEntity, VoteStatusEntity } from '../../../../types';\n\nexport type GetVoteStatusParams = {\n address: string;\n id: VoteDetailsEntity['id'];\n};\nexport type GetVoteStatusResult = VoteStatusEntity;\n"]}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/services/vote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { VoteDetailsEntity } from '../../../../types';\nimport { JsonRpcSigner, Signer } from 'ethers';\n\nexport type VoteParams = {\n id: VoteDetailsEntity['id'];\n voted: 'yes' | 'no';\n signer: Signer | JsonRpcSigner;\n};\nexport type VoteResult = {\n transactionHash: string;\n};\n"]}
@@ -1,12 +0,0 @@
1
- import { ReyaChainId } from '@reyaxyz/common';
2
- export type ServiceEnvironment = 'production' | 'test';
3
- export type ServiceConfig = {
4
- chainId: ReyaChainId;
5
- twitter: {
6
- clientId: string;
7
- redirectURI: string;
8
- };
9
- environment: ServiceEnvironment;
10
- };
11
- export declare const SERVICE_CONFIG: Record<ServiceEnvironment, ServiceConfig>;
12
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["client/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,WAAW,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAoBpE,CAAC"}
@@ -1,6 +0,0 @@
1
- import { VoteDetailsEntity } from '../../../../types';
2
- export type GetVoteDetailsParams = {
3
- id: VoteDetailsEntity['id'];
4
- };
5
- export type GetVoteDetailsResult = VoteDetailsEntity;
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/services/get-vote-details/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC"}
@@ -1,7 +0,0 @@
1
- import { VoteDetailsEntity, VoteStatusEntity } from '../../../../types';
2
- export type GetVoteStatusParams = {
3
- address: string;
4
- id: VoteDetailsEntity['id'];
5
- };
6
- export type GetVoteStatusResult = VoteStatusEntity;
7
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/services/get-vote-status/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC"}
@@ -1,11 +0,0 @@
1
- import { VoteDetailsEntity } from '../../../../types';
2
- import { JsonRpcSigner, Signer } from 'ethers';
3
- export type VoteParams = {
4
- id: VoteDetailsEntity['id'];
5
- voted: 'yes' | 'no';
6
- signer: Signer | JsonRpcSigner;
7
- };
8
- export type VoteResult = {
9
- transactionHash: string;
10
- };
11
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/services/vote/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
@@ -1,13 +0,0 @@
1
- export type VoteDetailsEntity = {
2
- id: number;
3
- startDate: number;
4
- endDate: number;
5
- percentageToPass: number;
6
- yesCount: number;
7
- noCount: number;
8
- };
9
- export type VoteStatusEntity = {
10
- votingPower: number;
11
- hasVoted: boolean;
12
- };
13
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC"}
package/dist/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type VoteDetailsEntity = {\n id: number;\n startDate: number; // timestamp in UTC milliseconds\n endDate: number; // timestamp in UTC milliseconds\n percentageToPass: number; // Example: 4%\n yesCount: number;\n noCount: number;\n};\n\nexport type VoteStatusEntity = {\n votingPower: number;\n hasVoted: boolean;\n};\n"]}