@reyaxyz/community-sdk 0.32.8 → 0.33.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.
@@ -79,10 +79,28 @@ var VoteModule = /** @class */ (function (_super) {
79
79
  _this.loggingEnabled = loggingEnabled;
80
80
  return _this;
81
81
  }
82
+ VoteModule.prototype.executeVoteTx = function (voteInfo) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var uri, result;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ uri = "/api/transaction-gelato/executeGelatoEip2771";
89
+ return [4 /*yield*/, this.post(uri, {}, {
90
+ signatureData: voteInfo.signatureData,
91
+ contractAddress: voteInfo.contractAddress,
92
+ })];
93
+ case 1:
94
+ result = _a.sent();
95
+ return [2 /*return*/, { transactionHash: result.txHash }];
96
+ }
97
+ });
98
+ });
99
+ };
82
100
  // WRITE
83
101
  VoteModule.prototype.vote = function (params) {
84
102
  return __awaiter(this, void 0, void 0, function () {
85
- var uri, metadata;
103
+ var uri, metadata, voteInfo;
86
104
  return __generator(this, function (_a) {
87
105
  switch (_a.label) {
88
106
  case 0:
@@ -90,7 +108,10 @@ var VoteModule = /** @class */ (function (_super) {
90
108
  return [4 /*yield*/, this.get(uri)];
91
109
  case 1:
92
110
  metadata = _a.sent();
93
- return [2 /*return*/, (0, services_1.vote)(__assign(__assign({}, params), { contractAddress: metadata.contractAddress }))];
111
+ return [4 /*yield*/, (0, services_1.vote)(__assign(__assign({}, params), { contractAddress: metadata.contractAddress }))];
112
+ case 2:
113
+ voteInfo = _a.sent();
114
+ return [2 /*return*/, this.executeVoteTx(voteInfo)];
94
115
  }
95
116
  });
96
117
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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AC;0CAKzB;IAIK;QADL,IAAA,eAAM,EAAC,2BAA2B,CAAC;oDAYnC;IAGK;QADL,IAAA,eAAM,EAAC,0BAA0B,CAAC;mDAIlC;IACH,iBAAC;CAAA,AApCD,CAAwC,mBAAU,GAoCjD;kBApCoB,UAAU","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport {\n GetVoteContractDetailsResult,\n GetVoteDetailsParams,\n GetVoteDetailsResult,\n GetVoteStatusParams,\n GetVoteStatusResult,\n VoteParams,\n} from './types';\nimport { vote } from './services';\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 async vote(params: VoteParams) {\n const uri = `/api/vote/contract-details/${params.slug}`;\n const metadata = await this.get<GetVoteContractDetailsResult>(uri);\n return vote({ ...params, contractAddress: metadata.contractAddress });\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;AAW7C,uCAAkC;AAClC,0CAAmD;AAEnD;IAAwC,8BAAU;I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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;IA9BK;QADL,IAAA,eAAM,EAAC,iBAAiB,CAAC;0CAUzB;IAIK;QADL,IAAA,eAAM,EAAC,2BAA2B,CAAC;oDAYnC;IAGK;QADL,IAAA,eAAM,EAAC,0BAA0B,CAAC;mDAIlC;IACH,iBAAC;CAAA,AAtDD,CAAwC,mBAAU,GAsDjD;kBAtDoB,UAAU","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport {\n GetVoteContractDetailsResult,\n GetVoteDetailsParams,\n GetVoteDetailsResult,\n GetVoteStatusParams,\n GetVoteStatusResult,\n VoteInfo,\n VoteParams,\n VoteResult,\n} from './types';\nimport { vote } from './services';\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 private async executeVoteTx(voteInfo: VoteInfo): Promise<VoteResult> {\n const uri = `/api/transaction-gelato/executeGelatoEip2771`;\n const result = await this.post<{ txHash: string; accountId?: string }>(\n uri,\n {},\n {\n signatureData: voteInfo.signatureData,\n contractAddress: voteInfo.contractAddress,\n },\n );\n return { transactionHash: result.txHash };\n }\n\n // WRITE\n @Logger('VoteModule.vote')\n async vote(params: VoteParams) {\n const uri = `/api/vote/contract-details/${params.slug}`;\n const metadata = await this.get<GetVoteContractDetailsResult>(uri);\n\n const voteInfo = await vote({\n ...params,\n contractAddress: metadata.contractAddress,\n });\n return this.executeVoteTx(voteInfo);\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"]}
@@ -39,8 +39,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.vote = void 0;
40
40
  var executeTransaction_1 = require("../executeTransaction");
41
41
  var encode_1 = require("./encode");
42
+ var relay_sdk_1 = require("@gelatonetwork/relay-sdk");
43
+ var common_1 = require("@reyaxyz/common");
42
44
  var vote = function (params) { return __awaiter(void 0, void 0, void 0, function () {
43
- var _a, data, value, network, chainId, result, error_1;
45
+ var _a, data, value, network, user, relay, request, signer, signatureData, error_1;
44
46
  var _b;
45
47
  return __generator(this, function (_c) {
46
48
  switch (_c.label) {
@@ -49,20 +51,37 @@ var vote = function (params) { return __awaiter(void 0, void 0, void 0, function
49
51
  return [4 /*yield*/, ((_b = params.signer.provider) === null || _b === void 0 ? void 0 : _b.getNetwork())];
50
52
  case 1:
51
53
  network = _c.sent();
52
- chainId = Number(network === null || network === void 0 ? void 0 : network.chainId);
53
- _c.label = 2;
54
+ if (!network) {
55
+ throw new Error('Vote failed. Network not found.');
56
+ }
57
+ return [4 /*yield*/, params.signer.getAddress()];
54
58
  case 2:
55
- _c.trys.push([2, 4, , 5]);
56
- return [4 /*yield*/, (0, executeTransaction_1.executeTransaction)(params.signer, data, value, chainId, params.contractAddress)];
59
+ user = _c.sent();
60
+ relay = new relay_sdk_1.GelatoRelay();
61
+ _c.label = 3;
57
62
  case 3:
58
- result = _c.sent();
63
+ _c.trys.push([3, 6, , 7]);
64
+ request = {
65
+ chainId: network.chainId,
66
+ target: params.contractAddress,
67
+ data: data,
68
+ user: user,
69
+ };
70
+ signer = params.signer;
71
+ return [4 /*yield*/, (0, executeTransaction_1.estimateGas)(params.signer, data, value, Number(network.chainId), params.contractAddress)];
72
+ case 4:
73
+ _c.sent();
74
+ return [4 /*yield*/, relay.getSignatureDataERC2771(request, signer, relay_sdk_1.ERC2771Type.SponsoredCall)];
75
+ case 5:
76
+ signatureData = _c.sent();
59
77
  return [2 /*return*/, {
60
- transactionHash: (result === null || result === void 0 ? void 0 : result.hash) || null,
78
+ signatureData: signatureData,
79
+ contractAddress: (0, common_1.convertToAddress)(params.contractAddress),
61
80
  }];
62
- case 4:
81
+ case 6:
63
82
  error_1 = _c.sent();
64
83
  throw new Error('Vote failed. Please reach out via Discord.');
65
- case 5: return [2 /*return*/];
84
+ case 7: return [2 /*return*/];
66
85
  }
67
86
  });
68
87
  }); };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2D;AAC3D,mCAA0C;AAGnC,IAAM,IAAI,GAAG,UAAO,MAAyB;;;;;;gBAC5C,KAA4B,IAAA,uBAAc,EAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,EAArD,IAAI,cAAA,EAAE,KAAK,WAAA,CAA2C;gBAExD,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBACpD,OAAO,GAAG,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;;;;gBAGxB,qBAAM,IAAA,uCAAkB,EACrC,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,CAAC,eAAe,CACvB,EAAA;;gBANK,MAAM,GAAG,SAMd;gBACD,sBAAO;wBACL,eAAe,EAAE,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,KAAI,IAAI;qBACtC,EAAC;;;gBAEF,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;;;;KAEjE,CAAC;AApBW,QAAA,IAAI,QAoBf","sourcesContent":["import { executeTransaction } from '../executeTransaction';\nimport { encodeCastVote } from './encode';\nimport { ExecuteVoteParams, VoteResult } from '../../types';\n\nexport const vote = async (params: ExecuteVoteParams): Promise<VoteResult> => {\n const { calldata: data, value } = encodeCastVote(params.voted == 'yes');\n\n const network = await params.signer.provider?.getNetwork();\n const chainId = Number(network?.chainId);\n\n try {\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n params.contractAddress,\n );\n return {\n transactionHash: result?.hash || null,\n };\n } catch (error) {\n throw new Error('Vote failed. Please reach out via Discord.');\n }\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAoD;AACpD,mCAA0C;AAE1C,sDAKkC;AAClC,0CAAmD;AAE5C,IAAM,IAAI,GAAG,UAAO,MAAyB;;;;;;gBAC5C,KAA4B,IAAA,uBAAc,EAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,EAArD,IAAI,cAAA,EAAE,KAAK,WAAA,CAA2C;gBAExD,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;gBAApD,OAAO,GAAG,SAA0C;gBAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;gBACrD,CAAC;gBACY,qBAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAvC,IAAI,GAAG,SAAgC;gBAEvC,KAAK,GAAG,IAAI,uBAAW,EAAE,CAAC;;;;gBAGxB,OAAO,GAA2B;oBACtC,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,MAAM,EAAE,MAAM,CAAC,eAAe;oBAC9B,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,IAAI;iBACX,CAAC;gBAEI,MAAM,GAAG,MAAM,CAAC,MAAqC,CAAC;gBAE5D,qBAAM,IAAA,gCAAW,EACf,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,EACL,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EACvB,MAAM,CAAC,eAAe,CACvB,EAAA;;gBAND,SAMC,CAAC;gBACoB,qBAAM,KAAK,CAAC,uBAAuB,CACvD,OAAO,EACP,MAAM,EACN,uBAAW,CAAC,aAAa,CAC1B,EAAA;;gBAJK,aAAa,GAAG,SAIrB;gBAED,sBAAO;wBACL,aAAa,EAAE,aAAa;wBAC5B,eAAe,EAAE,IAAA,yBAAgB,EAAC,MAAM,CAAC,eAAe,CAAC;qBAC1D,EAAC;;;gBAEF,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;;;;KAEjE,CAAC;AAzCW,QAAA,IAAI,QAyCf","sourcesContent":["import { estimateGas } from '../executeTransaction';\nimport { encodeCastVote } from './encode';\nimport { ExecuteVoteParams, VoteInfo } from '../../types';\nimport {\n GelatoRelay,\n CallWithERC2771Request,\n ERC2771Type,\n SignerOrProvider,\n} from '@gelatonetwork/relay-sdk';\nimport { convertToAddress } from '@reyaxyz/common';\n\nexport const vote = async (params: ExecuteVoteParams): Promise<VoteInfo> => {\n const { calldata: data, value } = encodeCastVote(params.voted == 'yes');\n\n const network = await params.signer.provider?.getNetwork();\n if (!network) {\n throw new Error('Vote failed. Network not found.');\n }\n const user = await params.signer.getAddress();\n\n const relay = new GelatoRelay();\n\n try {\n const request: CallWithERC2771Request = {\n chainId: network.chainId,\n target: params.contractAddress,\n data: data,\n user: user,\n };\n\n const signer = params.signer as unknown as SignerOrProvider;\n\n await estimateGas(\n params.signer,\n data,\n value,\n Number(network.chainId),\n params.contractAddress,\n );\n const signatureData = await relay.getSignatureDataERC2771(\n request,\n signer,\n ERC2771Type.SponsoredCall,\n );\n\n return {\n signatureData: signatureData,\n contractAddress: convertToAddress(params.contractAddress),\n };\n } catch (error) {\n throw new Error('Vote failed. Please reach out via Discord.');\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport {\n VoteDetailsEntity,\n VoteContractDetailsEntity,\n VoteStatusEntity,\n} from '@reyaxyz/common';\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 | JsonRpcSigner;\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 { SignatureData } from '@gelatonetwork/relay-sdk';\nimport {\n VoteDetailsEntity,\n VoteContractDetailsEntity,\n VoteStatusEntity,\n Address,\n} from '@reyaxyz/common';\n\nexport type VoteInfo = {\n signatureData: SignatureData;\n contractAddress: Address;\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,10 +1,11 @@
1
1
  import { RestClient } from '@reyaxyz/common';
2
- import { GetVoteDetailsParams, GetVoteStatusParams, VoteParams } from './types';
2
+ import { GetVoteDetailsParams, GetVoteStatusParams, VoteParams, VoteResult } from './types';
3
3
  import { Loggable } from '@reyaxyz/common';
4
4
  export default class VoteModule extends RestClient implements Loggable {
5
5
  loggingEnabled: boolean;
6
6
  constructor(apiUrl: string, loggingEnabled: boolean);
7
- vote(params: VoteParams): Promise<import("./types").VoteResult>;
7
+ private executeVoteTx;
8
+ vote(params: VoteParams): Promise<VoteResult>;
8
9
  getVoteDetails(params: GetVoteDetailsParams): Promise<import("@reyaxyz/common").VoteDetailsEntity>;
9
10
  getVoteStatus(params: GetVoteStatusParams): Promise<import("@reyaxyz/common").VoteStatusEntity>;
10
11
  }
@@ -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,EAEL,oBAAoB,EAEpB,mBAAmB,EAEnB,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,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;IAO7C,IAAI,CAAC,MAAM,EAAE,UAAU;IAQvB,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,EAGnB,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,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;YAKrC,aAAa;IAerB,IAAI,CAAC,MAAM,EAAE,UAAU;IAavB,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAc3C,aAAa,CAAC,MAAM,EAAE,mBAAmB;CAIhD"}
@@ -1,3 +1,3 @@
1
- import { ExecuteVoteParams, VoteResult } from '../../types';
2
- export declare const vote: (params: ExecuteVoteParams) => Promise<VoteResult>;
1
+ import { ExecuteVoteParams, VoteInfo } from '../../types';
2
+ export declare const vote: (params: ExecuteVoteParams) => Promise<VoteInfo>;
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE5D,eAAO,MAAM,IAAI,WAAkB,iBAAiB,KAAG,QAAQ,UAAU,CAoBxE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vote/services/vote/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAS1D,eAAO,MAAM,IAAI,WAAkB,iBAAiB,KAAG,QAAQ,QAAQ,CAyCtE,CAAC"}
@@ -1,5 +1,10 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
2
- import { VoteDetailsEntity, VoteContractDetailsEntity, VoteStatusEntity } from '@reyaxyz/common';
1
+ import { Signer } from 'ethers';
2
+ import { SignatureData } from '@gelatonetwork/relay-sdk';
3
+ import { VoteDetailsEntity, VoteContractDetailsEntity, VoteStatusEntity, Address } from '@reyaxyz/common';
4
+ export type VoteInfo = {
5
+ signatureData: SignatureData;
6
+ contractAddress: Address;
7
+ };
3
8
  export type VoteResult = {
4
9
  transactionHash: string | null;
5
10
  };
@@ -11,7 +16,7 @@ export type GetVoteContractDetailsResult = VoteContractDetailsEntity;
11
16
  export type VoteParams = {
12
17
  slug: VoteDetailsEntity['slug'];
13
18
  voted: 'yes' | 'no';
14
- signer: Signer | JsonRpcSigner;
19
+ signer: Signer;
15
20
  };
16
21
  export type ExecuteVoteParams = VoteParams & {
17
22
  contractAddress: string;
@@ -1 +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,EACL,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,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,CA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AAmB,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.32.8",
3
+ "version": "0.33.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -10,8 +10,9 @@
10
10
  "url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
11
11
  },
12
12
  "dependencies": {
13
- "@reyaxyz/common": "0.94.0",
14
- "@reyaxyz/sdk": "0.79.1",
13
+ "@gelatonetwork/relay-sdk": "^5.5.0",
14
+ "@reyaxyz/common": "0.95.0",
15
+ "@reyaxyz/sdk": "0.79.2",
15
16
  "ethers": "6.9.0"
16
17
  },
17
18
  "main": "dist/index.js",
@@ -38,5 +39,5 @@
38
39
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
39
40
  },
40
41
  "packageManager": "pnpm@8.3.1",
41
- "gitHead": "e8ab18452b7298d862f6aa4a06552a1eecd6236d"
42
+ "gitHead": "4dbd0097222e0a63ea94c80a3cf1b0ead1bef0b5"
42
43
  }
@@ -5,7 +5,9 @@ import {
5
5
  GetVoteDetailsResult,
6
6
  GetVoteStatusParams,
7
7
  GetVoteStatusResult,
8
+ VoteInfo,
8
9
  VoteParams,
10
+ VoteResult,
9
11
  } from './types';
10
12
  import { vote } from './services';
11
13
  import { Logger, Loggable } from '@reyaxyz/common';
@@ -18,12 +20,30 @@ export default class VoteModule extends RestClient implements Loggable {
18
20
  this.loggingEnabled = loggingEnabled;
19
21
  }
20
22
 
23
+ private async executeVoteTx(voteInfo: VoteInfo): Promise<VoteResult> {
24
+ const uri = `/api/transaction-gelato/executeGelatoEip2771`;
25
+ const result = await this.post<{ txHash: string; accountId?: string }>(
26
+ uri,
27
+ {},
28
+ {
29
+ signatureData: voteInfo.signatureData,
30
+ contractAddress: voteInfo.contractAddress,
31
+ },
32
+ );
33
+ return { transactionHash: result.txHash };
34
+ }
35
+
21
36
  // WRITE
22
37
  @Logger('VoteModule.vote')
23
38
  async vote(params: VoteParams) {
24
39
  const uri = `/api/vote/contract-details/${params.slug}`;
25
40
  const metadata = await this.get<GetVoteContractDetailsResult>(uri);
26
- return vote({ ...params, contractAddress: metadata.contractAddress });
41
+
42
+ const voteInfo = await vote({
43
+ ...params,
44
+ contractAddress: metadata.contractAddress,
45
+ });
46
+ return this.executeVoteTx(voteInfo);
27
47
  }
28
48
 
29
49
  // READ
@@ -1,23 +1,51 @@
1
- import { executeTransaction } from '../executeTransaction';
1
+ import { estimateGas } from '../executeTransaction';
2
2
  import { encodeCastVote } from './encode';
3
- import { ExecuteVoteParams, VoteResult } from '../../types';
3
+ import { ExecuteVoteParams, VoteInfo } from '../../types';
4
+ import {
5
+ GelatoRelay,
6
+ CallWithERC2771Request,
7
+ ERC2771Type,
8
+ SignerOrProvider,
9
+ } from '@gelatonetwork/relay-sdk';
10
+ import { convertToAddress } from '@reyaxyz/common';
4
11
 
5
- export const vote = async (params: ExecuteVoteParams): Promise<VoteResult> => {
12
+ export const vote = async (params: ExecuteVoteParams): Promise<VoteInfo> => {
6
13
  const { calldata: data, value } = encodeCastVote(params.voted == 'yes');
7
14
 
8
15
  const network = await params.signer.provider?.getNetwork();
9
- const chainId = Number(network?.chainId);
16
+ if (!network) {
17
+ throw new Error('Vote failed. Network not found.');
18
+ }
19
+ const user = await params.signer.getAddress();
20
+
21
+ const relay = new GelatoRelay();
10
22
 
11
23
  try {
12
- const result = await executeTransaction(
24
+ const request: CallWithERC2771Request = {
25
+ chainId: network.chainId,
26
+ target: params.contractAddress,
27
+ data: data,
28
+ user: user,
29
+ };
30
+
31
+ const signer = params.signer as unknown as SignerOrProvider;
32
+
33
+ await estimateGas(
13
34
  params.signer,
14
35
  data,
15
36
  value,
16
- chainId,
37
+ Number(network.chainId),
17
38
  params.contractAddress,
18
39
  );
40
+ const signatureData = await relay.getSignatureDataERC2771(
41
+ request,
42
+ signer,
43
+ ERC2771Type.SponsoredCall,
44
+ );
45
+
19
46
  return {
20
- transactionHash: result?.hash || null,
47
+ signatureData: signatureData,
48
+ contractAddress: convertToAddress(params.contractAddress),
21
49
  };
22
50
  } catch (error) {
23
51
  throw new Error('Vote failed. Please reach out via Discord.');
@@ -1,10 +1,17 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
1
+ import { Signer } from 'ethers';
2
+ import { SignatureData } from '@gelatonetwork/relay-sdk';
2
3
  import {
3
4
  VoteDetailsEntity,
4
5
  VoteContractDetailsEntity,
5
6
  VoteStatusEntity,
7
+ Address,
6
8
  } from '@reyaxyz/common';
7
9
 
10
+ export type VoteInfo = {
11
+ signatureData: SignatureData;
12
+ contractAddress: Address;
13
+ };
14
+
8
15
  export type VoteResult = {
9
16
  transactionHash: string | null;
10
17
  };
@@ -19,7 +26,7 @@ export type GetVoteContractDetailsResult = VoteContractDetailsEntity;
19
26
  export type VoteParams = {
20
27
  slug: VoteDetailsEntity['slug'];
21
28
  voted: 'yes' | 'no';
22
- signer: Signer | JsonRpcSigner;
29
+ signer: Signer;
23
30
  };
24
31
 
25
32
  export type ExecuteVoteParams = VoteParams & {