@aurigami/sdk 1.11.0-beta1 → 1.11.0-beta3

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.
@@ -152,6 +152,11 @@ export declare type PlyGameBetResult = {
152
152
  */
153
153
  transactionHash: string;
154
154
  };
155
+ export declare type PlyGameLeaderboardItem = {
156
+ player: string;
157
+ gamesPlayed: number;
158
+ unlockedPulpAmount: TokenAmount;
159
+ };
155
160
  export declare type PlyBetMadeEvent = TypedEvent<[string, BN, number] & {
156
161
  player: string;
157
162
  amount: BN;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.0-beta1",
2
+ "version": "1.11.0-beta3",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,6 +1,8 @@
1
+ import { TypedEvent } from '@aurigami/contracts/typechain/common';
1
2
  import { Provider } from '@ethersproject/abstract-provider';
2
3
  import BigNumber from 'bignumber.js';
3
4
  import { BigNumber as BN, utils } from 'ethers';
5
+ import { Result } from 'ethers/lib/utils';
4
6
  import { networkAddresses } from '../consts/constants';
5
7
  import { decimalRecords } from '../consts/decimals';
6
8
  import { symbolRecords } from '../consts/symbols';
@@ -160,3 +162,16 @@ export function devLog(message?: any, ...optionalParams: any[]): void {
160
162
  console.log('[DEV LOG]', message, ...optionalParams);
161
163
  }
162
164
  }
165
+
166
+ /**
167
+ * Sorts (in place) an array of Events by blocknumber.
168
+ * This method mutates the array and returns a reference to the same array.
169
+ **/
170
+ export function sortEvents<T extends Result>(events: TypedEvent<T>[]): TypedEvent<T>[] {
171
+ return events.sort((a, b) => {
172
+ if (a.blockNumber == b.blockNumber) {
173
+ return a.logIndex - b.logIndex;
174
+ }
175
+ return a.blockNumber - b.blockNumber;
176
+ });
177
+ }
@@ -2,8 +2,15 @@ import { TransactionResponse } from '@ethersproject/abstract-provider';
2
2
  import * as consts from '../consts';
3
3
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
4
4
  import * as helpers from '../helpers';
5
- import { getBlocksTimestamp, isSameAddress } from '../helpers';
6
- import { Address, NetworkConnection, PlyBetMadeEvent, PlyGameBetResult } from '../types';
5
+ import { getBlocksTimestamp, isSameAddress, sortEvents } from '../helpers';
6
+ import * as AuriAPI from '../helpers/aurigami-api';
7
+ import {
8
+ Address,
9
+ NetworkConnection,
10
+ PlyBetMadeEvent,
11
+ PlyGameBetResult,
12
+ PlyGameLeaderboardItem,
13
+ } from '../types';
7
14
 
8
15
  export class PlyGameRead extends BlockchainEntityRead {
9
16
  public readonly plyToken: Token;
@@ -53,6 +60,8 @@ export class PlyGameRead extends BlockchainEntityRead {
53
60
 
54
61
  let filter = this.env.plygame.filters.BetMade(user);
55
62
  let events = await this.env.plygame.queryFilter(filter, block100.toNumber());
63
+ // Sort descending by block number
64
+ sortEvents(events).reverse();
56
65
  return this.attachTimestamp(events.map((event) => this.parseBetMakeEvent(event)));
57
66
  }
58
67
 
@@ -86,6 +95,18 @@ export class PlyGameRead extends BlockchainEntityRead {
86
95
 
87
96
  return this.attachTimestamp(betMadeEvents.map((e) => this.parseBetMakeEvent(e)));
88
97
  }
98
+
99
+ /**
100
+ * Top 100 users by amount of PULP unlocked
101
+ */
102
+ public async leaderboard(): Promise<PlyGameLeaderboardItem[]> {
103
+ const result = await AuriAPI.getPaginatedApi('/plygame/leaderboard');
104
+ return result.items.map((item, i) => ({
105
+ player: item.user!,
106
+ unlockedPulpAmount: new TokenAmount(this.pulpToken, item.unlockedAmount!),
107
+ gamesPlayed: item.count!,
108
+ }));
109
+ }
89
110
  }
90
111
 
91
112
  export class PlyGameReadWrite extends PlyGameRead {
@@ -172,6 +172,12 @@ export type PlyGameBetResult = {
172
172
  transactionHash: string;
173
173
  };
174
174
 
175
+ export type PlyGameLeaderboardItem = {
176
+ player: string;
177
+ gamesPlayed: number;
178
+ unlockedPulpAmount: TokenAmount;
179
+ };
180
+
175
181
  export type PlyBetMadeEvent = TypedEvent<
176
182
  [string, BN, number] & { player: string; amount: BN; outcome: number }
177
183
  >;