@reyaxyz/community-sdk 0.52.48 → 0.53.1
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.
- package/dist/modules/vltz/index.js +8 -1
- package/dist/modules/vltz/index.js.map +1 -1
- package/dist/modules/vote/index.js +39 -3
- package/dist/modules/vote/index.js.map +1 -1
- package/dist/modules/vote/types.js.map +1 -1
- package/dist/types/modules/vltz/index.d.ts.map +1 -1
- package/dist/types/modules/vote/index.d.ts.map +1 -1
- package/dist/types/modules/vote/types.d.ts +2 -1
- package/dist/types/modules/vote/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/vltz/index.ts +10 -0
- package/src/modules/vote/index.ts +24 -2
- package/src/modules/vote/types.ts +7 -1
- package/dist/modules/vote/services/executeTransaction.js +0 -105
- package/dist/modules/vote/services/executeTransaction.js.map +0 -1
- package/dist/types/modules/vote/services/executeTransaction.d.ts +0 -15
- package/dist/types/modules/vote/services/executeTransaction.d.ts.map +0 -1
- package/src/modules/vote/services/executeTransaction.ts +0 -72
|
@@ -72,7 +72,7 @@ var VltzModule = /** @class */ (function (_super) {
|
|
|
72
72
|
VltzModule.prototype.mint = function (params) {
|
|
73
73
|
var _a;
|
|
74
74
|
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
-
var network, chainId, walletAddress, scaledAllocation, _b, data, value, result;
|
|
75
|
+
var network, chainId, walletAddress, scaledAllocation, deadlineMs, _b, data, value, result;
|
|
76
76
|
return __generator(this, function (_c) {
|
|
77
77
|
switch (_c.label) {
|
|
78
78
|
case 0: return [4 /*yield*/, ((_a = params.signer.provider) === null || _a === void 0 ? void 0 : _a.getNetwork())];
|
|
@@ -87,6 +87,13 @@ var VltzModule = /** @class */ (function (_super) {
|
|
|
87
87
|
chainId === common_1.MoneyInOutChainId.ethereumMainnet)) {
|
|
88
88
|
throw new Error('Network not supported. Switch to Ethereum.');
|
|
89
89
|
}
|
|
90
|
+
// if current time (UTC) is past the mint deadline, throw error
|
|
91
|
+
if (params.merkleRoot == common_1.VLTZ_MINTING_DETAILS[chainId].rounds[1].root) {
|
|
92
|
+
deadlineMs = common_1.VLTZ_MINTING_DETAILS[chainId].rounds[1].mintDeadline * 1000;
|
|
93
|
+
if (Date.now() > deadlineMs) {
|
|
94
|
+
throw new Error('Claim deadline passed');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
90
97
|
_b = (0, encode_1.encodeMint)(walletAddress, scaledAllocation, params.merkleProof, params.merkleRoot), data = _b.calldata, value = _b.value;
|
|
91
98
|
return [4 /*yield*/, (0, common_1.executeTransaction)(params.signer, data, value, chainId, params.contractAddress)];
|
|
92
99
|
case 3:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vltz/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/vltz/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAMyB;AASzB,0CAAmD;AACnD,mCAAsC;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,MAAsB;;;;;;4BACf,qBAAM,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,0CAAE,UAAU,EAAE,CAAA,EAAA;;wBAApD,OAAO,GAAG,SAA0C;wBACpD,OAAO,GAAsB,MAAM,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;wBACtC,qBAA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GAAG,GAAG,0BAAmB,MAAM,CAAC,EAAE,CAAE,CAAC;wBACpC,qBAAM,IAAI,CAAC,GAAG,CAAsB,GAAG,CAAC,EAAA;4BAA/C,sBAAO,SAAwC,EAAC;;;;KACjD;IAGK,sCAAiB,GAAjB,UAAkB,MAA4B;;;;;;wBAC5C,GAAG,GAAG,2BAAoB,MAAM,CAAC,OAAO,cAAI,MAAM,CAAC,OAAO,CAAE,CAAC;wBAC5D,qBAAM,IAAI,CAAC,GAAG,CAAuB,GAAG,CAAC,EAAA;4BAAhD,sBAAO,SAAyC,EAAC;;;;KAClD;IAxDK;QADL,IAAA,eAAM,EAAC,iBAAiB,CAAC;0CA4CzB;IAIK;QADL,IAAA,eAAM,EAAC,6BAA6B,CAAC;sDAIrC;IAGK;QADL,IAAA,eAAM,EAAC,8BAA8B,CAAC;uDAItC;IACH,iBAAC;CAAA,AAnED,CAAwC,mBAAU,GAmEjD;kBAnEoB,UAAU","sourcesContent":["import {\n executeTransaction,\n MoneyInOutChainId,\n RestClient,\n scale,\n VLTZ_MINTING_DETAILS,\n} from '@reyaxyz/common';\nimport {\n VltzMintResult,\n VltzMintParams,\n VltzRoundInfoResult,\n VltzRoundInfoParams,\n VltzWalletInfoParams,\n VltzWalletInfoResult,\n} from './types';\nimport { Logger, Loggable } from '@reyaxyz/common';\nimport { encodeMint } from './encode';\n\nexport default class VltzModule 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('VltzModule.mint')\n async mint(params: VltzMintParams): Promise<VltzMintResult> {\n const network = await params.signer.provider?.getNetwork();\n const chainId: MoneyInOutChainId = Number(network?.chainId);\n const walletAddress = await params.signer.getAddress();\n\n const scaledAllocation = scale(18)(Number(params.allocation)).toString();\n\n if (\n !(\n chainId === MoneyInOutChainId.ethereumSepolia ||\n chainId === MoneyInOutChainId.ethereumMainnet\n )\n ) {\n throw new Error('Network not supported. Switch to Ethereum.');\n }\n\n // if current time (UTC) is past the mint deadline, throw error\n if (params.merkleRoot == VLTZ_MINTING_DETAILS[chainId].rounds[1].root) {\n const deadlineMs =\n VLTZ_MINTING_DETAILS[chainId].rounds[1].mintDeadline * 1000;\n if (Date.now() > deadlineMs) {\n throw new Error('Claim deadline passed');\n }\n }\n\n const { calldata: data, value } = encodeMint(\n walletAddress,\n scaledAllocation,\n params.merkleProof,\n params.merkleRoot,\n );\n\n const result = await executeTransaction(\n params.signer,\n data,\n value,\n chainId,\n params.contractAddress,\n );\n\n return {\n transactionHash: result?.hash || null,\n };\n }\n\n // READ\n @Logger('VltzModule.getVltzRoundInfo')\n async getVltzRoundInfo(params: VltzRoundInfoParams) {\n const uri = `/api/vltz/round/${params.id}`;\n return await this.get<VltzRoundInfoResult>(uri);\n }\n\n @Logger('VltzModule.getVltzWalletInfo')\n async getVltzWalletInfo(params: VltzWalletInfoParams) {\n const uri = `/api/vltz/wallet/${params.address}/${params.roundId}`;\n return await this.get<VltzWalletInfoResult>(uri);\n }\n}\n"]}
|
|
@@ -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
|
-
|
|
74
|
-
|
|
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":"
|
|
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,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IAAA,eAAM,EAAC,iBAAiB,CAAC;0CAwBzB;IAIK;QADL,IAAA,eAAM,EAAC,2BAA2B,CAAC;oDAYnC;IAGK;QADL,IAAA,eAAM,EAAC,0BAA0B,CAAC;mDAIlC;IACH,iBAAC;CAAA,AAvDD,CAAwC,mBAAU,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 {
|
|
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/vltz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/vltz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,cAAc,EACd,cAAc,EAEd,mBAAmB,EACnB,oBAAoB,EAErB,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,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IA+CrD,gBAAgB,CAAC,MAAM,EAAE,mBAAmB;IAM5C,iBAAiB,CAAC,MAAM,EAAE,oBAAoB;CAIrD"}
|
|
@@ -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,
|
|
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,
|
|
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.
|
|
3
|
+
"version": "0.53.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -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": "
|
|
41
|
+
"gitHead": "57fea94d8cd2584baf6e2fd80eb517a61738dbc3"
|
|
42
42
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
MoneyInOutChainId,
|
|
4
4
|
RestClient,
|
|
5
5
|
scale,
|
|
6
|
+
VLTZ_MINTING_DETAILS,
|
|
6
7
|
} from '@reyaxyz/common';
|
|
7
8
|
import {
|
|
8
9
|
VltzMintResult,
|
|
@@ -41,6 +42,15 @@ export default class VltzModule extends RestClient implements Loggable {
|
|
|
41
42
|
throw new Error('Network not supported. Switch to Ethereum.');
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
// if current time (UTC) is past the mint deadline, throw error
|
|
46
|
+
if (params.merkleRoot == VLTZ_MINTING_DETAILS[chainId].rounds[1].root) {
|
|
47
|
+
const deadlineMs =
|
|
48
|
+
VLTZ_MINTING_DETAILS[chainId].rounds[1].mintDeadline * 1000;
|
|
49
|
+
if (Date.now() > deadlineMs) {
|
|
50
|
+
throw new Error('Claim deadline passed');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
44
54
|
const { calldata: data, value } = encodeMint(
|
|
45
55
|
walletAddress,
|
|
46
56
|
scaledAllocation,
|
|
@@ -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
|
-
|
|
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 {
|
|
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,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wB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D,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
|
-
}
|