@aurigami/sdk 1.10.0 → 1.11.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.
@@ -1,6 +1,8 @@
1
1
  import { AuToken } from '@aurigami/contracts/typechain';
2
+ import { TypedEvent } from '@aurigami/contracts/typechain/common';
2
3
  import BigNumber from 'bignumber.js';
3
4
  import type { providers, Signer } from 'ethers';
5
+ import { BigNumber as BN } from 'ethers';
4
6
  import { TokenAmount } from '../entities/tokenAmount';
5
7
  export declare enum ComptrollerRewardType {
6
8
  PLY = 0,
@@ -132,3 +134,26 @@ export declare type ReferralReward = {
132
134
  */
133
135
  transactionHash: string | null;
134
136
  };
137
+ export declare type PlyGameBetResult = {
138
+ player: string;
139
+ /**
140
+ * Bet outcome result
141
+ */
142
+ outcome: string;
143
+ /**
144
+ * Bet amount
145
+ */
146
+ amount: TokenAmount;
147
+ unlockedPulpAmount: TokenAmount;
148
+ block: number;
149
+ timestamp: number;
150
+ /**
151
+ * hash of the transaction on aurorascan (if no, return null)
152
+ */
153
+ transactionHash: string;
154
+ };
155
+ export declare type PlyBetMadeEvent = TypedEvent<[string, BN, number] & {
156
+ player: string;
157
+ amount: BN;
158
+ outcome: number;
159
+ }>;
package/package.json CHANGED
@@ -1,73 +1,73 @@
1
1
  {
2
- "version": "1.10.0",
3
- "license": "MIT",
4
- "main": "dist/index.js",
5
- "typings": "dist/index.d.ts",
6
- "files": [
7
- "dist",
8
- "src"
9
- ],
10
- "engines": {
11
- "node": ">=14"
12
- },
13
- "scripts": {
14
- "start": "tsdx watch",
15
- "build": "tsdx build",
16
- "test": "tsdx test --no-cache",
17
- "w-hardhat": "env TS_NODE_PROJECT=\"test-hardhat/tsconfig.json\" yarn hardhat",
18
- "lint": "prettier --check \"{src,test,test-hardhat}/**/*.{js,ts}\"",
19
- "format": "prettier --write \"{src,test,test-hardhat}/**/*.{js,ts}\"",
20
- "prepare": "tsdx build",
21
- "size": "size-limit",
22
- "analyze": "size-limit --why"
23
- },
24
- "peerDependencies": {},
25
- "husky": {
26
- "hooks": {
27
- "pre-commit": "tsdx lint"
28
- }
29
- },
30
- "name": "@aurigami/sdk",
31
- "author": "Aurigami Finance",
32
- "module": "dist/sdk.esm.js",
33
- "size-limit": [
34
- {
35
- "path": "dist/sdk.cjs.production.min.js",
36
- "limit": "300 KB"
2
+ "version": "1.11.0-beta1",
3
+ "license": "MIT",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "files": [
7
+ "dist",
8
+ "src"
9
+ ],
10
+ "engines": {
11
+ "node": ">=14"
12
+ },
13
+ "scripts": {
14
+ "start": "tsdx watch",
15
+ "build": "tsdx build",
16
+ "test": "tsdx test --no-cache",
17
+ "w-hardhat": "env TS_NODE_PROJECT=\"test-hardhat/tsconfig.json\" yarn hardhat",
18
+ "lint": "prettier --check \"{src,test,test-hardhat}/**/*.{js,ts}\"",
19
+ "format": "prettier --write \"{src,test,test-hardhat}/**/*.{js,ts}\"",
20
+ "prepare": "tsdx build",
21
+ "size": "size-limit",
22
+ "analyze": "size-limit --why"
23
+ },
24
+ "peerDependencies": {},
25
+ "husky": {
26
+ "hooks": {
27
+ "pre-commit": "tsdx lint"
28
+ }
29
+ },
30
+ "name": "@aurigami/sdk",
31
+ "author": "Aurigami Finance",
32
+ "module": "dist/sdk.esm.js",
33
+ "size-limit": [
34
+ {
35
+ "path": "dist/sdk.cjs.production.min.js",
36
+ "limit": "300 KB"
37
+ },
38
+ {
39
+ "path": "dist/sdk.esm.js",
40
+ "limit": "300 KB"
41
+ }
42
+ ],
43
+ "devDependencies": {
44
+ "@nomiclabs/hardhat-ethers": "^2.0.5",
45
+ "@nomiclabs/hardhat-etherscan": "^3.0.3",
46
+ "@nomiclabs/hardhat-waffle": "^2.0.3",
47
+ "@size-limit/preset-big-lib": "^7.0.8",
48
+ "@size-limit/webpack-why": "^7.0.8",
49
+ "@types/mocha": "^9.1.0",
50
+ "chai": "^4.3.6",
51
+ "dotenv": "^16.0.1",
52
+ "eslint-config-prettier": "^8.3.0",
53
+ "eslint-plugin-prettier": "^4.0.0",
54
+ "ethereum-waffle": "^3.4.4",
55
+ "hardhat": "^2.9.3",
56
+ "husky": "^7.0.4",
57
+ "prettier": "^2.5.1",
58
+ "size-limit": "^7.0.5",
59
+ "ts-node": "^10.7.0",
60
+ "tsdx": "^0.14.1",
61
+ "tslib": "^2.3.1",
62
+ "typescript": "^4.5.4"
63
+ },
64
+ "dependencies": {
65
+ "@aurigami/contracts": "3.12.0-beta-3",
66
+ "axios": "^0.26.1",
67
+ "bignumber.js": "^9.0.2",
68
+ "ethers": "^5.6.4"
37
69
  },
38
- {
39
- "path": "dist/sdk.esm.js",
40
- "limit": "300 KB"
70
+ "jest": {
71
+ "testURL": "https://app.aurigami.finance"
41
72
  }
42
- ],
43
- "devDependencies": {
44
- "@nomiclabs/hardhat-ethers": "^2.0.5",
45
- "@nomiclabs/hardhat-etherscan": "^3.0.3",
46
- "@nomiclabs/hardhat-waffle": "^2.0.3",
47
- "@size-limit/preset-big-lib": "^7.0.8",
48
- "@size-limit/webpack-why": "^7.0.8",
49
- "@types/mocha": "^9.1.0",
50
- "chai": "^4.3.6",
51
- "dotenv": "^16.0.1",
52
- "eslint-config-prettier": "^8.3.0",
53
- "eslint-plugin-prettier": "^4.0.0",
54
- "ethereum-waffle": "^3.4.4",
55
- "hardhat": "^2.9.3",
56
- "husky": "^7.0.4",
57
- "prettier": "^2.5.1",
58
- "size-limit": "^7.0.5",
59
- "ts-node": "^10.7.0",
60
- "tsdx": "^0.14.1",
61
- "tslib": "^2.3.1",
62
- "typescript": "^4.5.4"
63
- },
64
- "dependencies": {
65
- "@aurigami/contracts": "3.10.3",
66
- "axios": "^0.26.1",
67
- "bignumber.js": "^9.0.2",
68
- "ethers": "^5.6.4"
69
- },
70
- "jest": {
71
- "testURL": "https://app.aurigami.finance"
72
- }
73
- }
73
+ }
package/src/abis/index.ts CHANGED
@@ -14,6 +14,7 @@ import IUniswapV2PairABI from '@aurigami/contracts/artifacts/contracts/mock/IUni
14
14
  import Multicall2ABI from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
15
15
  import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
16
16
  import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
17
+ import PlyGameABI from '@aurigami/contracts/artifacts/contracts/plygame/PlyGame.sol/PlyGame.json';
17
18
  export {
18
19
  AuriOracleABI,
19
20
  AuTokenABI,
@@ -31,4 +32,5 @@ export {
31
32
  Multicall2ABI,
32
33
  PulpABI,
33
34
  AuriInternalLensABI,
35
+ PlyGameABI,
34
36
  };
@@ -90,6 +90,7 @@ export const networkAddresses: NetworkAddresses = {
90
90
  PLY_TOKEN_LOCK: MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
91
91
  REFERRAL: MAINNET_ADDRESSES.referralDirectory.toLowerCase(),
92
92
  AURI_INTERNAL_LENS: MAINNET_ADDRESSES.auriInternalLens.toLowerCase(),
93
+ PLYGAME: '0x60bf668CA101060BD83BD644531a38719586B89f'.toLowerCase(), // TODO: FIX THIS AFTER PLY GAME IS DEPLOYED
93
94
  },
94
95
  tokens: {
95
96
  AURORA: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
@@ -2,6 +2,8 @@ import { networkAddresses } from './constants';
2
2
 
3
3
  export const symbolRecords: Record<string, string> = Object.fromEntries(
4
4
  networkAddresses.auTokens
5
- .map((e) => [e.address.toLowerCase(), e.name])
6
- .concat(networkAddresses.auTokens.map((e) => [e.underlying.toLowerCase(), e.name.slice(2)]))
5
+ .map((e) => [e.address, e.name]) // AuToken
6
+ .concat(networkAddresses.auTokens.map((e) => [e.underlying, e.name.slice(2)])) // underlying token
7
+ .concat([['0x04ac48711bcdc45b4d223fb021e09da73c71095e', 'PULP']]) // others
8
+ .map(([address, name]) => [address.toLowerCase(), name])
7
9
  );
@@ -7,6 +7,7 @@ import {
7
7
  AuriOracle,
8
8
  Comptroller,
9
9
  IERC20,
10
+ PlyGame,
10
11
  PULP,
11
12
  ReferralDirectory,
12
13
  } from '@aurigami/contracts/typechain';
@@ -27,6 +28,7 @@ export class AuriEnv extends BlockchainEntityRead {
27
28
  private _auriAirdrop: AuriAirdrop | null = null;
28
29
  private _referralDirectory: ReferralDirectory | null = null;
29
30
  private _oracle: AuriOracle | null = null;
31
+ private _plygame: PlyGame | null = null;
30
32
 
31
33
  public getContract<CType extends Contract>(address: string, abi: any) {
32
34
  return new Contract(address, abi, this._networkConnection.provider) as CType;
@@ -65,7 +67,6 @@ export class AuriEnv extends BlockchainEntityRead {
65
67
  address = networkAddresses.auTokens.find(
66
68
  (auToken) => auToken.name == 'au' + underlyingName
67
69
  )?.address;
68
- console.log(address);
69
70
  assert(address !== undefined, `AuToken with underlying ${underlyingName} not found`);
70
71
  }
71
72
 
@@ -155,4 +156,11 @@ export class AuriEnv extends BlockchainEntityRead {
155
156
  }
156
157
  return this._oracle;
157
158
  }
159
+
160
+ get plygame(): PlyGame {
161
+ if (!this._plygame) {
162
+ this._plygame = this.getContract<PlyGame>(networkAddresses.misc.PLYGAME, abis.PlyGameABI.abi);
163
+ }
164
+ return this._plygame;
165
+ }
158
166
  }
@@ -0,0 +1,126 @@
1
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
2
+ import * as consts from '../consts';
3
+ import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
4
+ import * as helpers from '../helpers';
5
+ import { getBlocksTimestamp, isSameAddress } from '../helpers';
6
+ import { Address, NetworkConnection, PlyBetMadeEvent, PlyGameBetResult } from '../types';
7
+
8
+ export class PlyGameRead extends BlockchainEntityRead {
9
+ public readonly plyToken: Token;
10
+ public readonly pulpToken: Token;
11
+ public readonly env: AuriEnv;
12
+
13
+ public constructor(networkConnection: NetworkConnection) {
14
+ super(networkConnection);
15
+ this.env = new AuriEnv(networkConnection);
16
+
17
+ let plyAddress = consts.networkAddresses.tokens.PLY;
18
+ let pulpAddress = consts.networkAddresses.tokens.PULP;
19
+ this.plyToken = new Token(plyAddress, helpers.getDecimal(plyAddress));
20
+ this.pulpToken = new Token(pulpAddress, helpers.getDecimal(pulpAddress));
21
+ }
22
+
23
+ private parseBetMakeEvent(event: PlyBetMadeEvent): PlyGameBetResult {
24
+ let outcome = ['bigWin', 'win', 'lose', 'noImpact'][event.args.outcome];
25
+ let amount = event.args.amount;
26
+ let unlock = amount.mul([10, 1, 0, 0][event.args.outcome]);
27
+ return {
28
+ player: event.args.player,
29
+ amount: new TokenAmount(this.plyToken, amount.toString()),
30
+ unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
31
+ outcome: outcome,
32
+ transactionHash: event.transactionHash,
33
+ block: event.blockNumber,
34
+ timestamp: 0, // will be filled later
35
+ };
36
+ }
37
+
38
+ private async attachTimestamp(results: PlyGameBetResult[]): Promise<PlyGameBetResult[]> {
39
+ let blockNumbers = results.map((e) => e.block);
40
+ let blockstimestamp = await getBlocksTimestamp(this._networkConnection.provider, blockNumbers);
41
+ return results.map((e, i) => ({ ...e, timestamp: blockstimestamp[i] }));
42
+ }
43
+
44
+ /**
45
+ * Get 100 most recent bets of the market users
46
+ */
47
+ public async getUserPlyGameHistory(user: Address): Promise<PlyGameBetResult[]> {
48
+ let block100 = await this.env.plygame.getLastBlock(user, 100);
49
+
50
+ if (block100.eq(0)) {
51
+ return [];
52
+ }
53
+
54
+ let filter = this.env.plygame.filters.BetMade(user);
55
+ let events = await this.env.plygame.queryFilter(filter, block100.toNumber());
56
+ return this.attachTimestamp(events.map((event) => this.parseBetMakeEvent(event)));
57
+ }
58
+
59
+ /**
60
+ * Get current jackpot amount
61
+ */
62
+ public async currentJackpotAmount(): Promise<TokenAmount> {
63
+ let jackpot = await this.env.plygame.currentJackpotAmount();
64
+ return new TokenAmount(this.plyToken, jackpot.toString());
65
+ }
66
+
67
+ public async nextJackpotRevealTime(): Promise<number> {
68
+ return 0; // TODO: TBD
69
+ }
70
+
71
+ public async earlyUnlockedPulpAmount(user: Address): Promise<TokenAmount> {
72
+ let earlyUnlockedPulpAmount = await this.env.plygame.totalPlyUnlockedEarly(user);
73
+ return new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString());
74
+ }
75
+
76
+ public async getPlyGameResultsInTransaction(txHash: Address): Promise<PlyGameBetResult[]> {
77
+ let tx = await this._networkConnection.provider.getTransactionReceipt(txHash);
78
+ let filter = this.env.plygame.filters.BetMade();
79
+ let betMadeEvents: PlyBetMadeEvent[] = tx.logs
80
+ .filter((log) => isSameAddress(log.topics[0], filter.topics![0] as string))
81
+ .map((log) => ({
82
+ ...this.env.plygame.interface.parseLog(log),
83
+ blockNumber: tx.blockNumber,
84
+ transactionHash: txHash,
85
+ })) as unknown as PlyBetMadeEvent[];
86
+
87
+ return this.attachTimestamp(betMadeEvents.map((e) => this.parseBetMakeEvent(e)));
88
+ }
89
+ }
90
+
91
+ export class PlyGameReadWrite extends PlyGameRead {
92
+ /**
93
+ * makes "times" independent bets, but consecutively, of the same amount
94
+ */
95
+ public async makeBetMultiple(amount: TokenAmount, times: number): Promise<TransactionResponse> {
96
+ return this.env.plygame
97
+ .connect(this._networkConnection.signer!)
98
+ .makeBetMultiple(amount.rawAmount(), times);
99
+ }
100
+
101
+ /**
102
+ * Make a single bet
103
+ */
104
+ public async makeBetOnce(amount: TokenAmount): Promise<TransactionResponse> {
105
+ return this.env.plygame
106
+ .connect(this._networkConnection.signer!)
107
+ .makeBetOnce(amount.rawAmount());
108
+ }
109
+ public async approve(amount: TokenAmount): Promise<TransactionResponse> {
110
+ return this.env.ply
111
+ .connect(this._networkConnection.signer!)
112
+ .approve(this.env.plygame.address, amount.rawAmount());
113
+ }
114
+ }
115
+
116
+ export class PlyGame extends BlockchainEntity {
117
+ constructor() {
118
+ super();
119
+ }
120
+ public read(networkConnection: NetworkConnection): PlyGameRead {
121
+ return new PlyGameRead(networkConnection);
122
+ }
123
+ public readWrite(networkConnection: NetworkConnection): PlyGameReadWrite {
124
+ return new PlyGameReadWrite(networkConnection);
125
+ }
126
+ }
@@ -2,5 +2,6 @@ export * from './Airdrop';
2
2
  export * from './misc';
3
3
  export * from './MoneyMarket';
4
4
  export * from './Papermill';
5
+ export * from './PlyGame';
5
6
  export * from './Referral';
6
7
  export * from './Staking';
@@ -1,6 +1,8 @@
1
1
  import { AuToken } from '@aurigami/contracts/typechain';
2
+ import { TypedEvent } from '@aurigami/contracts/typechain/common';
2
3
  import BigNumber from 'bignumber.js';
3
4
  import type { providers, Signer } from 'ethers';
5
+ import { BigNumber as BN } from 'ethers';
4
6
  import { TokenAmount } from '../entities/tokenAmount';
5
7
 
6
8
  export enum ComptrollerRewardType {
@@ -149,3 +151,27 @@ export type ReferralReward = {
149
151
  */
150
152
  transactionHash: string | null;
151
153
  };
154
+
155
+ export type PlyGameBetResult = {
156
+ player: string;
157
+ /**
158
+ * Bet outcome result
159
+ */
160
+ outcome: string;
161
+ /**
162
+ * Bet amount
163
+ */
164
+ amount: TokenAmount;
165
+ unlockedPulpAmount: TokenAmount;
166
+
167
+ block: number;
168
+ timestamp: number;
169
+ /**
170
+ * hash of the transaction on aurorascan (if no, return null)
171
+ */
172
+ transactionHash: string;
173
+ };
174
+
175
+ export type PlyBetMadeEvent = TypedEvent<
176
+ [string, BN, number] & { player: string; amount: BN; outcome: number }
177
+ >;