@reyaxyz/api-sdk 0.136.2 → 0.137.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/README.md +1 -1
- package/dist/clients/modules/lottery/index.js +69 -68
- package/dist/clients/modules/lottery/index.js.map +1 -1
- package/dist/clients/modules/lottery/types.js.map +1 -1
- package/dist/types/clients/modules/lottery/index.d.ts +3 -2
- package/dist/types/clients/modules/lottery/index.d.ts.map +1 -1
- package/dist/types/clients/modules/lottery/types.d.ts +1 -11
- package/dist/types/clients/modules/lottery/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/lottery/index.ts +58 -79
- package/src/clients/modules/lottery/types.ts +1 -12
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -52,7 +63,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
52
63
|
};
|
|
53
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
65
|
var common_1 = require("@reyaxyz/common");
|
|
55
|
-
var constants_1 = require("./constants");
|
|
56
66
|
var LotteryClient = /** @class */ (function (_super) {
|
|
57
67
|
__extends(LotteryClient, _super);
|
|
58
68
|
function LotteryClient(serviceEnvironment, host) {
|
|
@@ -63,19 +73,17 @@ var LotteryClient = /** @class */ (function (_super) {
|
|
|
63
73
|
}
|
|
64
74
|
LotteryClient.prototype.getLotteryPotBalance = function () {
|
|
65
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var lotteryPotOwnerAddress, lotteryPotAccountId, contributionFromReya, uri, lotteryPotMarginAccountData;
|
|
67
76
|
return __generator(this, function (_a) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
77
|
+
// const lotteryPotOwnerAddress: string =
|
|
78
|
+
// LOTTERY_CONFIGS[this.serviceEnvironment].address;
|
|
79
|
+
// const lotteryPotAccountId: MarginAccountEntity['id'] =
|
|
80
|
+
// LOTTERY_CONFIGS[this.serviceEnvironment].marginAccountId;
|
|
81
|
+
// const contributionFromReya: number = 20000;
|
|
82
|
+
// const uri = `/api/accounts/${lotteryPotOwnerAddress}/marginAccount/${lotteryPotAccountId}`;
|
|
83
|
+
// const lotteryPotMarginAccountData: MarginAccountEntity =
|
|
84
|
+
// await this.get<MarginAccountEntity>(uri);
|
|
85
|
+
// return lotteryPotMarginAccountData.totalBalance + contributionFromReya;
|
|
86
|
+
return [2 /*return*/, 23598.637065];
|
|
79
87
|
});
|
|
80
88
|
});
|
|
81
89
|
};
|
|
@@ -88,70 +96,63 @@ var LotteryClient = /** @class */ (function (_super) {
|
|
|
88
96
|
});
|
|
89
97
|
});
|
|
90
98
|
};
|
|
91
|
-
LotteryClient.prototype.
|
|
99
|
+
LotteryClient.prototype.getEnhancedLotteryWinners = function (lotteryWinners) {
|
|
92
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var
|
|
101
|
+
var lotteryPot, amounts, enhancedLotteryWinners;
|
|
94
102
|
return __generator(this, function (_a) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
amount: 10,
|
|
112
|
-
place: 3,
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
executor: {
|
|
116
|
-
address: (0, common_1.convertToAddress)('0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5'),
|
|
117
|
-
timestampMs: 1728389136000,
|
|
118
|
-
},
|
|
119
|
-
}];
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0: return [4 /*yield*/, this.getLotteryPotBalance()];
|
|
105
|
+
case 1:
|
|
106
|
+
lotteryPot = _a.sent();
|
|
107
|
+
amounts = {
|
|
108
|
+
1: lotteryPot * 0.7,
|
|
109
|
+
2: lotteryPot * 0.2,
|
|
110
|
+
3: lotteryPot * 0.1,
|
|
111
|
+
};
|
|
112
|
+
enhancedLotteryWinners = {
|
|
113
|
+
winners: lotteryWinners.winners.map(function (winner) {
|
|
114
|
+
return __assign(__assign({}, winner), { amount: amounts[winner.place] });
|
|
115
|
+
}),
|
|
116
|
+
executor: lotteryWinners.executor,
|
|
117
|
+
};
|
|
118
|
+
return [2 /*return*/, enhancedLotteryWinners];
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
LotteryClient.prototype.getLotteryWinners = function () {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var uri, lotteryWinners;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
uri = '/api/xp/lottery/get-winners';
|
|
130
|
+
return [4 /*yield*/, this.get(uri)];
|
|
131
|
+
case 1:
|
|
132
|
+
lotteryWinners = _a.sent();
|
|
133
|
+
if (lotteryWinners === null) {
|
|
134
|
+
return [2 /*return*/, null];
|
|
135
|
+
}
|
|
136
|
+
return [2 /*return*/, this.getEnhancedLotteryWinners(lotteryWinners)];
|
|
123
137
|
}
|
|
124
|
-
return [2 /*return*/];
|
|
125
138
|
});
|
|
126
139
|
});
|
|
127
140
|
};
|
|
128
|
-
LotteryClient.prototype.selectLotteryWinners = function () {
|
|
141
|
+
LotteryClient.prototype.selectLotteryWinners = function (params) {
|
|
129
142
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
var uri, lotteryWinners;
|
|
130
144
|
return __generator(this, function (_a) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
winners
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
place: 2,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
address: (0, common_1.convertToAddress)('0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9'),
|
|
146
|
-
amount: 10,
|
|
147
|
-
place: 3,
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
executor: {
|
|
151
|
-
address: (0, common_1.convertToAddress)('0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5'),
|
|
152
|
-
timestampMs: 1728389136000,
|
|
153
|
-
},
|
|
154
|
-
}];
|
|
145
|
+
switch (_a.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
uri = "/api/xp/lottery/select-winners/".concat(params.executorAddress);
|
|
148
|
+
return [4 /*yield*/, this.get(uri)];
|
|
149
|
+
case 1:
|
|
150
|
+
lotteryWinners = _a.sent();
|
|
151
|
+
if (lotteryWinners === null) {
|
|
152
|
+
throw new Error('Unpexpected error while selecting lottery winners');
|
|
153
|
+
}
|
|
154
|
+
return [2 /*return*/, this.getEnhancedLotteryWinners(lotteryWinners)];
|
|
155
|
+
}
|
|
155
156
|
});
|
|
156
157
|
});
|
|
157
158
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/lottery/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/lottery/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AAGzB;IAA2C,iCAAU;IAEnD,uBAAY,kBAAsC,EAAE,IAAY;QAC9D,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC;QAFN,wBAAkB,GAAuB,MAAM,CAAC;QAGtD,KAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;;IAC/C,CAAC;IAEK,4CAAoB,GAA1B;;;gBACE,yCAAyC;gBACzC,sDAAsD;gBACtD,yDAAyD;gBACzD,8DAA8D;gBAC9D,8CAA8C;gBAE9C,8FAA8F;gBAC9F,2DAA2D;gBAC3D,8CAA8C;gBAC9C,0EAA0E;gBAE1E,sBAAO,YAAY,EAAC;;;KACrB;IAEK,iDAAyB,GAA/B,UAAgC,aAAqB;;;gBACnD,+BAA+B;gBAC/B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAC3B,sBAAO,CAAC,EAAC;;;KACV;IAEa,iDAAyB,GAAvC,UACE,cAAuC;;;;;4BAEpB,qBAAM,IAAI,CAAC,oBAAoB,EAAE,EAAA;;wBAA9C,UAAU,GAAG,SAAiC;wBAC9C,OAAO,GAAG;4BACd,CAAC,EAAE,UAAU,GAAG,GAAG;4BACnB,CAAC,EAAE,UAAU,GAAG,GAAG;4BACnB,CAAC,EAAE,UAAU,GAAG,GAAG;yBACpB,CAAC;wBAEI,sBAAsB,GAAyB;4BACnD,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,MAAM;gCACzC,6BACK,MAAM,KACT,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,KAAkB,CAAC,IAC1C;4BACJ,CAAC,CAAC;4BACF,QAAQ,EAAE,cAAc,CAAC,QAAQ;yBAClC,CAAC;wBAEF,sBAAO,sBAAsB,EAAC;;;;KAC/B;IAEK,yCAAiB,GAAvB;;;;;;wBACQ,GAAG,GAAG,6BAA6B,CAAC;wBAGxC,qBAAM,IAAI,CAAC,GAAG,CAAiC,GAAG,CAAC,EAAA;;wBAD/C,cAAc,GAClB,SAAmD;wBAErD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;4BAC5B,sBAAO,IAAI,EAAC;wBACd,CAAC;wBAED,sBAAO,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,EAAC;;;;KACvD;IAEK,4CAAoB,GAA1B,UACE,MAAkC;;;;;;wBAE5B,GAAG,GAAG,yCAAkC,MAAM,CAAC,eAAe,CAAE,CAAC;wBAGrE,qBAAM,IAAI,CAAC,GAAG,CAA8B,GAAG,CAAC,EAAA;;wBAD5C,cAAc,GAClB,SAAgD;wBAElD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;4BAC5B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;wBACvE,CAAC;wBAED,sBAAO,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,EAAC;;;;KACvD;IACH,oBAAC;AAAD,CAAC,AA9ED,CAA2C,mBAAU,GA8EpD","sourcesContent":["import {\n RestClient,\n ServiceEnvironment,\n GetLotteryWinnersResult,\n SelectLotteryWinnersParams,\n} from '@reyaxyz/common';\nimport { LotteryWinnersResult } from './types';\n\nexport default class LotteryClient extends RestClient {\n private serviceEnvironment: ServiceEnvironment = 'test';\n constructor(serviceEnvironment: ServiceEnvironment, host: string) {\n super(host);\n this.serviceEnvironment = serviceEnvironment;\n }\n\n async getLotteryPotBalance(): Promise<number> {\n // const lotteryPotOwnerAddress: string =\n // LOTTERY_CONFIGS[this.serviceEnvironment].address;\n // const lotteryPotAccountId: MarginAccountEntity['id'] =\n // LOTTERY_CONFIGS[this.serviceEnvironment].marginAccountId;\n // const contributionFromReya: number = 20000;\n\n // const uri = `/api/accounts/${lotteryPotOwnerAddress}/marginAccount/${lotteryPotAccountId}`;\n // const lotteryPotMarginAccountData: MarginAccountEntity =\n // await this.get<MarginAccountEntity>(uri);\n // return lotteryPotMarginAccountData.totalBalance + contributionFromReya;\n\n return 23598.637065;\n }\n\n async getNumberOfLotteryTickets(walletAddress: string): Promise<number> {\n // todo: p1: add implementation\n console.log(walletAddress);\n return 1;\n }\n\n private async getEnhancedLotteryWinners(\n lotteryWinners: GetLotteryWinnersResult,\n ): Promise<LotteryWinnersResult> {\n const lotteryPot = await this.getLotteryPotBalance();\n const amounts = {\n 1: lotteryPot * 0.7,\n 2: lotteryPot * 0.2,\n 3: lotteryPot * 0.1,\n };\n\n const enhancedLotteryWinners: LotteryWinnersResult = {\n winners: lotteryWinners.winners.map((winner) => {\n return {\n ...winner,\n amount: amounts[winner.place as 1 | 2 | 3],\n };\n }),\n executor: lotteryWinners.executor,\n };\n\n return enhancedLotteryWinners;\n }\n\n async getLotteryWinners(): Promise<LotteryWinnersResult | null> {\n const uri = '/api/xp/lottery/get-winners';\n\n const lotteryWinners: GetLotteryWinnersResult | null =\n await this.get<GetLotteryWinnersResult | null>(uri);\n\n if (lotteryWinners === null) {\n return null;\n }\n\n return this.getEnhancedLotteryWinners(lotteryWinners);\n }\n\n async selectLotteryWinners(\n params: SelectLotteryWinnersParams,\n ): Promise<LotteryWinnersResult> {\n const uri = `/api/xp/lottery/select-winners/${params.executorAddress}`;\n\n const lotteryWinners: LotteryWinnersResult | null =\n await this.get<LotteryWinnersResult | null>(uri);\n\n if (lotteryWinners === null) {\n throw new Error('Unpexpected error while selecting lottery winners');\n }\n\n return this.getEnhancedLotteryWinners(lotteryWinners);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/lottery/types.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/lottery/types.ts"],"names":[],"mappings":"","sourcesContent":["import { WinnerData, ExecutorData } from '@reyaxyz/common';\n\nexport type LotteryWinnersResult = {\n winners: WinnerData[];\n executor: ExecutorData;\n};\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { RestClient, ServiceEnvironment } from '@reyaxyz/common';
|
|
1
|
+
import { RestClient, ServiceEnvironment, SelectLotteryWinnersParams } from '@reyaxyz/common';
|
|
2
2
|
import { LotteryWinnersResult } from './types';
|
|
3
3
|
export default class LotteryClient extends RestClient {
|
|
4
4
|
private serviceEnvironment;
|
|
5
5
|
constructor(serviceEnvironment: ServiceEnvironment, host: string);
|
|
6
6
|
getLotteryPotBalance(): Promise<number>;
|
|
7
7
|
getNumberOfLotteryTickets(walletAddress: string): Promise<number>;
|
|
8
|
+
private getEnhancedLotteryWinners;
|
|
8
9
|
getLotteryWinners(): Promise<LotteryWinnersResult | null>;
|
|
9
|
-
selectLotteryWinners(): Promise<LotteryWinnersResult>;
|
|
10
|
+
selectLotteryWinners(params: SelectLotteryWinnersParams): Promise<LotteryWinnersResult>;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/lottery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/lottery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,kBAAkB,EAElB,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD,OAAO,CAAC,kBAAkB,CAA8B;gBAC5C,kBAAkB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM;IAK1D,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAevC,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAMzD,yBAAyB;IAuBjC,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAazD,oBAAoB,CACxB,MAAM,EAAE,0BAA0B,GACjC,OAAO,CAAC,oBAAoB,CAAC;CAYjC"}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type WinnerData = {
|
|
3
|
-
address: Address;
|
|
4
|
-
amount: number;
|
|
5
|
-
place: number;
|
|
6
|
-
};
|
|
7
|
-
type ExecutorData = {
|
|
8
|
-
address: Address;
|
|
9
|
-
timestampMs: number;
|
|
10
|
-
};
|
|
1
|
+
import { WinnerData, ExecutorData } from '@reyaxyz/common';
|
|
11
2
|
export type LotteryWinnersResult = {
|
|
12
3
|
winners: WinnerData[];
|
|
13
4
|
executor: ExecutorData;
|
|
14
5
|
};
|
|
15
|
-
export {};
|
|
16
6
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/lottery/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/lottery/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.137.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@reyaxyz/common": "0.
|
|
36
|
+
"@reyaxyz/common": "0.210.0",
|
|
37
37
|
"@simplewebauthn/types": "^10.0.0",
|
|
38
38
|
"axios": "^1.6.2",
|
|
39
39
|
"bignumber.js": "^9.1.2",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ws": "^8.16.0"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "28bc98dc143130a4ba89855cd1fbfbf0c0280db3",
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/ws": "8.5.10"
|
|
48
48
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RestClient,
|
|
3
|
-
MarginAccountEntity,
|
|
4
3
|
ServiceEnvironment,
|
|
5
|
-
|
|
4
|
+
GetLotteryWinnersResult,
|
|
5
|
+
SelectLotteryWinnersParams,
|
|
6
6
|
} from '@reyaxyz/common';
|
|
7
|
-
import { LOTTERY_CONFIGS } from './constants';
|
|
8
7
|
import { LotteryWinnersResult } from './types';
|
|
9
8
|
|
|
10
9
|
export default class LotteryClient extends RestClient {
|
|
@@ -15,16 +14,18 @@ export default class LotteryClient extends RestClient {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
async getLotteryPotBalance(): Promise<number> {
|
|
18
|
-
const lotteryPotOwnerAddress: string =
|
|
19
|
-
|
|
20
|
-
const lotteryPotAccountId: MarginAccountEntity['id'] =
|
|
21
|
-
|
|
22
|
-
const contributionFromReya: number = 20000;
|
|
23
|
-
|
|
24
|
-
const uri = `/api/accounts/${lotteryPotOwnerAddress}/marginAccount/${lotteryPotAccountId}`;
|
|
25
|
-
const lotteryPotMarginAccountData: MarginAccountEntity =
|
|
26
|
-
|
|
27
|
-
return lotteryPotMarginAccountData.totalBalance + contributionFromReya;
|
|
17
|
+
// const lotteryPotOwnerAddress: string =
|
|
18
|
+
// LOTTERY_CONFIGS[this.serviceEnvironment].address;
|
|
19
|
+
// const lotteryPotAccountId: MarginAccountEntity['id'] =
|
|
20
|
+
// LOTTERY_CONFIGS[this.serviceEnvironment].marginAccountId;
|
|
21
|
+
// const contributionFromReya: number = 20000;
|
|
22
|
+
|
|
23
|
+
// const uri = `/api/accounts/${lotteryPotOwnerAddress}/marginAccount/${lotteryPotAccountId}`;
|
|
24
|
+
// const lotteryPotMarginAccountData: MarginAccountEntity =
|
|
25
|
+
// await this.get<MarginAccountEntity>(uri);
|
|
26
|
+
// return lotteryPotMarginAccountData.totalBalance + contributionFromReya;
|
|
27
|
+
|
|
28
|
+
return 23598.637065;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
async getNumberOfLotteryTickets(walletAddress: string): Promise<number> {
|
|
@@ -33,76 +34,54 @@ export default class LotteryClient extends RestClient {
|
|
|
33
34
|
return 1;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
private async getEnhancedLotteryWinners(
|
|
38
|
+
lotteryWinners: GetLotteryWinnersResult,
|
|
39
|
+
): Promise<LotteryWinnersResult> {
|
|
40
|
+
const lotteryPot = await this.getLotteryPotBalance();
|
|
41
|
+
const amounts = {
|
|
42
|
+
1: lotteryPot * 0.7,
|
|
43
|
+
2: lotteryPot * 0.2,
|
|
44
|
+
3: lotteryPot * 0.1,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const enhancedLotteryWinners: LotteryWinnersResult = {
|
|
48
|
+
winners: lotteryWinners.winners.map((winner) => {
|
|
49
|
+
return {
|
|
50
|
+
...winner,
|
|
51
|
+
amount: amounts[winner.place as 1 | 2 | 3],
|
|
52
|
+
};
|
|
53
|
+
}),
|
|
54
|
+
executor: lotteryWinners.executor,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return enhancedLotteryWinners;
|
|
58
|
+
}
|
|
59
|
+
|
|
36
60
|
async getLotteryWinners(): Promise<LotteryWinnersResult | null> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
address: convertToAddress(
|
|
44
|
-
'0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1',
|
|
45
|
-
),
|
|
46
|
-
amount: 70,
|
|
47
|
-
place: 1,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
address: convertToAddress(
|
|
51
|
-
'0xaE173a960084903b1d278Ff9E3A81DeD82275556',
|
|
52
|
-
),
|
|
53
|
-
amount: 20,
|
|
54
|
-
place: 2,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
address: convertToAddress(
|
|
58
|
-
'0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9',
|
|
59
|
-
),
|
|
60
|
-
amount: 10,
|
|
61
|
-
place: 3,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
executor: {
|
|
65
|
-
address: convertToAddress(
|
|
66
|
-
'0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5',
|
|
67
|
-
),
|
|
68
|
-
timestampMs: 1728389136000,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
} else {
|
|
61
|
+
const uri = '/api/xp/lottery/get-winners';
|
|
62
|
+
|
|
63
|
+
const lotteryWinners: GetLotteryWinnersResult | null =
|
|
64
|
+
await this.get<GetLotteryWinnersResult | null>(uri);
|
|
65
|
+
|
|
66
|
+
if (lotteryWinners === null) {
|
|
72
67
|
return null;
|
|
73
68
|
}
|
|
69
|
+
|
|
70
|
+
return this.getEnhancedLotteryWinners(lotteryWinners);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
async selectLotteryWinners(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
'0xaE173a960084903b1d278Ff9E3A81DeD82275556',
|
|
90
|
-
),
|
|
91
|
-
amount: 20,
|
|
92
|
-
place: 2,
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
address: convertToAddress(
|
|
96
|
-
'0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9',
|
|
97
|
-
),
|
|
98
|
-
amount: 10,
|
|
99
|
-
place: 3,
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
executor: {
|
|
103
|
-
address: convertToAddress('0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5'),
|
|
104
|
-
timestampMs: 1728389136000,
|
|
105
|
-
},
|
|
106
|
-
};
|
|
73
|
+
async selectLotteryWinners(
|
|
74
|
+
params: SelectLotteryWinnersParams,
|
|
75
|
+
): Promise<LotteryWinnersResult> {
|
|
76
|
+
const uri = `/api/xp/lottery/select-winners/${params.executorAddress}`;
|
|
77
|
+
|
|
78
|
+
const lotteryWinners: LotteryWinnersResult | null =
|
|
79
|
+
await this.get<LotteryWinnersResult | null>(uri);
|
|
80
|
+
|
|
81
|
+
if (lotteryWinners === null) {
|
|
82
|
+
throw new Error('Unpexpected error while selecting lottery winners');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return this.getEnhancedLotteryWinners(lotteryWinners);
|
|
107
86
|
}
|
|
108
87
|
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type WinnerData = {
|
|
4
|
-
address: Address;
|
|
5
|
-
amount: number;
|
|
6
|
-
place: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type ExecutorData = {
|
|
10
|
-
address: Address;
|
|
11
|
-
timestampMs: number;
|
|
12
|
-
};
|
|
1
|
+
import { WinnerData, ExecutorData } from '@reyaxyz/common';
|
|
13
2
|
|
|
14
3
|
export type LotteryWinnersResult = {
|
|
15
4
|
winners: WinnerData[];
|