@reyaxyz/community-sdk 0.52.47 → 0.53.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.
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
29
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
30
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -59,6 +70,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
59
70
  Object.defineProperty(exports, "__esModule", { value: true });
60
71
  var common_1 = require("@reyaxyz/common");
61
72
  var common_2 = require("@reyaxyz/common");
73
+ var services_1 = require("./services");
62
74
  var VoteModule = /** @class */ (function (_super) {
63
75
  __extends(VoteModule, _super);
64
76
  function VoteModule(apiUrl, loggingEnabled) {
@@ -70,8 +82,33 @@ var VoteModule = /** @class */ (function (_super) {
70
82
  // WRITE
71
83
  VoteModule.prototype.vote = function (params) {
72
84
  return __awaiter(this, void 0, void 0, function () {
73
- return __generator(this, function (_a) {
74
- throw new Error('Unimplemented.');
85
+ var infoUri, infoMetadata, _a, signature, signatureDeadline, voteUri, result, _b, _c;
86
+ var _d;
87
+ return __generator(this, function (_e) {
88
+ switch (_e.label) {
89
+ case 0:
90
+ infoUri = "/api/vote/contract-details/".concat(params.slug);
91
+ return [4 /*yield*/, this.get(infoUri)];
92
+ case 1:
93
+ infoMetadata = _e.sent();
94
+ return [4 /*yield*/, (0, services_1.sendVote)(__assign(__assign({}, params), { contractAddress: infoMetadata.contractAddress }))];
95
+ case 2:
96
+ _a = _e.sent(), signature = _a.signature, signatureDeadline = _a.deadline;
97
+ voteUri = "/api/vote/".concat(infoMetadata.contractAddress, "/vote");
98
+ _b = this.put;
99
+ _c = [voteUri,
100
+ {}];
101
+ _d = {};
102
+ return [4 /*yield*/, params.signer.getAddress()];
103
+ case 3: return [4 /*yield*/, _b.apply(this, _c.concat([(_d.voter = _e.sent(),
104
+ _d.isYesVote = params.voted,
105
+ _d.signature = signature,
106
+ _d.signatureDeadline = signatureDeadline,
107
+ _d)]))];
108
+ case 4:
109
+ result = _e.sent();
110
+ return [2 /*return*/, { transactionHash: result.txHash }];
111
+ }
75
112
  });
76
113
  });
77
114
  };
@@ -107,7 +144,6 @@ var VoteModule = /** @class */ (function (_super) {
107
144
  };
108
145
  __decorate([
109
146
  (0, common_2.Logger)('VoteModule.vote')
110
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
147
  ], VoteModule.prototype, "vote", null);
112
148
  __decorate([
113
149
  (0, common_2.Logger)('VoteModule.getVoteDetails')
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAS7C,0CAAmD;AAEnD;IAAwC,8BAAU;IAGhD,oBAAY,MAAc,EAAE,cAAuB;QACjD,YAAA,MAAK,YAAC,MAAM,CAAC,SAAC;QAHhB,oBAAc,GAAY,KAAK,CAAC;QAI9B,KAAI,CAAC,cAAc,GAAG,cAAc,CAAC;;IACvC,CAAC;IAED,QAAQ;IAGF,yBAAI,GAAJ,UAAK,MAAkB;;;gBAC3B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;;;KACnC;IAED,OAAO;IAED,mCAAc,GAAd,UAAe,MAA4B;;;;;;wBACzC,GAAG,GAAG,oBAAa,MAAM,CAAC,IAAI,CAAE,CAAC;wBACnB,qBAAM,IAAI,CAAC,GAAG,CAAuB,GAAG,CAAC,EAAA;;wBAAvD,WAAW,GAAG,SAAyC;wBACzD,mBAAmB,GAAG,EAAE,CAAC;wBAC7B,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAC,CAAC;4BAChD,mBAAmB,GAAG,UAAG,mBAAmB,iBAEhD,CAAC,CAAE,CAAC;wBACF,CAAC,CAAC,CAAC;wBACH,WAAW,CAAC,WAAW,GAAG,mBAAmB,CAAC;wBAC9C,sBAAO,WAAW,EAAC;;;;KACpB;IAGK,kCAAa,GAAb,UAAc,MAA2B;;;;gBACvC,GAAG,GAAG,oBAAa,MAAM,CAAC,IAAI,mBAAS,MAAM,CAAC,OAAO,CAAE,CAAC;gBAC9D,sBAAO,IAAI,CAAC,GAAG,CAAsB,GAAG,CAAC,EAAC;;;KAC3C;IAvBK;QAFL,IAAA,eAAM,EAAC,iBAAiB,CAAC;QAC1B,6DAA6D;0CAG5D;IAIK;QADL,IAAA,eAAM,EAAC,2BAA2B,CAAC;oDAYnC;IAGK;QADL,IAAA,eAAM,EAAC,0BAA0B,CAAC;mDAIlC;IACH,iBAAC;CAAA,AAnCD,CAAwC,mBAAU,GAmCjD;kBAnCoB,UAAU","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport {\n GetVoteDetailsParams,\n GetVoteDetailsResult,\n GetVoteStatusParams,\n GetVoteStatusResult,\n VoteParams,\n VoteResult,\n} from './types';\nimport { Logger, Loggable } from '@reyaxyz/common';\n\nexport default class VoteModule extends RestClient implements Loggable {\n loggingEnabled: boolean = false;\n\n constructor(apiUrl: string, loggingEnabled: boolean) {\n super(apiUrl);\n this.loggingEnabled = loggingEnabled;\n }\n\n // WRITE\n @Logger('VoteModule.vote')\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async vote(params: VoteParams): Promise<VoteResult> {\n throw new Error('Unimplemented.');\n }\n\n // READ\n @Logger('VoteModule.getVoteDetails')\n async getVoteDetails(params: GetVoteDetailsParams) {\n const uri = `/api/vote/${params.slug}`;\n const voteDetails = await this.get<GetVoteDetailsResult>(uri);\n let markdownDescription = '';\n voteDetails.description.split('\\n ').forEach((i) => {\n markdownDescription = `${markdownDescription}\n\n${i}`;\n });\n voteDetails.description = markdownDescription;\n return voteDetails;\n }\n\n @Logger('VoteModule.getVoteStatus')\n async getVoteStatus(params: GetVoteStatusParams) {\n const uri = `/api/vote/${params.slug}/user/${params.address}`;\n return this.get<GetVoteStatusResult>(uri);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAU7C,0CAAmD;AACnD,uCAAsC;AAEtC;IAAwC,8BAAU;IAGhD,oBAAY,MAAc,EAAE,cAAuB;QACjD,YAAA,MAAK,YAAC,MAAM,CAAC,SAAC;QAHhB,oBAAc,GAAY,KAAK,CAAC;QAI9B,KAAI,CAAC,cAAc,GAAG,cAAc,CAAC;;IACvC,CAAC;IAED,QAAQ;IAEF,yBAAI,GAAJ,UAAK,MAAkB;;;;;;;wBACrB,OAAO,GAAG,qCAA8B,MAAM,CAAC,IAAI,CAAE,CAAC;wBACvC,qBAAM,IAAI,CAAC,GAAG,CAA+B,OAAO,CAAC,EAAA;;wBAApE,YAAY,GAAG,SAAqD;wBAGxE,qBAAM,IAAA,mBAAQ,wBACT,MAAM,KACT,eAAe,EAAE,YAAY,CAAC,eAAe,IAC7C,EAAA;;wBAJE,KACJ,SAGE,EAJe,SAAS,eAAA,EAAY,iBAAiB,cAAA;wBAMnD,OAAO,GAAG,oBAAa,YAAY,CAAC,eAAe,UAAO,CAAC;wBAC5C,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BAAU,GAuDjD;kBAvDoB,UAAU","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport {\n GetVoteContractDetailsResult,\n GetVoteDetailsParams,\n GetVoteDetailsResult,\n GetVoteStatusParams,\n GetVoteStatusResult,\n VoteParams,\n VoteResult,\n} from './types';\nimport { Logger, Loggable } from '@reyaxyz/common';\nimport { sendVote } from './services';\n\nexport default class VoteModule extends RestClient implements Loggable {\n loggingEnabled: boolean = false;\n\n constructor(apiUrl: string, loggingEnabled: boolean) {\n super(apiUrl);\n this.loggingEnabled = loggingEnabled;\n }\n\n // WRITE\n @Logger('VoteModule.vote')\n async vote(params: VoteParams): Promise<VoteResult> {\n const infoUri = `/api/vote/contract-details/${params.slug}`;\n const infoMetadata = await this.get<GetVoteContractDetailsResult>(infoUri);\n\n const { signature: signature, deadline: signatureDeadline } =\n await sendVote({\n ...params,\n contractAddress: infoMetadata.contractAddress,\n });\n\n const voteUri = `/api/vote/${infoMetadata.contractAddress}/vote`;\n const result = await this.put<{ txHash: string }>(\n voteUri,\n {},\n {\n voter: await params.signer.getAddress(),\n isYesVote: params.voted,\n signature: signature,\n signatureDeadline: signatureDeadline,\n },\n );\n\n return { transactionHash: result.txHash };\n }\n\n // READ\n @Logger('VoteModule.getVoteDetails')\n async getVoteDetails(params: GetVoteDetailsParams) {\n const uri = `/api/vote/${params.slug}`;\n const voteDetails = await this.get<GetVoteDetailsResult>(uri);\n let markdownDescription = '';\n voteDetails.description.split('\\n ').forEach((i) => {\n markdownDescription = `${markdownDescription}\n\n${i}`;\n });\n voteDetails.description = markdownDescription;\n return voteDetails;\n }\n\n @Logger('VoteModule.getVoteStatus')\n async getVoteStatus(params: GetVoteStatusParams) {\n const uri = `/api/vote/${params.slug}/user/${params.address}`;\n return this.get<GetVoteStatusResult>(uri);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer } from 'ethers';\nimport { VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';\n\nexport type SignedVote = {\n signature: string;\n deadline: number;\n};\n\nexport type VoteResult = {\n transactionHash: string | null;\n};\n\nexport type GetVoteDetailsParams = {\n slug: VoteDetailsEntity['slug'];\n};\nexport type GetVoteDetailsResult = VoteDetailsEntity;\n\nexport type VoteParams = {\n slug: VoteDetailsEntity['slug'];\n voted: 'yes' | 'no';\n signer: Signer;\n};\n\nexport type ExecuteVoteParams = VoteParams & {\n contractAddress: string;\n};\n\nexport type GetVoteStatusParams = {\n address: string;\n slug: VoteDetailsEntity['slug'];\n};\nexport type GetVoteStatusResult = VoteStatusEntity;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer } from 'ethers';\nimport {\n VoteContractDetailsEntity,\n VoteDetailsEntity,\n VoteStatusEntity,\n} from '@reyaxyz/common';\n\nexport type SignedVote = {\n signature: string;\n deadline: number;\n};\n\nexport type VoteResult = {\n transactionHash: string | null;\n};\n\nexport type GetVoteDetailsParams = {\n slug: VoteDetailsEntity['slug'];\n};\nexport type GetVoteDetailsResult = VoteDetailsEntity;\n\nexport type GetVoteContractDetailsResult = VoteContractDetailsEntity;\n\nexport type VoteParams = {\n slug: VoteDetailsEntity['slug'];\n voted: 'yes' | 'no';\n signer: Signer;\n};\n\nexport type ExecuteVoteParams = VoteParams & {\n contractAddress: string;\n};\n\nexport type GetVoteStatusParams = {\n address: string;\n slug: VoteDetailsEntity['slug'];\n};\nexport type GetVoteStatusResult = VoteStatusEntity;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,oBAAoB,EAEpB,mBAAmB,EAEnB,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAU,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,UAAW,YAAW,QAAQ;IACpE,cAAc,EAAE,OAAO,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO;IAQ7C,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAM7C,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAc3C,aAAa,CAAC,MAAM,EAAE,mBAAmB;CAIhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAEL,oBAAoB,EAEpB,mBAAmB,EAEnB,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAU,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGnD,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,UAAW,YAAW,QAAQ;IACpE,cAAc,EAAE,OAAO,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO;IAO7C,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA2B7C,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAc3C,aAAa,CAAC,MAAM,EAAE,mBAAmB;CAIhD"}
@@ -1,5 +1,5 @@
1
1
  import { Signer } from 'ethers';
2
- import { VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
2
+ import { VoteContractDetailsEntity, VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
3
3
  export type SignedVote = {
4
4
  signature: string;
5
5
  deadline: number;
@@ -11,6 +11,7 @@ export type GetVoteDetailsParams = {
11
11
  slug: VoteDetailsEntity['slug'];
12
12
  };
13
13
  export type GetVoteDetailsResult = VoteDetailsEntity;
14
+ export type GetVoteContractDetailsResult = VoteContractDetailsEntity;
14
15
  export type VoteParams = {
15
16
  slug: VoteDetailsEntity['slug'];
16
17
  voted: 'yes' | 'no';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD,MAAM,MAAM,4BAA4B,GAAG,yBAAyB,CAAC;AAErE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/community-sdk",
3
- "version": "0.52.47",
3
+ "version": "0.53.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -10,8 +10,8 @@
10
10
  "url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
11
11
  },
12
12
  "dependencies": {
13
- "@reyaxyz/common": "0.323.0",
14
- "@reyaxyz/sdk": "0.140.1",
13
+ "@reyaxyz/common": "0.324.0",
14
+ "@reyaxyz/sdk": "0.140.2",
15
15
  "ethers": "6.9.0"
16
16
  },
17
17
  "main": "dist/index.js",
@@ -38,5 +38,5 @@
38
38
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
39
39
  },
40
40
  "packageManager": "pnpm@8.3.1",
41
- "gitHead": "14753daf1fd9d785f10e14ce5d923d2fa8cb71b1"
41
+ "gitHead": "22962719b00f42ae9cc5be93e14713526c95972e"
42
42
  }
@@ -1,5 +1,6 @@
1
1
  import { RestClient } from '@reyaxyz/common';
2
2
  import {
3
+ GetVoteContractDetailsResult,
3
4
  GetVoteDetailsParams,
4
5
  GetVoteDetailsResult,
5
6
  GetVoteStatusParams,
@@ -8,6 +9,7 @@ import {
8
9
  VoteResult,
9
10
  } from './types';
10
11
  import { Logger, Loggable } from '@reyaxyz/common';
12
+ import { sendVote } from './services';
11
13
 
12
14
  export default class VoteModule extends RestClient implements Loggable {
13
15
  loggingEnabled: boolean = false;
@@ -19,9 +21,29 @@ export default class VoteModule extends RestClient implements Loggable {
19
21
 
20
22
  // WRITE
21
23
  @Logger('VoteModule.vote')
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
24
  async vote(params: VoteParams): Promise<VoteResult> {
24
- throw new Error('Unimplemented.');
25
+ const infoUri = `/api/vote/contract-details/${params.slug}`;
26
+ const infoMetadata = await this.get<GetVoteContractDetailsResult>(infoUri);
27
+
28
+ const { signature: signature, deadline: signatureDeadline } =
29
+ await sendVote({
30
+ ...params,
31
+ contractAddress: infoMetadata.contractAddress,
32
+ });
33
+
34
+ const voteUri = `/api/vote/${infoMetadata.contractAddress}/vote`;
35
+ const result = await this.put<{ txHash: string }>(
36
+ voteUri,
37
+ {},
38
+ {
39
+ voter: await params.signer.getAddress(),
40
+ isYesVote: params.voted,
41
+ signature: signature,
42
+ signatureDeadline: signatureDeadline,
43
+ },
44
+ );
45
+
46
+ return { transactionHash: result.txHash };
25
47
  }
26
48
 
27
49
  // READ
@@ -1,5 +1,9 @@
1
1
  import { Signer } from 'ethers';
2
- import { VoteDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
2
+ import {
3
+ VoteContractDetailsEntity,
4
+ VoteDetailsEntity,
5
+ VoteStatusEntity,
6
+ } from '@reyaxyz/common';
3
7
 
4
8
  export type SignedVote = {
5
9
  signature: string;
@@ -15,6 +19,8 @@ export type GetVoteDetailsParams = {
15
19
  };
16
20
  export type GetVoteDetailsResult = VoteDetailsEntity;
17
21
 
22
+ export type GetVoteContractDetailsResult = VoteContractDetailsEntity;
23
+
18
24
  export type VoteParams = {
19
25
  slug: VoteDetailsEntity['slug'];
20
26
  voted: 'yes' | 'no';
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.executeTransaction = exports.estimateGas = void 0;
51
- var contractAddresses_1 = require("../../../utils/contractAddresses");
52
- var common_1 = require("@reyaxyz/common");
53
- function estimateGas(signer, data, value, chainId, targetContract) {
54
- return __awaiter(this, void 0, void 0, function () {
55
- var accountAddress, contractAddress, tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
58
- case 0: return [4 /*yield*/, signer.getAddress()];
59
- case 1:
60
- accountAddress = _a.sent();
61
- contractAddress = Object.values(contractAddresses_1.ContractType).includes(targetContract)
62
- ? (0, contractAddresses_1.getAddress)(chainId, targetContract)
63
- : targetContract;
64
- tx = __assign({ from: accountAddress, to: contractAddress, data: data }, (value && value !== '0' ? { value: value } : {}));
65
- gasLimit = BigInt('5000000');
66
- if (Object.values(common_1.ReyaChainId).includes(chainId)) {
67
- maxPriorityFeePerGas = BigInt('0');
68
- maxFeePerGas = BigInt('100000000');
69
- return [2 /*return*/, __assign(__assign({}, tx), { gasLimit: gasLimit, maxPriorityFeePerGas: maxPriorityFeePerGas, maxFeePerGas: maxFeePerGas })];
70
- }
71
- return [2 /*return*/, __assign(__assign({}, tx), { gasLimit: gasLimit })];
72
- }
73
- });
74
- });
75
- }
76
- exports.estimateGas = estimateGas;
77
- function executeTransaction(signer, data, value, chainId, targetContract) {
78
- return __awaiter(this, void 0, void 0, function () {
79
- var txData, txResponse, txReceipt, error_1;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0: return [4 /*yield*/, estimateGas(signer, data, value, chainId, targetContract)];
83
- case 1:
84
- txData = _a.sent();
85
- _a.label = 2;
86
- case 2:
87
- _a.trys.push([2, 5, , 6]);
88
- return [4 /*yield*/, signer.sendTransaction(txData)];
89
- case 3:
90
- txResponse = _a.sent();
91
- return [4 /*yield*/, txResponse.wait()];
92
- case 4:
93
- txReceipt = _a.sent();
94
- return [2 /*return*/, txReceipt];
95
- case 5:
96
- error_1 = _a.sent();
97
- console.warn(error_1);
98
- throw new Error('Transaction Execution Error');
99
- case 6: return [2 /*return*/];
100
- }
101
- });
102
- });
103
- }
104
- exports.executeTransaction = executeTransaction;
105
- //# sourceMappingURL=executeTransaction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["modules/vote/services/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sEAA4E;AAC5E,0CAA8C;AAS9C,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAC1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAA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AAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAvBD,gDAuBC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ContractType, getAddress } from '../../../utils/contractAddresses';\nimport { ReyaChainId } from '@reyaxyz/common';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress,\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\n"]}
@@ -1,15 +0,0 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
2
- import { ContractType } from '../../../utils/contractAddresses';
3
- export type Transaction = {
4
- from: string;
5
- to: string;
6
- data: string;
7
- value?: string;
8
- };
9
- export declare function estimateGas(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<Transaction & {
10
- gasLimit: bigint;
11
- maxPriorityFeePerGas?: bigint;
12
- maxFeePerGas?: bigint;
13
- }>;
14
- export declare function executeTransaction(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<import("ethers").TransactionReceipt | null>;
15
- //# sourceMappingURL=executeTransaction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["modules/vote/services/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAc,MAAM,kCAAkC,CAAC;AAG5E,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,GACpC,OAAO,CACR,WAAW,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAuBA;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,uDAkBtC"}
@@ -1,72 +0,0 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
2
- import { ContractType, getAddress } from '../../../utils/contractAddresses';
3
- import { ReyaChainId } from '@reyaxyz/common';
4
-
5
- export type Transaction = {
6
- from: string;
7
- to: string;
8
- data: string;
9
- value?: string;
10
- };
11
-
12
- export async function estimateGas(
13
- signer: Signer | JsonRpcSigner,
14
- data: string,
15
- value: string,
16
- chainId: number,
17
- targetContract: ContractType | string,
18
- ): Promise<
19
- Transaction & {
20
- gasLimit: bigint;
21
- maxPriorityFeePerGas?: bigint;
22
- maxFeePerGas?: bigint;
23
- }
24
- > {
25
- const accountAddress = await signer.getAddress();
26
- const contractAddress = Object.values(ContractType).includes(
27
- targetContract as ContractType,
28
- )
29
- ? getAddress(chainId, targetContract as ContractType)
30
- : targetContract;
31
- const tx = {
32
- from: accountAddress,
33
- to: contractAddress,
34
- data,
35
- ...(value && value !== '0' ? { value: value } : {}),
36
- };
37
-
38
- const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit
39
-
40
- if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {
41
- const maxPriorityFeePerGas: bigint = BigInt('0');
42
- const maxFeePerGas: bigint = BigInt('100000000');
43
- return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };
44
- }
45
-
46
- return { ...tx, gasLimit };
47
- }
48
-
49
- export async function executeTransaction(
50
- signer: Signer | JsonRpcSigner,
51
- data: string,
52
- value: string,
53
- chainId: number,
54
- targetContract: ContractType | string,
55
- ) {
56
- const txData = await estimateGas(
57
- signer,
58
- data,
59
- value,
60
- chainId,
61
- targetContract,
62
- );
63
-
64
- try {
65
- const txResponse = await signer.sendTransaction(txData);
66
- const txReceipt = await txResponse.wait();
67
- return txReceipt;
68
- } catch (error) {
69
- console.warn(error);
70
- throw new Error('Transaction Execution Error');
71
- }
72
- }