@aurigami/sdk 1.11.0-beta2 → 1.11.0-beta4
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/helpers/helpers.d.ts +7 -0
- package/dist/sdk.cjs.development.js +25 -4
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +25 -5
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/helpers/helpers.ts +15 -0
- package/src/interactors/PlyGame.ts +9 -4
- package/src/types/index.ts +2 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -141,9 +141,9 @@ export declare type PlyGameBetResult = {
|
|
|
141
141
|
*/
|
|
142
142
|
outcome: string;
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
144
|
+
* ply lost amount
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
lostAmount: TokenAmount;
|
|
147
147
|
unlockedPulpAmount: TokenAmount;
|
|
148
148
|
block: number;
|
|
149
149
|
timestamp: number;
|
package/package.json
CHANGED
package/src/helpers/helpers.ts
CHANGED
|
@@ -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,7 +2,7 @@ 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';
|
|
5
|
+
import { getBlocksTimestamp, isSameAddress, sortEvents } from '../helpers';
|
|
6
6
|
import * as AuriAPI from '../helpers/aurigami-api';
|
|
7
7
|
import {
|
|
8
8
|
Address,
|
|
@@ -29,11 +29,14 @@ export class PlyGameRead extends BlockchainEntityRead {
|
|
|
29
29
|
|
|
30
30
|
private parseBetMakeEvent(event: PlyBetMadeEvent): PlyGameBetResult {
|
|
31
31
|
let outcome = ['bigWin', 'win', 'lose', 'noImpact'][event.args.outcome];
|
|
32
|
-
let
|
|
33
|
-
|
|
32
|
+
let betAmount = event.args.amount;
|
|
33
|
+
// 0%, 0%, 100%, 2%
|
|
34
|
+
// big win, win, lose, no impact
|
|
35
|
+
let lostAmount = betAmount.mul([0, 0, 100, 2][event.args.outcome]).div(100);
|
|
36
|
+
let unlock = betAmount.mul([10, 1, 0, 0][event.args.outcome]);
|
|
34
37
|
return {
|
|
35
38
|
player: event.args.player,
|
|
36
|
-
|
|
39
|
+
lostAmount: new TokenAmount(this.plyToken, lostAmount.toString()),
|
|
37
40
|
unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
|
|
38
41
|
outcome: outcome,
|
|
39
42
|
transactionHash: event.transactionHash,
|
|
@@ -60,6 +63,8 @@ export class PlyGameRead extends BlockchainEntityRead {
|
|
|
60
63
|
|
|
61
64
|
let filter = this.env.plygame.filters.BetMade(user);
|
|
62
65
|
let events = await this.env.plygame.queryFilter(filter, block100.toNumber());
|
|
66
|
+
// Sort descending by block number
|
|
67
|
+
sortEvents(events).reverse();
|
|
63
68
|
return this.attachTimestamp(events.map((event) => this.parseBetMakeEvent(event)));
|
|
64
69
|
}
|
|
65
70
|
|
package/src/types/index.ts
CHANGED