@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 CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-1.32%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-6.81%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0.51%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-1.33%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-1.31%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-6.81%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0.5%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-1.32%25-red.svg?style=flat) |
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
- switch (_a.label) {
69
- case 0:
70
- lotteryPotOwnerAddress = constants_1.LOTTERY_CONFIGS[this.serviceEnvironment].address;
71
- lotteryPotAccountId = constants_1.LOTTERY_CONFIGS[this.serviceEnvironment].marginAccountId;
72
- contributionFromReya = 20000;
73
- uri = "/api/accounts/".concat(lotteryPotOwnerAddress, "/marginAccount/").concat(lotteryPotAccountId);
74
- return [4 /*yield*/, this.get(uri)];
75
- case 1:
76
- lotteryPotMarginAccountData = _a.sent();
77
- return [2 /*return*/, lotteryPotMarginAccountData.totalBalance + contributionFromReya];
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.getLotteryWinners = function () {
99
+ LotteryClient.prototype.getEnhancedLotteryWinners = function (lotteryWinners) {
92
100
  return __awaiter(this, void 0, void 0, function () {
93
- var r;
101
+ var lotteryPot, amounts, enhancedLotteryWinners;
94
102
  return __generator(this, function (_a) {
95
- r = Math.random();
96
- if (r < 0.5) {
97
- return [2 /*return*/, {
98
- winners: [
99
- {
100
- address: (0, common_1.convertToAddress)('0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1'),
101
- amount: 70,
102
- place: 1,
103
- },
104
- {
105
- address: (0, common_1.convertToAddress)('0xaE173a960084903b1d278Ff9E3A81DeD82275556'),
106
- amount: 20,
107
- place: 2,
108
- },
109
- {
110
- address: (0, common_1.convertToAddress)('0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9'),
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
- else {
122
- return [2 /*return*/, null];
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
- // todo: this is a mock
132
- return [2 /*return*/, {
133
- winners: [
134
- {
135
- address: (0, common_1.convertToAddress)('0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1'),
136
- amount: 70,
137
- place: 1,
138
- },
139
- {
140
- address: (0, common_1.convertToAddress)('0xaE173a960084903b1d278Ff9E3A81DeD82275556'),
141
- amount: 20,
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AACzB,yCAA8C;AAG9C;IAA2C,iCAAU;IAEnD,uBAAY,kBAAsC,EAAE,IAAY;QAC9D,YAAA,MAAK,YAAC,IAAI,CAAC,SAAC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,EACvB,4CAA4C,CAC7C;gCACD,WAAW,EAAE,aAAa;6BAC3B;yBACF,EAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,sBAAO,IAAI,EAAC;gBACd,CAAC;;;;KACF;IAEK,4CAAoB,GAA1B;;;gBACE,uBAAuB;gBACvB,sBAAO;wBACL,OAAO,EAAE;4BACP;gCACE,OAAO,EAAE,IAAA,yBAAgB,EACvB,4CAA4C,CAC7C;gCACD,MAAM,EAAE,EAAE;gCACV,KAAK,EAAE,CAAC;6BACT;4BACD;gCACE,OAAO,EAAE,IAAA,yBAAgB,EACvB,4CAA4C,CAC7C;gCACD,MAAM,EAAE,EAAE;gCACV,KAAK,EAAE,CAAC;6BACT;4BACD;gCACE,OAAO,EAAE,IAAA,yBAAgB,EACvB,4CAA4C,CAC7C;gCACD,MAAM,EAAE,EAAE;gCACV,KAAK,EAAE,CAAC;6BACT;yBACF;wBACD,QAAQ,EAAE;4BACR,OAAO,EAAE,IAAA,yBAAgB,EAAC,4CAA4C,CAAC;4BACvE,WAAW,EAAE,aAAa;yBAC3B;qBACF,EAAC;;;KACH;IACH,oBAAC;AAAD,CAAC,AAlGD,CAA2C,mBAAU,GAkGpD","sourcesContent":["import {\n RestClient,\n MarginAccountEntity,\n ServiceEnvironment,\n convertToAddress,\n} from '@reyaxyz/common';\nimport { LOTTERY_CONFIGS } from './constants';\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\n async getNumberOfLotteryTickets(walletAddress: string): Promise<number> {\n // todo: p1: add implementation\n console.log(walletAddress);\n return 1;\n }\n\n async getLotteryWinners(): Promise<LotteryWinnersResult | null> {\n // todo: this is a mock\n const r = Math.random();\n if (r < 0.5) {\n return {\n winners: [\n {\n address: convertToAddress(\n '0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1',\n ),\n amount: 70,\n place: 1,\n },\n {\n address: convertToAddress(\n '0xaE173a960084903b1d278Ff9E3A81DeD82275556',\n ),\n amount: 20,\n place: 2,\n },\n {\n address: convertToAddress(\n '0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9',\n ),\n amount: 10,\n place: 3,\n },\n ],\n executor: {\n address: convertToAddress(\n '0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5',\n ),\n timestampMs: 1728389136000,\n },\n };\n } else {\n return null;\n }\n }\n\n async selectLotteryWinners(): Promise<LotteryWinnersResult> {\n // todo: this is a mock\n return {\n winners: [\n {\n address: convertToAddress(\n '0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1',\n ),\n amount: 70,\n place: 1,\n },\n {\n address: convertToAddress(\n '0xaE173a960084903b1d278Ff9E3A81DeD82275556',\n ),\n amount: 20,\n place: 2,\n },\n {\n address: convertToAddress(\n '0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9',\n ),\n amount: 10,\n place: 3,\n },\n ],\n executor: {\n address: convertToAddress('0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5'),\n timestampMs: 1728389136000,\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/lottery/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB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;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 { Address } from '@reyaxyz/common';\n\ntype WinnerData = {\n address: Address;\n amount: number;\n place: number;\n};\n\ntype ExecutorData = {\n address: Address;\n timestampMs: number;\n};\n\nexport type LotteryWinnersResult = {\n winners: WinnerData[];\n executor: ExecutorData;\n};\n"]}
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,EAEV,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAEzB,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;IAavC,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMjE,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAwCzD,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC;CAgC5D"}
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 { Address } from '@reyaxyz/common';
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,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,KAAK,UAAU,GAAG;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC"}
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.136.2",
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.209.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": "069bdece153b9bf76b73274ed29189a3f9899396",
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
- convertToAddress,
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
- LOTTERY_CONFIGS[this.serviceEnvironment].address;
20
- const lotteryPotAccountId: MarginAccountEntity['id'] =
21
- LOTTERY_CONFIGS[this.serviceEnvironment].marginAccountId;
22
- const contributionFromReya: number = 20000;
23
-
24
- const uri = `/api/accounts/${lotteryPotOwnerAddress}/marginAccount/${lotteryPotAccountId}`;
25
- const lotteryPotMarginAccountData: MarginAccountEntity =
26
- await this.get<MarginAccountEntity>(uri);
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
- // todo: this is a mock
38
- const r = Math.random();
39
- if (r < 0.5) {
40
- return {
41
- winners: [
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(): Promise<LotteryWinnersResult> {
77
- // todo: this is a mock
78
- return {
79
- winners: [
80
- {
81
- address: convertToAddress(
82
- '0xF8F6B70a36f4398f0853a311dC6699Aba8333Cc1',
83
- ),
84
- amount: 70,
85
- place: 1,
86
- },
87
- {
88
- address: convertToAddress(
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 { Address } from '@reyaxyz/common';
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[];