@reyaxyz/community-sdk 0.33.0 → 0.33.2

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.
@@ -80,18 +80,24 @@ var VoteModule = /** @class */ (function (_super) {
80
80
  return _this;
81
81
  }
82
82
  VoteModule.prototype.executeVoteTx = function (voteInfo) {
83
+ var _a;
83
84
  return __awaiter(this, void 0, void 0, function () {
84
85
  var uri, result;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
86
+ return __generator(this, function (_b) {
87
+ switch (_b.label) {
87
88
  case 0:
88
89
  uri = "/api/transaction-gelato/executeGelatoEip2771";
89
90
  return [4 /*yield*/, this.post(uri, {}, {
90
- signatureData: voteInfo.signatureData,
91
+ signature: voteInfo.signature,
92
+ chainId: voteInfo.struct.chainId.toString(),
93
+ data: voteInfo.struct.data,
94
+ userDeadline: voteInfo.struct.userDeadline,
95
+ userNonce: ((_a = voteInfo.struct.userNonce) !== null && _a !== void 0 ? _a : 0).toString(),
96
+ user: voteInfo.struct.user,
91
97
  contractAddress: voteInfo.contractAddress,
92
98
  })];
93
99
  case 1:
94
- result = _a.sent();
100
+ result = _b.sent();
95
101
  return [2 /*return*/, { transactionHash: result.txHash }];
96
102
  }
97
103
  });
@@ -100,17 +106,28 @@ var VoteModule = /** @class */ (function (_super) {
100
106
  // WRITE
101
107
  VoteModule.prototype.vote = function (params) {
102
108
  return __awaiter(this, void 0, void 0, function () {
103
- var uri, metadata, voteInfo;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
109
+ var uri, metadata, voteInfo, _a, _b;
110
+ return __generator(this, function (_c) {
111
+ switch (_c.label) {
106
112
  case 0:
107
113
  uri = "/api/vote/contract-details/".concat(params.slug);
108
114
  return [4 /*yield*/, this.get(uri)];
109
115
  case 1:
110
- metadata = _a.sent();
116
+ metadata = _c.sent();
111
117
  return [4 /*yield*/, (0, services_1.vote)(__assign(__assign({}, params), { contractAddress: metadata.contractAddress }))];
112
118
  case 2:
113
- voteInfo = _a.sent();
119
+ voteInfo = _c.sent();
120
+ if (!!voteInfo.struct.userNonce) return [3 /*break*/, 4];
121
+ _a = voteInfo.struct;
122
+ _b = BigInt;
123
+ return [4 /*yield*/, params.signer.getNonce()];
124
+ case 3:
125
+ _a.userNonce = _b.apply(void 0, [_c.sent()]);
126
+ _c.label = 4;
127
+ case 4:
128
+ if (!voteInfo.struct.userDeadline) {
129
+ voteInfo.struct.userDeadline = Date.now() / 1000 + 3600;
130
+ }
114
131
  return [2 /*return*/, this.executeVoteTx(voteInfo)];
115
132
  }
116
133
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAW7C,uCAAkC;AAClC,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;IAEa,kCAAa,GAA3B,UAA4B,QAAkB;;;;;;wBACtC,GAAG,GAAG,8CAA8C,CAAC;wBAC5C,qBAAM,IAAI,CAAC,IAAI,CAC5B,GAAG,EACH,EAAE,EACF;gCACE,aAAa,EAAE,QAAQ,CAAC,aAAa;gCACrC,eAAe,EAAE,QAAQ,CAAC,eAAe;6BAC1C,CACF,EAAA;;wBAPK,MAAM,GAAG,SAOd;wBACD,sBAAO,EAAE,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,EAAC;;;;KAC3C;IAED,QAAQ;IAEF,yBAAI,GAAJ,UAAK,MAAkB;;;;;;wBACrB,GAAG,GAAG,qCAA8B,MAAM,CAAC,IAAI,CAAE,CAAC;wBACvC,qBAAM,IAAI,CAAC,GAAG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ams,\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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAW7C,uCAAkC;AAClC,0CAAmD;AAEnD;IAAwC,8BAAU;IAGhD,oBAAY,MA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U,GAiEjD;kBAjEoB,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 signature: voteInfo.signature,\n chainId: voteInfo.struct.chainId.toString(),\n data: voteInfo.struct.data,\n userDeadline: voteInfo.struct.userDeadline,\n userNonce: (voteInfo.struct.userNonce ?? 0).toString(),\n user: voteInfo.struct.user,\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 if (!voteInfo.struct.userNonce) {\n voteInfo.struct.userNonce = BigInt(await params.signer.getNonce());\n }\n if (!voteInfo.struct.userDeadline) {\n voteInfo.struct.userDeadline = Date.now() / 1000 + 3600;\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"]}
@@ -75,7 +75,8 @@ var vote = function (params) { return __awaiter(void 0, void 0, void 0, function
75
75
  case 5:
76
76
  signatureData = _c.sent();
77
77
  return [2 /*return*/, {
78
- signatureData: signatureData,
78
+ signature: signatureData.signature,
79
+ struct: signatureData.struct,
79
80
  contractAddress: (0, common_1.convertToAddress)(params.contractAddress),
80
81
  }];
81
82
  case 6:
@@ -1 +1 @@
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
+ {"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,SAAS,EAAE,aAAa,CAAC,SAAS;wBAClC,MAAM,EAAE,aAAa,CAAC,MAAM;wBAC5B,eAAe,EAAE,IAAA,yBAAgB,EAAC,MAAM,CAAC,eAAe,CAAC;qBAC1D,EAAC;;;gBAEF,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;;;;KAEjE,CAAC;AA1CW,QAAA,IAAI,QA0Cf","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 signature: signatureData.signature,\n struct: signatureData.struct,\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 { 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
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["modules/vote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Signer } from 'ethers';\nimport { CallWithERC2771Request } from '@gelatonetwork/relay-sdk';\nimport {\n VoteDetailsEntity,\n VoteContractDetailsEntity,\n VoteStatusEntity,\n Address,\n} from '@reyaxyz/common';\n\nexport type VoteInfo = {\n signature: string;\n struct: CallWithERC2771Request;\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 +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,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
+ {"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;IAoBrB,IAAI,CAAC,MAAM,EAAE,UAAU;IAmBvB,cAAc,CAAC,MAAM,EAAE,oBAAoB;IAc3C,aAAa,CAAC,MAAM,EAAE,mBAAmB;CAIhD"}
@@ -1 +1 @@
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
+ {"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,CA0CtE,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { Signer } from 'ethers';
2
- import { SignatureData } from '@gelatonetwork/relay-sdk';
2
+ import { CallWithERC2771Request } from '@gelatonetwork/relay-sdk';
3
3
  import { VoteDetailsEntity, VoteContractDetailsEntity, VoteStatusEntity, Address } from '@reyaxyz/common';
4
4
  export type VoteInfo = {
5
- signatureData: SignatureData;
5
+ signature: string;
6
+ struct: CallWithERC2771Request;
6
7
  contractAddress: Address;
7
8
  };
8
9
  export type VoteResult = {
@@ -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,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,OAAO,EACR,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,QAAQ,GAAG;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC;CAC1B,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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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.33.0",
3
+ "version": "0.33.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@gelatonetwork/relay-sdk": "^5.5.0",
14
- "@reyaxyz/common": "0.95.0",
15
- "@reyaxyz/sdk": "0.79.2",
14
+ "@reyaxyz/common": "0.96.0",
15
+ "@reyaxyz/sdk": "0.79.3",
16
16
  "ethers": "6.9.0"
17
17
  },
18
18
  "main": "dist/index.js",
@@ -39,5 +39,5 @@
39
39
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
40
40
  },
41
41
  "packageManager": "pnpm@8.3.1",
42
- "gitHead": "4dbd0097222e0a63ea94c80a3cf1b0ead1bef0b5"
42
+ "gitHead": "0bcc7e14b9c7ddae447d9807f04a3bde3beef05e"
43
43
  }
@@ -26,7 +26,12 @@ export default class VoteModule extends RestClient implements Loggable {
26
26
  uri,
27
27
  {},
28
28
  {
29
- signatureData: voteInfo.signatureData,
29
+ signature: voteInfo.signature,
30
+ chainId: voteInfo.struct.chainId.toString(),
31
+ data: voteInfo.struct.data,
32
+ userDeadline: voteInfo.struct.userDeadline,
33
+ userNonce: (voteInfo.struct.userNonce ?? 0).toString(),
34
+ user: voteInfo.struct.user,
30
35
  contractAddress: voteInfo.contractAddress,
31
36
  },
32
37
  );
@@ -43,6 +48,12 @@ export default class VoteModule extends RestClient implements Loggable {
43
48
  ...params,
44
49
  contractAddress: metadata.contractAddress,
45
50
  });
51
+ if (!voteInfo.struct.userNonce) {
52
+ voteInfo.struct.userNonce = BigInt(await params.signer.getNonce());
53
+ }
54
+ if (!voteInfo.struct.userDeadline) {
55
+ voteInfo.struct.userDeadline = Date.now() / 1000 + 3600;
56
+ }
46
57
  return this.executeVoteTx(voteInfo);
47
58
  }
48
59
 
@@ -44,7 +44,8 @@ export const vote = async (params: ExecuteVoteParams): Promise<VoteInfo> => {
44
44
  );
45
45
 
46
46
  return {
47
- signatureData: signatureData,
47
+ signature: signatureData.signature,
48
+ struct: signatureData.struct,
48
49
  contractAddress: convertToAddress(params.contractAddress),
49
50
  };
50
51
  } catch (error) {
@@ -1,5 +1,5 @@
1
1
  import { Signer } from 'ethers';
2
- import { SignatureData } from '@gelatonetwork/relay-sdk';
2
+ import { CallWithERC2771Request } from '@gelatonetwork/relay-sdk';
3
3
  import {
4
4
  VoteDetailsEntity,
5
5
  VoteContractDetailsEntity,
@@ -8,7 +8,8 @@ import {
8
8
  } from '@reyaxyz/common';
9
9
 
10
10
  export type VoteInfo = {
11
- signatureData: SignatureData;
11
+ signature: string;
12
+ struct: CallWithERC2771Request;
12
13
  contractAddress: Address;
13
14
  };
14
15