@aurigami/sdk 1.11.2-dummy1 → 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.
@@ -133,7 +133,6 @@ 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;
137
136
  };
138
137
  export declare type PlyGameBetResult = {
139
138
  player: string;
@@ -142,9 +141,9 @@ export declare type PlyGameBetResult = {
142
141
  */
143
142
  outcome: string;
144
143
  /**
145
- * ply lost amount
144
+ * Bet amount
146
145
  */
147
- lostAmount: TokenAmount;
146
+ amount: TokenAmount;
148
147
  unlockedPulpAmount: TokenAmount;
149
148
  block: number;
150
149
  timestamp: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.2-dummy1",
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"
@@ -70,4 +70,4 @@
70
70
  "jest": {
71
71
  "testURL": "https://app.aurigami.finance"
72
72
  }
73
- }
73
+ }
package/src/a.ts.log ADDED
@@ -0,0 +1,29 @@
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();
@@ -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(),
@@ -30,22 +30,20 @@ export const dummyUserMarketDetails: UserMarketDetails = {
30
30
 
31
31
  export const referralRewardDummy1: ReferralReward = {
32
32
  campaign: 'testa',
33
- startTime: Math.trunc(new Date(2022, 8, 1).getTime() / 1000),
34
- endTime: Math.trunc(new Date(2022, 9, 30).getTime() / 1000),
33
+ startTime: 1652882400, // May 18, 2022 2:00:00 PM
34
+ endTime: 1653573599, // May 26, 2022 1:59:59 PM
35
35
  isReferrer: false,
36
36
  rewardTokenAmount: dummyTokenAmount,
37
37
  transactionHash: null,
38
38
  userAddr: '0x...123',
39
- refereeAddress: '0x123..123',
40
39
  };
41
40
 
42
41
  export const referralRewardDummy2: ReferralReward = {
43
42
  campaign: 'testb',
44
- startTime: Math.trunc(new Date(2022, 8, 1).getTime() / 1000),
45
- endTime: Math.trunc(new Date(2022, 8, 31).getTime() / 1000),
43
+ startTime: 1652882400, // May 18, 2022 2:00:00 PM
44
+ endTime: 1653573599, // May 26, 2022 1:59:59 PM
46
45
  isReferrer: true,
47
46
  rewardTokenAmount: dummyTokenAmount2,
48
47
  transactionHash: '0x4da9657663b46ef18d150b897b28c7b717f16421978b52e3a06d91b54ca3548b',
49
48
  userAddr: '0x...456',
50
- refereeAddress: '0x123..123',
51
49
  };
@@ -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,11 +1,7 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
- import { ethers, BigNumber as BN } from 'ethers';
3
- import {
4
- networkAddresses,
5
- referralRewardDummy1,
6
- referralRewardDummy2,
7
- REFERRAL_CAMPAIGNS,
8
- } from '../consts';
2
+ import axios from 'axios';
3
+ import { ethers } from 'ethers';
4
+ import { AURORA_PLUS_API_PREFIX, REFERRAL_CAMPAIGNS } from '../consts';
9
5
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
10
6
  import { getBlocksTimestamp } from '../helpers';
11
7
  import * as AuriAPI from '../helpers/aurigami-api';
@@ -77,7 +73,7 @@ export class ReferralRead extends BlockchainEntityRead {
77
73
  */
78
74
  public async referralRewards(userAddr: Address): Promise<ReferralReward[]> {
79
75
  const result = await AuriAPI.getPaginatedApi('/referral/rewards', { address: userAddr });
80
- let items: ReferralReward[] = result.items.map((item, i) => ({
76
+ const items: ReferralReward[] = result.items.map((item, i) => ({
81
77
  campaign: item.campaign!,
82
78
  userAddr: userAddr,
83
79
  isReferrer: (item.campaign as string).includes('referrer'),
@@ -85,10 +81,7 @@ export class ReferralRead extends BlockchainEntityRead {
85
81
  startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
86
82
  endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
87
83
  transactionHash: item.transactionHash ?? null,
88
- refereeAddress: null,
89
84
  }));
90
-
91
- items = [referralRewardDummy1, referralRewardDummy2, ...items];
92
85
  return items;
93
86
  }
94
87
 
@@ -105,34 +98,20 @@ export class ReferralRead extends BlockchainEntityRead {
105
98
  startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
106
99
  endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
107
100
  transactionHash: null,
108
- refereeAddress: null,
109
101
  }));
110
102
  items.sort((a, b) => b.rewardTokenAmount.compare(a.rewardTokenAmount));
111
103
  return items;
112
104
  }
113
105
 
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;
106
+ public async isWhitelistedAddress(address: Address): Promise<boolean> {
107
+ let result = await AuriAPI.getApi('/referral/whitelisted', { address: address });
108
+ return result.isWhitelisted;
119
109
  }
120
110
 
121
- public totalReferralSlots() {
122
- return 500;
123
- }
111
+ public async isOnAuroraPlus(address: Address): Promise<boolean> {
112
+ let resp = await axios.get(AURORA_PLUS_API_PREFIX + address);
124
113
 
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
- }
114
+ return resp.data.status == 'active';
136
115
  }
137
116
  }
138
117
 
@@ -150,8 +150,6 @@ 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;
155
153
  };
156
154
 
157
155
  export type PlyGameBetResult = {
@@ -161,9 +159,9 @@ export type PlyGameBetResult = {
161
159
  */
162
160
  outcome: string;
163
161
  /**
164
- * ply lost amount
162
+ * Bet amount
165
163
  */
166
- lostAmount: TokenAmount;
164
+ amount: TokenAmount;
167
165
  unlockedPulpAmount: TokenAmount;
168
166
 
169
167
  block: number;