@aurigami/sdk 1.11.1 → 1.12.0-beta1

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.
@@ -141,9 +141,9 @@ export declare type PlyGameBetResult = {
141
141
  */
142
142
  outcome: string;
143
143
  /**
144
- * ply lost amount
144
+ * Bet amount
145
145
  */
146
- lostAmount: TokenAmount;
146
+ amount: TokenAmount;
147
147
  unlockedPulpAmount: TokenAmount;
148
148
  block: number;
149
149
  timestamp: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.1",
2
+ "version": "1.12.0-beta1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "typescript": "^4.5.4"
63
63
  },
64
64
  "dependencies": {
65
- "@aurigami/contracts": "3.12.0-beta-4",
65
+ "@aurigami/contracts": "3.12.0-beta-3",
66
66
  "axios": "^0.26.1",
67
67
  "bignumber.js": "^9.0.2",
68
68
  "ethers": "^5.6.4"
@@ -8,6 +8,8 @@ export const AURORA_CHAINID = 1313161554;
8
8
 
9
9
  export const DECIMAL_PRECISION = 10;
10
10
 
11
+ export const AURORA_PLUS_API_PREFIX = 'https://aurora.plus/api/wallet/';
12
+
11
13
  export type NetworkAddresses = {
12
14
  auTokens: {
13
15
  name: string;
@@ -90,7 +92,7 @@ export const networkAddresses: NetworkAddresses = {
90
92
  PLY_TOKEN_LOCK: MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
91
93
  REFERRAL: MAINNET_ADDRESSES.referralDirectory.toLowerCase(),
92
94
  AURI_INTERNAL_LENS: MAINNET_ADDRESSES.auriInternalLens.toLowerCase(),
93
- PLYGAME: MAINNET_ADDRESSES.plyGame.toLowerCase(),
95
+ PLYGAME: '0x60bf668CA101060BD83BD644531a38719586B89f'.toLowerCase(), // TODO: FIX THIS AFTER PLY GAME IS DEPLOYED
94
96
  },
95
97
  tokens: {
96
98
  AURORA: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
@@ -1,8 +1,6 @@
1
- import { TypedEvent } from '@aurigami/contracts/typechain/common';
2
1
  import { Provider } from '@ethersproject/abstract-provider';
3
2
  import BigNumber from 'bignumber.js';
4
3
  import { BigNumber as BN, utils } from 'ethers';
5
- import { Result } from 'ethers/lib/utils';
6
4
  import { networkAddresses } from '../consts/constants';
7
5
  import { decimalRecords } from '../consts/decimals';
8
6
  import { symbolRecords } from '../consts/symbols';
@@ -33,12 +31,6 @@ export const getCurrentTimestamp = (): number => {
33
31
  return Math.trunc(Date.now() / 1000);
34
32
  };
35
33
 
36
- export async function sleep(duration: number): Promise<void> {
37
- return new Promise((resolve) => {
38
- setTimeout(resolve, duration);
39
- });
40
- }
41
-
42
34
  export function validateAndParseAddress(address: Address): Address {
43
35
  try {
44
36
  return utils.getAddress(address);
@@ -168,16 +160,3 @@ export function devLog(message?: any, ...optionalParams: any[]): void {
168
160
  console.log('[DEV LOG]', message, ...optionalParams);
169
161
  }
170
162
  }
171
-
172
- /**
173
- * Sorts (in place) an array of Events by blocknumber.
174
- * This method mutates the array and returns a reference to the same array.
175
- **/
176
- export function sortEvents<T extends Result>(events: TypedEvent<T>[]): TypedEvent<T>[] {
177
- return events.sort((a, b) => {
178
- if (a.blockNumber == b.blockNumber) {
179
- return a.logIndex - b.logIndex;
180
- }
181
- return a.blockNumber - b.blockNumber;
182
- });
183
- }
@@ -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, sleep, sortEvents } from '../helpers';
5
+ import { getBlocksTimestamp, isSameAddress } from '../helpers';
6
6
  import * as AuriAPI from '../helpers/aurigami-api';
7
7
  import {
8
8
  Address,
@@ -29,14 +29,11 @@ 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 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]);
32
+ let amount = event.args.amount;
33
+ let unlock = amount.mul([10, 1, 0, 0][event.args.outcome]);
37
34
  return {
38
35
  player: event.args.player,
39
- lostAmount: new TokenAmount(this.plyToken, lostAmount.toString()),
36
+ amount: new TokenAmount(this.plyToken, amount.toString()),
40
37
  unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
41
38
  outcome: outcome,
42
39
  transactionHash: event.transactionHash,
@@ -63,8 +60,6 @@ export class PlyGameRead extends BlockchainEntityRead {
63
60
 
64
61
  let filter = this.env.plygame.filters.BetMade(user);
65
62
  let events = await this.env.plygame.queryFilter(filter, block100.toNumber());
66
- // Sort descending by block number
67
- sortEvents(events).reverse();
68
63
  return this.attachTimestamp(events.map((event) => this.parseBetMakeEvent(event)));
69
64
  }
70
65
 
@@ -76,25 +71,17 @@ export class PlyGameRead extends BlockchainEntityRead {
76
71
  return new TokenAmount(this.plyToken, jackpot.toString());
77
72
  }
78
73
 
74
+ public async nextJackpotRevealTime(): Promise<number> {
75
+ return 0; // TODO: TBD
76
+ }
77
+
79
78
  public async earlyUnlockedPulpAmount(user: Address): Promise<TokenAmount> {
80
79
  let earlyUnlockedPulpAmount = await this.env.plygame.totalPlyUnlockedEarly(user);
81
80
  return new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString());
82
81
  }
83
82
 
84
83
  public async getPlyGameResultsInTransaction(txHash: Address): Promise<PlyGameBetResult[]> {
85
- // wait for the tx to be mined if needed.
86
- // Don't use `waitForTransaction` because it will wait for longer than needed.
87
84
  let tx = await this._networkConnection.provider.getTransactionReceipt(txHash);
88
-
89
- for (let i = 0; i < 100 && !tx; i++) {
90
- await sleep(1000); // Sleep for 1 second before retrying
91
- tx = await this._networkConnection.provider.getTransactionReceipt(txHash);
92
- }
93
-
94
- if (!tx) {
95
- throw new Error(`Transaction ${txHash} takes too long to be mined`);
96
- }
97
-
98
85
  let filter = this.env.plygame.filters.BetMade();
99
86
  let betMadeEvents: PlyBetMadeEvent[] = tx.logs
100
87
  .filter((log) => isSameAddress(log.topics[0], filter.topics![0] as string))
@@ -121,6 +108,15 @@ export class PlyGameRead extends BlockchainEntityRead {
121
108
  }
122
109
 
123
110
  export class PlyGameReadWrite extends PlyGameRead {
111
+ /**
112
+ * makes "times" independent bets, but consecutively, of the same amount
113
+ */
114
+ public async makeBetMultiple(amount: TokenAmount, times: number): Promise<TransactionResponse> {
115
+ return this.env.plygame
116
+ .connect(this._networkConnection.signer!)
117
+ .makeBetMultiple(amount.rawAmount(), times);
118
+ }
119
+
124
120
  /**
125
121
  * Make a single bet
126
122
  */
@@ -129,7 +125,6 @@ export class PlyGameReadWrite extends PlyGameRead {
129
125
  .connect(this._networkConnection.signer!)
130
126
  .makeBetOnce(amount.rawAmount());
131
127
  }
132
-
133
128
  public async approve(amount: TokenAmount): Promise<TransactionResponse> {
134
129
  return this.env.ply
135
130
  .connect(this._networkConnection.signer!)
@@ -1,6 +1,7 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
+ import axios from 'axios';
2
3
  import { ethers } from 'ethers';
3
- import { REFERRAL_CAMPAIGNS } from '../consts';
4
+ import { AURORA_PLUS_API_PREFIX, REFERRAL_CAMPAIGNS } from '../consts';
4
5
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
5
6
  import { getBlocksTimestamp } from '../helpers';
6
7
  import * as AuriAPI from '../helpers/aurigami-api';
@@ -101,6 +102,17 @@ export class ReferralRead extends BlockchainEntityRead {
101
102
  items.sort((a, b) => b.rewardTokenAmount.compare(a.rewardTokenAmount));
102
103
  return items;
103
104
  }
105
+
106
+ public async isWhitelistedAddress(address: Address): Promise<boolean> {
107
+ let result = await AuriAPI.getApi('/referral/whitelisted', { address: address });
108
+ return result.isWhitelisted;
109
+ }
110
+
111
+ public async isOnAuroraPlus(address: Address): Promise<boolean> {
112
+ let resp = await axios.get(AURORA_PLUS_API_PREFIX + address);
113
+
114
+ return resp.data.status == 'active';
115
+ }
104
116
  }
105
117
 
106
118
  export class ReferralReadWrite extends ReferralRead {
@@ -159,9 +159,9 @@ export type PlyGameBetResult = {
159
159
  */
160
160
  outcome: string;
161
161
  /**
162
- * ply lost amount
162
+ * Bet amount
163
163
  */
164
- lostAmount: TokenAmount;
164
+ amount: TokenAmount;
165
165
  unlockedPulpAmount: TokenAmount;
166
166
 
167
167
  block: number;