@aurigami/sdk 1.7.6 → 1.7.7-dummy
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/dist/consts/dummy.d.ts +3 -1
- package/dist/contracts/Airdrop.d.ts +2 -3
- package/dist/contracts/Referral.d.ts +15 -4
- package/dist/entities/auriEnv.d.ts +18 -9
- package/dist/sdk.cjs.development.js +279 -61
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +279 -63
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/index.d.ts +23 -0
- package/package.json +2 -2
- package/src/consts/dummy.ts +21 -2
- package/src/contracts/Airdrop.ts +6 -14
- package/src/contracts/Referral.ts +41 -18
- package/src/entities/auriEnv.ts +83 -31
- package/src/types/index.ts +24 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -105,3 +105,26 @@ export declare type AccountAuTokensInfo = {
|
|
|
105
105
|
export declare type AuTokenWithUnderlying = AuToken & {
|
|
106
106
|
underlying: string;
|
|
107
107
|
};
|
|
108
|
+
export declare type ReferralReward = {
|
|
109
|
+
campaign: string;
|
|
110
|
+
/**
|
|
111
|
+
* start timetamp of the referral round
|
|
112
|
+
*/
|
|
113
|
+
startTime: number;
|
|
114
|
+
/**
|
|
115
|
+
* end timetamp of the referral round
|
|
116
|
+
*/
|
|
117
|
+
endTime: number;
|
|
118
|
+
/**
|
|
119
|
+
* referrer's rewards
|
|
120
|
+
*/
|
|
121
|
+
isReferrer: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* reward amount
|
|
124
|
+
*/
|
|
125
|
+
rewardTokenAmount: TokenAmount;
|
|
126
|
+
/**
|
|
127
|
+
* hash of the transaction on aurorascan (if no, return null)
|
|
128
|
+
*/
|
|
129
|
+
transactionHash: string | null;
|
|
130
|
+
};
|
package/package.json
CHANGED
package/src/consts/dummy.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Token, TokenAmount } from '../entities';
|
|
2
|
-
import { UserMarketDetails } from '../types';
|
|
2
|
+
import { ReferralReward, UserMarketDetails } from '../types';
|
|
3
|
+
import { networkAddresses } from './constants';
|
|
3
4
|
|
|
4
|
-
export const dummyToken = new Token(
|
|
5
|
+
export const dummyToken = new Token(networkAddresses.tokens.WNEAR, 24);
|
|
5
6
|
|
|
6
7
|
export const dummyPly = new Token('0x8729438eb15e2c8b576fcc6aecda6a148776c0f5', 18);
|
|
7
8
|
|
|
@@ -26,3 +27,21 @@ export const dummyUserMarketDetails: UserMarketDetails = {
|
|
|
26
27
|
collateralRatio: 0.5,
|
|
27
28
|
underlyingPrice: '1',
|
|
28
29
|
};
|
|
30
|
+
|
|
31
|
+
export const referralRewardDummy1: ReferralReward = {
|
|
32
|
+
campaign: 'testa',
|
|
33
|
+
startTime: 1652882400, // May 18, 2022 2:00:00 PM
|
|
34
|
+
endTime: 1653573599, // May 26, 2022 1:59:59 PM
|
|
35
|
+
isReferrer: false,
|
|
36
|
+
rewardTokenAmount: dummyTokenAmount,
|
|
37
|
+
transactionHash: null,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const referralRewardDummy2: ReferralReward = {
|
|
41
|
+
campaign: 'testb',
|
|
42
|
+
startTime: 1652882400, // May 18, 2022 2:00:00 PM
|
|
43
|
+
endTime: 1653573599, // May 26, 2022 1:59:59 PM
|
|
44
|
+
isReferrer: true,
|
|
45
|
+
rewardTokenAmount: dummyTokenAmount2,
|
|
46
|
+
transactionHash: '0x4da9657663b46ef18d150b897b28c7b717f16421978b52e3a06d91b54ca3548b',
|
|
47
|
+
};
|
package/src/contracts/Airdrop.ts
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import { AuriAirdrop } from '@aurigami/contracts/typechain';
|
|
2
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
3
|
-
import { BigNumber as BN,
|
|
4
|
-
import {
|
|
5
|
-
import * as consts from '../consts';
|
|
6
|
-
import { BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
|
|
2
|
+
import { BigNumber as BN, utils } from 'ethers';
|
|
3
|
+
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
|
|
7
4
|
import * as helpers from '../helpers';
|
|
8
5
|
import { Address, NetworkConnection } from '../types';
|
|
9
6
|
|
|
10
7
|
export class AirdropRead extends BlockchainEntityRead {
|
|
11
|
-
public readonly
|
|
8
|
+
public readonly env: AuriEnv;
|
|
12
9
|
|
|
13
10
|
public constructor(networkConnection: NetworkConnection) {
|
|
14
11
|
super(networkConnection);
|
|
15
|
-
|
|
16
|
-
this.airDrop = new Contract(
|
|
17
|
-
consts.networkAddresses.misc.AURI_AIRDROP,
|
|
18
|
-
AuriAirdropABI.abi,
|
|
19
|
-
networkConnection.provider
|
|
20
|
-
) as AuriAirdrop;
|
|
12
|
+
this.env = new AuriEnv(networkConnection);
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
/**
|
|
@@ -30,7 +22,7 @@ export class AirdropRead extends BlockchainEntityRead {
|
|
|
30
22
|
): Promise<TokenAmount> {
|
|
31
23
|
let tokenInstance: Token = new Token(token, helpers.getDecimal(token));
|
|
32
24
|
|
|
33
|
-
let rewards: BN = await this.
|
|
25
|
+
let rewards: BN = await this.env.auriAirdrop.getRedeemableReward(
|
|
34
26
|
utils.formatBytes32String(campaign),
|
|
35
27
|
token,
|
|
36
28
|
user
|
|
@@ -52,7 +44,7 @@ export class AirdropReadWrite extends AirdropRead {
|
|
|
52
44
|
campaigns.length == tokens.length,
|
|
53
45
|
'campaigns and tokens must have the same length'
|
|
54
46
|
);
|
|
55
|
-
return this.
|
|
47
|
+
return this.env.auriAirdrop.connect(this._networkConnection.signer!).redeem(
|
|
56
48
|
campaigns.map((e) => utils.formatBytes32String(e)),
|
|
57
49
|
tokens,
|
|
58
50
|
await this._networkConnection.signer!.getAddress()
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { ReferralDirectory } from '@aurigami/contracts/typechain';
|
|
2
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { BlockchainEntity, BlockchainEntityRead } from '../entities';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { referralRewardDummy1, referralRewardDummy2 } from '../consts';
|
|
4
|
+
import { AuriEnv, BlockchainEntity, BlockchainEntityRead } from '../entities';
|
|
5
|
+
import { getBlocksTimestamp } from '../helpers';
|
|
8
6
|
import * as AuriAPI from '../helpers/aurigami-api';
|
|
9
|
-
import { Address, NetworkConnection } from '../types';
|
|
7
|
+
import { Address, NetworkConnection, ReferralReward } from '../types';
|
|
8
|
+
import { AirdropReadWrite } from './Airdrop';
|
|
10
9
|
|
|
11
10
|
export class ReferralRead extends BlockchainEntityRead {
|
|
12
|
-
public readonly
|
|
11
|
+
public readonly env: AuriEnv;
|
|
13
12
|
constructor(networkConnection: NetworkConnection) {
|
|
14
13
|
super(networkConnection);
|
|
15
|
-
this.
|
|
16
|
-
consts.networkAddresses.misc.REFERRAL,
|
|
17
|
-
abis.ReferralDirectoryABI.abi,
|
|
18
|
-
networkConnection.provider
|
|
19
|
-
) as ReferralDirectory;
|
|
14
|
+
this.env = new AuriEnv(networkConnection);
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
/**
|
|
@@ -38,7 +33,7 @@ export class ReferralRead extends BlockchainEntityRead {
|
|
|
38
33
|
* Called to check if a user has a referral code.
|
|
39
34
|
*/
|
|
40
35
|
public async getUserReferralCode(userAddr: Address): Promise<string> {
|
|
41
|
-
const result = await this.
|
|
36
|
+
const result = await this.env.referralDirectory.userReferralCode(userAddr);
|
|
42
37
|
return ethers.utils.parseBytes32String(result);
|
|
43
38
|
}
|
|
44
39
|
|
|
@@ -46,7 +41,7 @@ export class ReferralRead extends BlockchainEntityRead {
|
|
|
46
41
|
* Get referral code that a user was referred by, returns empty string if not found.
|
|
47
42
|
*/
|
|
48
43
|
public async getReferralCodeUsed(userAddr: Address): Promise<string> {
|
|
49
|
-
const result = await this.
|
|
44
|
+
const result = await this.env.referralDirectory.referralCodeUsed(userAddr);
|
|
50
45
|
return ethers.utils.parseBytes32String(result);
|
|
51
46
|
}
|
|
52
47
|
|
|
@@ -55,7 +50,7 @@ export class ReferralRead extends BlockchainEntityRead {
|
|
|
55
50
|
*/
|
|
56
51
|
public async getReferralCodeOwner(code: string): Promise<Address> {
|
|
57
52
|
const referralCode = ethers.utils.formatBytes32String(code);
|
|
58
|
-
return this.
|
|
53
|
+
return this.env.referralDirectory.referralCodeOwner(referralCode);
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
/**
|
|
@@ -71,6 +66,22 @@ export class ReferralRead extends BlockchainEntityRead {
|
|
|
71
66
|
}));
|
|
72
67
|
return items;
|
|
73
68
|
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Array of rewards, sorted by time of the referral period (from latest to oldest)
|
|
72
|
+
*/
|
|
73
|
+
public async referralRewards(userAddr: Address): Promise<ReferralReward[]> {
|
|
74
|
+
// TODO: Fix this
|
|
75
|
+
return [referralRewardDummy1, referralRewardDummy2];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Top 50 reward earners from the last round, sorted by token amount
|
|
80
|
+
*/
|
|
81
|
+
public async leaderboard(): Promise<ReferralReward[]> {
|
|
82
|
+
// TODO: Fix this
|
|
83
|
+
return [referralRewardDummy2, referralRewardDummy1];
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
export class ReferralReadWrite extends ReferralRead {
|
|
@@ -81,7 +92,7 @@ export class ReferralReadWrite extends ReferralRead {
|
|
|
81
92
|
*/
|
|
82
93
|
public async registerNewReferralCode(): Promise<TransactionResponse> {
|
|
83
94
|
const referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
|
|
84
|
-
return this.
|
|
95
|
+
return this.env.referralDirectory
|
|
85
96
|
.connect(this._networkConnection.signer!)
|
|
86
97
|
.registerNewUserReferralCode(referralCode);
|
|
87
98
|
}
|
|
@@ -91,10 +102,22 @@ export class ReferralReadWrite extends ReferralRead {
|
|
|
91
102
|
*/
|
|
92
103
|
public async useReferralCode(code: string): Promise<TransactionResponse> {
|
|
93
104
|
const referralCode = ethers.utils.formatBytes32String(code);
|
|
94
|
-
return this.
|
|
105
|
+
return this.env.referralDirectory
|
|
95
106
|
.connect(this._networkConnection.signer!)
|
|
96
107
|
.registerReferralCodeUsed(referralCode);
|
|
97
108
|
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Claim all unclaimed rewards for a given user
|
|
112
|
+
*/
|
|
113
|
+
public async claimReferralRewards(): Promise<TransactionResponse> {
|
|
114
|
+
const unclaimedRewards = (
|
|
115
|
+
await this.referralRewards(await this._networkConnection.signer!.getAddress())
|
|
116
|
+
).filter((reward) => reward.transactionHash == null);
|
|
117
|
+
const campaigns = unclaimedRewards.map((reward) => reward.campaign);
|
|
118
|
+
const tokens = unclaimedRewards.map((reward) => reward.rewardTokenAmount.token.address);
|
|
119
|
+
return new AirdropReadWrite(this._networkConnection).redeemMultiple(campaigns, tokens);
|
|
120
|
+
}
|
|
98
121
|
}
|
|
99
122
|
|
|
100
123
|
export class Referral extends BlockchainEntity {
|
package/src/entities/auriEnv.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AuriAirdrop,
|
|
2
3
|
AuriFairLaunch,
|
|
3
4
|
AuriInternalLens,
|
|
4
5
|
AuriLens,
|
|
5
6
|
Comptroller,
|
|
6
7
|
IERC20,
|
|
7
8
|
PULP,
|
|
9
|
+
ReferralDirectory,
|
|
8
10
|
} from '@aurigami/contracts/typechain';
|
|
9
11
|
import { Contract } from 'ethers';
|
|
10
12
|
import * as abis from '../abis';
|
|
11
13
|
import { networkAddresses } from '../consts/constants';
|
|
12
|
-
import { AuTokenWithUnderlying
|
|
14
|
+
import { AuTokenWithUnderlying } from '../types';
|
|
13
15
|
import { BlockchainEntityRead } from './BlockchainEntity';
|
|
14
16
|
|
|
15
17
|
export class AuriEnv extends BlockchainEntityRead {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
private _comptroller: Comptroller | null = null;
|
|
19
|
+
private _auriFairLaunch: AuriFairLaunch | null = null;
|
|
20
|
+
private _auriLens: AuriLens | null = null;
|
|
21
|
+
private _ply: IERC20 | null = null;
|
|
22
|
+
private _pulp: PULP | null = null;
|
|
23
|
+
private _auriInternalLens: AuriInternalLens | null = null;
|
|
24
|
+
private _auriAirdrop: AuriAirdrop | null = null;
|
|
25
|
+
private _referralDirectory: ReferralDirectory | null = null;
|
|
23
26
|
|
|
24
27
|
public getContract<CType extends Contract>(address: string, abi: any) {
|
|
25
28
|
return new Contract(address, abi, this._networkConnection.provider) as CType;
|
|
@@ -36,28 +39,77 @@ export class AuriEnv extends BlockchainEntityRead {
|
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
get comptroller(): Comptroller {
|
|
43
|
+
if (!this._comptroller) {
|
|
44
|
+
this._comptroller = this.getContract<Comptroller>(
|
|
45
|
+
networkAddresses.misc.COMPTROLLER,
|
|
46
|
+
abis.ComptrollerABI.abi
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return this._comptroller;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get auriFairLaunch(): AuriFairLaunch {
|
|
53
|
+
if (!this._auriFairLaunch) {
|
|
54
|
+
this._auriFairLaunch = this.getContract<AuriFairLaunch>(
|
|
55
|
+
networkAddresses.misc.AURIFAIRLAUNCH,
|
|
56
|
+
abis.AuriFairLaunchABI.abi
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return this._auriFairLaunch;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get auriLens(): AuriLens {
|
|
63
|
+
if (!this._auriLens) {
|
|
64
|
+
this._auriLens = this.getContract<AuriLens>(
|
|
65
|
+
networkAddresses.misc.AURILENS,
|
|
66
|
+
abis.AuriLensABI.abi
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return this._auriLens;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get ply(): IERC20 {
|
|
73
|
+
if (!this._ply) {
|
|
74
|
+
this._ply = this.getContract<IERC20>(networkAddresses.tokens.PLY, abis.EIP20InterfaceABI.abi);
|
|
75
|
+
}
|
|
76
|
+
return this._ply;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get pulp(): PULP {
|
|
80
|
+
if (!this._pulp) {
|
|
81
|
+
this._pulp = this.getContract<PULP>(networkAddresses.tokens.PULP, abis.PulpABI.abi);
|
|
82
|
+
}
|
|
83
|
+
return this._pulp;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get auriInternalLens(): AuriInternalLens {
|
|
87
|
+
if (!this._auriInternalLens) {
|
|
88
|
+
this._auriInternalLens = this.getContract<AuriInternalLens>(
|
|
89
|
+
networkAddresses.misc.AURI_INTERNAL_LENS,
|
|
90
|
+
abis.AuriInternalLensABI.abi
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return this._auriInternalLens;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get auriAirdrop(): AuriAirdrop {
|
|
97
|
+
if (!this._auriAirdrop) {
|
|
98
|
+
this._auriAirdrop = this.getContract<AuriAirdrop>(
|
|
99
|
+
networkAddresses.misc.AURI_AIRDROP,
|
|
100
|
+
abis.AuriAirdropABI.abi
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return this._auriAirdrop;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get referralDirectory(): ReferralDirectory {
|
|
107
|
+
if (!this._referralDirectory) {
|
|
108
|
+
this._referralDirectory = this.getContract<ReferralDirectory>(
|
|
109
|
+
networkAddresses.misc.REFERRAL,
|
|
110
|
+
abis.ReferralDirectoryABI.abi
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return this._referralDirectory;
|
|
62
114
|
}
|
|
63
115
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -121,3 +121,27 @@ export type AccountAuTokensInfo = {
|
|
|
121
121
|
export type AuTokenWithUnderlying = AuToken & {
|
|
122
122
|
underlying: string;
|
|
123
123
|
};
|
|
124
|
+
|
|
125
|
+
export type ReferralReward = {
|
|
126
|
+
campaign: string;
|
|
127
|
+
/**
|
|
128
|
+
* start timetamp of the referral round
|
|
129
|
+
*/
|
|
130
|
+
startTime: number;
|
|
131
|
+
/**
|
|
132
|
+
* end timetamp of the referral round
|
|
133
|
+
*/
|
|
134
|
+
endTime: number;
|
|
135
|
+
/**
|
|
136
|
+
* referrer's rewards
|
|
137
|
+
*/
|
|
138
|
+
isReferrer: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* reward amount
|
|
141
|
+
*/
|
|
142
|
+
rewardTokenAmount: TokenAmount;
|
|
143
|
+
/**
|
|
144
|
+
* hash of the transaction on aurorascan (if no, return null)
|
|
145
|
+
*/
|
|
146
|
+
transactionHash: string | null;
|
|
147
|
+
};
|