@aurigami/sdk 1.12.0-beta1 → 1.12.0-beta2

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.
@@ -133,6 +133,7 @@ export declare type ReferralReward = {
133
133
  * hash of the transaction on aurorascan (if no, return null)
134
134
  */
135
135
  transactionHash: string | null;
136
+ refereeAddress: string | null;
136
137
  };
137
138
  export declare type PlyGameBetResult = {
138
139
  player: string;
@@ -141,9 +142,9 @@ export declare type PlyGameBetResult = {
141
142
  */
142
143
  outcome: string;
143
144
  /**
144
- * Bet amount
145
+ * ply lost amount
145
146
  */
146
- amount: TokenAmount;
147
+ lostAmount: TokenAmount;
147
148
  unlockedPulpAmount: TokenAmount;
148
149
  block: number;
149
150
  timestamp: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.12.0-beta1",
2
+ "version": "1.12.0-beta2",
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-3",
65
+ "@aurigami/contracts": "3.12.0-beta-4",
66
66
  "axios": "^0.26.1",
67
67
  "bignumber.js": "^9.0.2",
68
68
  "ethers": "^5.6.4"
@@ -70,4 +70,4 @@
70
70
  "jest": {
71
71
  "testURL": "https://app.aurigami.finance"
72
72
  }
73
- }
73
+ }
@@ -92,7 +92,7 @@ export const networkAddresses: NetworkAddresses = {
92
92
  PLY_TOKEN_LOCK: MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
93
93
  REFERRAL: MAINNET_ADDRESSES.referralDirectory.toLowerCase(),
94
94
  AURI_INTERNAL_LENS: MAINNET_ADDRESSES.auriInternalLens.toLowerCase(),
95
- PLYGAME: '0x60bf668CA101060BD83BD644531a38719586B89f'.toLowerCase(), // TODO: FIX THIS AFTER PLY GAME IS DEPLOYED
95
+ PLYGAME: MAINNET_ADDRESSES.plyGame.toLowerCase(),
96
96
  },
97
97
  tokens: {
98
98
  AURORA: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
@@ -30,20 +30,22 @@ export const dummyUserMarketDetails: UserMarketDetails = {
30
30
 
31
31
  export const referralRewardDummy1: ReferralReward = {
32
32
  campaign: 'testa',
33
- startTime: 1652882400, // May 18, 2022 2:00:00 PM
34
- endTime: 1653573599, // May 26, 2022 1:59:59 PM
33
+ startTime: Math.trunc(new Date(2022, 8, 1).getTime() / 1000),
34
+ endTime: Math.trunc(new Date(2022, 9, 30).getTime() / 1000),
35
35
  isReferrer: false,
36
36
  rewardTokenAmount: dummyTokenAmount,
37
37
  transactionHash: null,
38
38
  userAddr: '0x...123',
39
+ refereeAddress: '0x123..123',
39
40
  };
40
41
 
41
42
  export const referralRewardDummy2: ReferralReward = {
42
43
  campaign: 'testb',
43
- startTime: 1652882400, // May 18, 2022 2:00:00 PM
44
- endTime: 1653573599, // May 26, 2022 1:59:59 PM
44
+ startTime: Math.trunc(new Date(2022, 8, 1).getTime() / 1000),
45
+ endTime: Math.trunc(new Date(2022, 8, 31).getTime() / 1000),
45
46
  isReferrer: true,
46
47
  rewardTokenAmount: dummyTokenAmount2,
47
48
  transactionHash: '0x4da9657663b46ef18d150b897b28c7b717f16421978b52e3a06d91b54ca3548b',
48
49
  userAddr: '0x...456',
50
+ refereeAddress: '0x123..123',
49
51
  };
@@ -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';
@@ -31,6 +33,12 @@ export const getCurrentTimestamp = (): number => {
31
33
  return Math.trunc(Date.now() / 1000);
32
34
  };
33
35
 
36
+ export async function sleep(duration: number): Promise<void> {
37
+ return new Promise((resolve) => {
38
+ setTimeout(resolve, duration);
39
+ });
40
+ }
41
+
34
42
  export function validateAndParseAddress(address: Address): Address {
35
43
  try {
36
44
  return utils.getAddress(address);
@@ -160,3 +168,16 @@ export function devLog(message?: any, ...optionalParams: any[]): void {
160
168
  console.log('[DEV LOG]', message, ...optionalParams);
161
169
  }
162
170
  }
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 } from '../helpers';
5
+ import { getBlocksTimestamp, isSameAddress, sleep, 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 amount = event.args.amount;
33
- let unlock = amount.mul([10, 1, 0, 0][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]);
34
37
  return {
35
38
  player: event.args.player,
36
- amount: new TokenAmount(this.plyToken, amount.toString()),
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
 
@@ -71,17 +76,25 @@ export class PlyGameRead extends BlockchainEntityRead {
71
76
  return new TokenAmount(this.plyToken, jackpot.toString());
72
77
  }
73
78
 
74
- public async nextJackpotRevealTime(): Promise<number> {
75
- return 0; // TODO: TBD
76
- }
77
-
78
79
  public async earlyUnlockedPulpAmount(user: Address): Promise<TokenAmount> {
79
80
  let earlyUnlockedPulpAmount = await this.env.plygame.totalPlyUnlockedEarly(user);
80
81
  return new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString());
81
82
  }
82
83
 
83
84
  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.
84
87
  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
+
85
98
  let filter = this.env.plygame.filters.BetMade();
86
99
  let betMadeEvents: PlyBetMadeEvent[] = tx.logs
87
100
  .filter((log) => isSameAddress(log.topics[0], filter.topics![0] as string))
@@ -108,15 +121,6 @@ export class PlyGameRead extends BlockchainEntityRead {
108
121
  }
109
122
 
110
123
  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
-
120
124
  /**
121
125
  * Make a single bet
122
126
  */
@@ -125,6 +129,7 @@ export class PlyGameReadWrite extends PlyGameRead {
125
129
  .connect(this._networkConnection.signer!)
126
130
  .makeBetOnce(amount.rawAmount());
127
131
  }
132
+
128
133
  public async approve(amount: TokenAmount): Promise<TransactionResponse> {
129
134
  return this.env.ply
130
135
  .connect(this._networkConnection.signer!)
@@ -1,7 +1,11 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
2
  import axios from 'axios';
3
3
  import { ethers } from 'ethers';
4
- import { AURORA_PLUS_API_PREFIX, REFERRAL_CAMPAIGNS } from '../consts';
4
+ import {
5
+ AURORA_PLUS_API_PREFIX, referralRewardDummy1,
6
+ referralRewardDummy2,
7
+ REFERRAL_CAMPAIGNS
8
+ } from '../consts';
5
9
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
6
10
  import { getBlocksTimestamp } from '../helpers';
7
11
  import * as AuriAPI from '../helpers/aurigami-api';
@@ -73,7 +77,7 @@ export class ReferralRead extends BlockchainEntityRead {
73
77
  */
74
78
  public async referralRewards(userAddr: Address): Promise<ReferralReward[]> {
75
79
  const result = await AuriAPI.getPaginatedApi('/referral/rewards', { address: userAddr });
76
- const items: ReferralReward[] = result.items.map((item, i) => ({
80
+ let items: ReferralReward[] = result.items.map((item, i) => ({
77
81
  campaign: item.campaign!,
78
82
  userAddr: userAddr,
79
83
  isReferrer: (item.campaign as string).includes('referrer'),
@@ -81,7 +85,10 @@ export class ReferralRead extends BlockchainEntityRead {
81
85
  startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
82
86
  endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
83
87
  transactionHash: item.transactionHash ?? null,
88
+ refereeAddress: null,
84
89
  }));
90
+
91
+ items = [referralRewardDummy1, referralRewardDummy2, ...items];
85
92
  return items;
86
93
  }
87
94
 
@@ -98,11 +105,36 @@ export class ReferralRead extends BlockchainEntityRead {
98
105
  startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
99
106
  endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
100
107
  transactionHash: null,
108
+ refereeAddress: null,
101
109
  }));
102
110
  items.sort((a, b) => b.rewardTokenAmount.compare(a.rewardTokenAmount));
103
111
  return items;
104
112
  }
105
113
 
114
+ /**
115
+ * current number of slots under a referral code being used that exceed minimum deposit amount
116
+ */
117
+ public async slotsInUse(referralCode: string): Promise<number> {
118
+ return 123;
119
+ }
120
+
121
+ public totalReferralSlots() {
122
+ return 500;
123
+ }
124
+
125
+ /**
126
+ * a way to determine qualification status of a user. null if not referred yet,
127
+ * qualified if referred + min deposit, notQualified if referred + min deposit
128
+ * not reached or withdrew too early
129
+ */
130
+ public async userReferralStatus(userAddr: Address): Promise<string> {
131
+ if ((await this.getReferralCodeUsed(userAddr)) !== '') {
132
+ return 'notQualified';
133
+ } else {
134
+ return 'notReferred';
135
+ }
136
+ }
137
+
106
138
  public async isWhitelistedAddress(address: Address): Promise<boolean> {
107
139
  let result = await AuriAPI.getApi('/referral/whitelisted', { address: address });
108
140
  return result.isWhitelisted;
@@ -150,6 +150,8 @@ export type ReferralReward = {
150
150
  * hash of the transaction on aurorascan (if no, return null)
151
151
  */
152
152
  transactionHash: string | null;
153
+
154
+ refereeAddress: string | null;
153
155
  };
154
156
 
155
157
  export type PlyGameBetResult = {
@@ -159,9 +161,9 @@ export type PlyGameBetResult = {
159
161
  */
160
162
  outcome: string;
161
163
  /**
162
- * Bet amount
164
+ * ply lost amount
163
165
  */
164
- amount: TokenAmount;
166
+ lostAmount: TokenAmount;
165
167
  unlockedPulpAmount: TokenAmount;
166
168
 
167
169
  block: number;
package/src/a.ts.log DELETED
@@ -1,29 +0,0 @@
1
- import { AuToken } from '@aurigami/contracts/typechain';
2
- import { ethers } from 'ethers';
3
- import { AuriEnv, formatObject, getDecimal, MAINNET_ADDRESSES, networkAddresses, SDK, Token } from '../src';
4
- import { ask } from 'stdio';
5
- const AURORA_DEFAULT_PROVIDER_URL = `https://mainnet.aurora.dev/`;
6
-
7
- const AURORA_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
8
- AURORA_DEFAULT_PROVIDER_URL
9
- );
10
-
11
- async function foo(contract: AuToken, block: number) {
12
- let data = await contract.callStatic.borrowBalanceCurrent('0x25a087dc3512e3be548f0ca13233ae29d3781bdc', {blockTag: block});
13
- console.log("c", data.toString());
14
- data = await contract.callStatic.borrowBalanceStored('0x25a087dc3512e3be548f0ca13233ae29d3781bdc', {blockTag: block});
15
- console.log("s", data.toString());
16
- }
17
-
18
- async function main() {
19
- let env = new AuriEnv({ provider: AURORA_DEFAULT_PROVIDER });
20
- let contract = env.getAuErc20Contract({address: MAINNET_ADDRESSES.auTokens.USDC});
21
- // let block = 60596417;
22
- // while (true) {
23
- // block = parseInt(eval(await ask('block')));
24
- // if (block == 0) break;
25
- // await foo(contract, block);
26
- // }
27
- }
28
-
29
- main();