@aurigami/sdk 1.6.1 → 1.6.2

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.1",
2
+ "version": "1.6.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -60,7 +60,7 @@
60
60
  "typescript": "^4.5.4"
61
61
  },
62
62
  "dependencies": {
63
- "@aurigami/contracts": "3.4.0",
63
+ "@aurigami/contracts": "3.5.0",
64
64
  "axios": "^0.26.1",
65
65
  "bignumber.js": "^9.0.2",
66
66
  "dotenv": "^16.0.0",
@@ -81,6 +81,7 @@ export const networkAddresses: NetworkAddresses = {
81
81
  MULTICALL: MAINNET_ADDRESSES.multicall.toLowerCase(),
82
82
  TEAM_MULTISIG: '0x2D05FfFE70CE64c5954710D4C308dB31C8dBd8dE'.toLowerCase(),
83
83
  PLY_TOKEN_LOCK: MAINNET_ADDRESSES.plyTokenLock.toLowerCase(),
84
+ REFERRAL: MAINNET_ADDRESSES.referralDirectory.toLocaleLowerCase(),
84
85
  },
85
86
  tokens: {
86
87
  AURORA: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase(),
@@ -0,0 +1,98 @@
1
+ import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
2
+ import { ReferralDirectory } from '@aurigami/contracts/typechain';
3
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
4
+ import { Contract, ethers } from 'ethers';
5
+ import * as consts from '../consts';
6
+ import { BlockchainEntity, BlockchainEntityRead } from '../entities';
7
+ import { Address, NetworkConnection } from '../types';
8
+
9
+ export class ReferralRead extends BlockchainEntityRead {
10
+ protected _referral: ReferralDirectory;
11
+ constructor(networkConnection: NetworkConnection) {
12
+ super(networkConnection);
13
+ this._referral = new Contract(
14
+ consts.networkAddresses.misc.REFERRAL,
15
+ ReferralDirectoryABI.abi,
16
+ networkConnection.provider
17
+ ) as ReferralDirectory;
18
+ }
19
+
20
+ /**
21
+ * Generate a 10-character referral code
22
+ * containing alphanumeric characters.
23
+ */
24
+ protected generateReferralCode(): string {
25
+ let letters = 'abcdefghijklmnopqrstuvwxyz';
26
+ let numbers = '1234567890';
27
+ let charset = letters + letters.toUpperCase() + numbers;
28
+ let R = '';
29
+ for (var i = 0; i < 10; i++)
30
+ R += charset[Math.floor(Math.random() * charset.length)];
31
+ return R;
32
+ }
33
+
34
+ /**
35
+ * Get the referral code for a given address, returns empty string if not found.
36
+ *
37
+ * Called to check if a user has a referral code.
38
+ */
39
+ public async getUserReferralCode(userAddr: Address): Promise<string> {
40
+ const result = await this._referral.userReferralCode(userAddr);
41
+ return ethers.utils.parseBytes32String(result);
42
+ }
43
+
44
+ /**
45
+ * Get referral code that a user was referred by, returns empty string if not found.
46
+ */
47
+ public async getReferralCodeUsed(userAddr: Address): Promise<string> {
48
+ const result = await this._referral.referralCodeUsed(userAddr);
49
+ return ethers.utils.parseBytes32String(result);
50
+ }
51
+
52
+ /**
53
+ * Get owner of a referral code, returns zero address if not found.
54
+ */
55
+ public async getReferralCodeOwner(code: string): Promise<Address> {
56
+ const referralCode = ethers.utils.formatBytes32String(code);
57
+ return this._referral.referralCodeOwner(referralCode);
58
+ }
59
+ }
60
+
61
+ export class ReferralReadWrite extends ReferralRead {
62
+ /**
63
+ * Generate a referral code for a given address.
64
+ *
65
+ * Called when an user want to creates his own referral code
66
+ */
67
+ public async registerNewReferralCode(): Promise<TransactionResponse> {
68
+ const referralCode = ethers.utils.formatBytes32String(
69
+ this.generateReferralCode()
70
+ );
71
+ return this._referral
72
+ .connect(this._networkConnection.signer!)
73
+ .registerNewUserReferralCode(referralCode);
74
+ }
75
+
76
+ /**
77
+ * Called when an user confirms he is referred by a specified code
78
+ */
79
+ public async useReferralCode(code: string): Promise<TransactionResponse> {
80
+ const referralCode = ethers.utils.formatBytes32String(code);
81
+ return this._referral
82
+ .connect(this._networkConnection.signer!)
83
+ .registerReferralCodeUsed(referralCode);
84
+ }
85
+ }
86
+
87
+ export class Referral extends BlockchainEntity {
88
+ constructor() {
89
+ super();
90
+ }
91
+ public read(networkConnection: NetworkConnection): ReferralRead {
92
+ return new ReferralRead(networkConnection);
93
+ }
94
+
95
+ public readWrite(networkConnection: NetworkConnection): ReferralReadWrite {
96
+ return new ReferralReadWrite(networkConnection);
97
+ }
98
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './airdrop-lottery';
2
2
  export * from './MoneyMarket';
3
3
  export * from './Papermill';
4
+ export * from './Referral';
4
5
  export * from './Staking';