@aurigami/sdk 1.24.0 → 1.24.1
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/helpers/priceFetcher.js +9 -13
- package/package.json +2 -14
- package/src/SDK.ts +0 -223
- package/src/abis/index.ts +0 -38
- package/src/consts/constants.ts +0 -210
- package/src/consts/decimals.ts +0 -31
- package/src/consts/deployments.ts +0 -4
- package/src/consts/dummy.ts +0 -51
- package/src/consts/index.ts +0 -5
- package/src/consts/symbols.ts +0 -9
- package/src/entities/BlockchainEntity.ts +0 -29
- package/src/entities/auriEnv.ts +0 -180
- package/src/entities/index.ts +0 -4
- package/src/entities/token.ts +0 -21
- package/src/entities/tokenAmount.ts +0 -48
- package/src/helpers/aurigami-api.ts +0 -42
- package/src/helpers/aurora-api-helpers.ts +0 -17
- package/src/helpers/graphql-helpers.ts +0 -8
- package/src/helpers/helpers.ts +0 -212
- package/src/helpers/historicalPriceFetcher.ts +0 -200
- package/src/helpers/index.ts +0 -7
- package/src/helpers/kyber-aggregator-api.ts +0 -37
- package/src/helpers/multicall.ts +0 -251
- package/src/helpers/notification-api.ts +0 -22
- package/src/helpers/one-inch-aggregator-api.ts +0 -45
- package/src/helpers/priceFetcher.ts +0 -388
- package/src/helpers/subgraphQuery.ts +0 -17
- package/src/helpers/transfer-event-query.ts +0 -68
- package/src/index.ts +0 -14
- package/src/interactors/Airdrop.ts +0 -72
- package/src/interactors/MoneyMarket.ts +0 -486
- package/src/interactors/Multicall.ts +0 -50
- package/src/interactors/Papermill.ts +0 -185
- package/src/interactors/PlyGame.ts +0 -172
- package/src/interactors/PlyTokenLock.ts +0 -46
- package/src/interactors/Pulp.ts +0 -41
- package/src/interactors/Referral.ts +0 -214
- package/src/interactors/Staking.ts +0 -156
- package/src/interactors/index.ts +0 -9
- package/src/interactors/misc.ts +0 -433
- package/src/types/index.ts +0 -252
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { BigNumber as BN } from 'ethers';
|
|
4
|
-
import * as consts from '../consts';
|
|
5
|
-
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
|
|
6
|
-
import * as helpers from '../helpers';
|
|
7
|
-
import { Address, NetworkConnection, UserLockingDetails } from '../types';
|
|
8
|
-
|
|
9
|
-
const LOCKING_DENOMINATOR = BN.from(10000);
|
|
10
|
-
export class PapermillRead extends BlockchainEntityRead {
|
|
11
|
-
public readonly plyToken: Token;
|
|
12
|
-
public readonly pulpToken: Token;
|
|
13
|
-
public readonly env: AuriEnv;
|
|
14
|
-
|
|
15
|
-
constructor(networkConnection: NetworkConnection) {
|
|
16
|
-
super(networkConnection);
|
|
17
|
-
this.env = new AuriEnv(networkConnection);
|
|
18
|
-
|
|
19
|
-
let plyAddress = consts.networkAddresses.tokens.PLY;
|
|
20
|
-
let pulpAddress = consts.networkAddresses.tokens.PULP;
|
|
21
|
-
|
|
22
|
-
this.plyToken = new Token(plyAddress, helpers.getDecimal(plyAddress));
|
|
23
|
-
this.pulpToken = new Token(pulpAddress, helpers.getDecimal(pulpAddress));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
|
|
27
|
-
const plyBalance = await this.env.ply.raw.balanceOf(userAddress);
|
|
28
|
-
return new TokenAmount(this.plyToken, plyBalance.toString());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
|
|
32
|
-
const pulpBalance = await this.env.pulp.raw.balanceOf(userAddress);
|
|
33
|
-
return new TokenAmount(this.pulpToken, pulpBalance.toString());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get all unclaimed PLY reward of the user in all markets + all staking pools
|
|
38
|
-
*/
|
|
39
|
-
public async getUnclaimedPlyReward(userAddress: Address): Promise<TokenAmount> {
|
|
40
|
-
let rewardBalancesMetadata = await this.env.auriLens.raw.callStatic.claimRewards(
|
|
41
|
-
this.env.comptroller.address,
|
|
42
|
-
this.env.auriFairLaunch.address,
|
|
43
|
-
consts.ALL_STAKING_POOLS,
|
|
44
|
-
{ from: userAddress }
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString());
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public getWeek(timestamp: number): number {
|
|
51
|
-
return BN.from(timestamp - consts.REWARD_CLAIM_START)
|
|
52
|
-
.div(consts.ONE_WEEK)
|
|
53
|
-
.toNumber();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get all locking details of the user in all markets + all staking pools
|
|
58
|
-
*/
|
|
59
|
-
public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
|
|
60
|
-
const currentWeek = this.getWeek(helpers.getCurrentTimestamp());
|
|
61
|
-
|
|
62
|
-
const values = await Promise.all([
|
|
63
|
-
this.env.auriLens.raw.getPercentLock(this.env.pulp.address, userAddress, currentWeek),
|
|
64
|
-
this.env.auriLens.raw.getPercentLock(this.env.pulp.address, userAddress, currentWeek + 1),
|
|
65
|
-
this.getUnclaimedPlyReward(userAddress),
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
let percentLockCurrentWeek = BN.from(values[0]);
|
|
69
|
-
let percentLockNextWeek = BN.from(values[1]);
|
|
70
|
-
let totalRewards = values[2] as TokenAmount;
|
|
71
|
-
|
|
72
|
-
let [pulpAmountCurrentWeek, plyAmountCurrentWeek] = await this.env.pulp.raw.calcLockAmount(
|
|
73
|
-
userAddress,
|
|
74
|
-
totalRewards.rawAmount()
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// Predict next week lock amount = totalRewards * percentLock next week
|
|
78
|
-
// This doesn't take (the reward that user might earn in the next week) into account
|
|
79
|
-
let plyAmountNextWeek = percentLockNextWeek
|
|
80
|
-
.mul(totalRewards.rawAmount())
|
|
81
|
-
.div(LOCKING_DENOMINATOR);
|
|
82
|
-
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(plyAmountNextWeek);
|
|
83
|
-
|
|
84
|
-
// we need to divide these two number by 10000 and multiple by 100 to get the percentage
|
|
85
|
-
// I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
|
|
86
|
-
let currentUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockCurrentWeek).toString();
|
|
87
|
-
let nextUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
vestingStart: consts.REWARD_CLAIM_START,
|
|
91
|
-
currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
|
|
92
|
-
accruedPly: totalRewards,
|
|
93
|
-
currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
|
|
94
|
-
currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
|
|
95
|
-
//
|
|
96
|
-
nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
|
|
97
|
-
nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
|
|
98
|
-
nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Get the first timestamp that the unlockPortion reach the target
|
|
104
|
-
*
|
|
105
|
-
* @param userAddress currently doesn't matter
|
|
106
|
-
* @param targetUnlockPortion unlockPortion target
|
|
107
|
-
*/
|
|
108
|
-
public async getTimestampToUnlock(
|
|
109
|
-
userAddress: Address,
|
|
110
|
-
targetUnlockPortion: number
|
|
111
|
-
): Promise<number> {
|
|
112
|
-
let weekId = await this.env.auriLens.raw.getWeekToUnlock(
|
|
113
|
-
this.env.pulp.address,
|
|
114
|
-
userAddress,
|
|
115
|
-
targetUnlockPortion * 100
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
return consts.REWARD_CLAIM_START + consts.ONE_WEEK * weekId.toNumber();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Get the start timestamp of next week of the papermill contract.
|
|
123
|
-
*
|
|
124
|
-
* This is a sync function!
|
|
125
|
-
*
|
|
126
|
-
* @returns the timestamp in seconds
|
|
127
|
-
*/
|
|
128
|
-
public getNextWeekTimestamp(): number {
|
|
129
|
-
const nextWeek = this.getWeek(helpers.getCurrentTimestamp()) + 1;
|
|
130
|
-
return consts.REWARD_CLAIM_START + consts.ONE_WEEK * nextWeek;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public async getUnlockPortionAt(userAddress: Address, timestamp: number): Promise<number> {
|
|
134
|
-
let lockPortion = await this.env.auriLens.raw.getPercentLock(
|
|
135
|
-
this.env.pulp.address,
|
|
136
|
-
userAddress,
|
|
137
|
-
this.getWeek(timestamp)
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
let unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
|
|
141
|
-
|
|
142
|
-
return unlockPortion.toNumber() / 100;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export class PapermillReadWrite extends PapermillRead {
|
|
147
|
-
constructor(networkConnection: NetworkConnection) {
|
|
148
|
-
super(networkConnection);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Redeem PLY from PULP and transfer PLY to another address
|
|
153
|
-
* @param recipient Address that will receive the PLY.
|
|
154
|
-
* @param amount Amount of PULP to be converted to PLY.
|
|
155
|
-
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
156
|
-
*/
|
|
157
|
-
public async redeem(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
|
|
158
|
-
return this.env.pulp.raw
|
|
159
|
-
.connect(this._networkConnection.signer!)
|
|
160
|
-
.redeem(recipient, amount.rawAmount());
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Redeem PLY from PULP and transfer PLY to msg.sender
|
|
165
|
-
* @param amount Amount of PULP to be converted to PLY.
|
|
166
|
-
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
167
|
-
*/
|
|
168
|
-
public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
|
|
169
|
-
let msgSender: string = await this._networkConnection.signer!.getAddress();
|
|
170
|
-
return this.redeem(msgSender, amount);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export class Papermill extends BlockchainEntity {
|
|
175
|
-
constructor() {
|
|
176
|
-
super();
|
|
177
|
-
}
|
|
178
|
-
public read(networkConnection: NetworkConnection): PapermillRead {
|
|
179
|
-
return new PapermillRead(networkConnection);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
|
|
183
|
-
return new PapermillReadWrite(networkConnection);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
-
import { BigNumber as BN } from 'ethers';
|
|
3
|
-
import * as consts from '../consts';
|
|
4
|
-
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
|
|
5
|
-
import * as helpers from '../helpers';
|
|
6
|
-
import { getBlocksTimestamp, isSameAddress, sleep, sortEvents } from '../helpers';
|
|
7
|
-
import * as AuriAPI from '../helpers/aurigami-api';
|
|
8
|
-
import {
|
|
9
|
-
Address,
|
|
10
|
-
NetworkConnection,
|
|
11
|
-
PlyBetMadeEvent,
|
|
12
|
-
PlyGameBetResult,
|
|
13
|
-
PlyGameLeaderboardItem,
|
|
14
|
-
} from '../types';
|
|
15
|
-
|
|
16
|
-
export class PlyGameRead extends BlockchainEntityRead {
|
|
17
|
-
public readonly plyToken: Token;
|
|
18
|
-
public readonly pulpToken: Token;
|
|
19
|
-
public readonly env: AuriEnv;
|
|
20
|
-
|
|
21
|
-
public constructor(networkConnection: NetworkConnection) {
|
|
22
|
-
super(networkConnection);
|
|
23
|
-
this.env = new AuriEnv(networkConnection);
|
|
24
|
-
|
|
25
|
-
let plyAddress = consts.networkAddresses.tokens.PLY;
|
|
26
|
-
let pulpAddress = consts.networkAddresses.tokens.PULP;
|
|
27
|
-
this.plyToken = new Token(plyAddress, helpers.getDecimal(plyAddress));
|
|
28
|
-
this.pulpToken = new Token(pulpAddress, helpers.getDecimal(pulpAddress));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private parseBetMakeEvent(event: PlyBetMadeEvent): PlyGameBetResult {
|
|
32
|
-
let outcome = ['bigWin', 'win', 'lose', 'noImpact'][event.args.outcome];
|
|
33
|
-
let betAmount = event.args.amount;
|
|
34
|
-
// 0%, 0%, 100%, 2%
|
|
35
|
-
// big win, win, lose, no impact
|
|
36
|
-
let lostAmount = betAmount.mul([0, 0, 100, 2][event.args.outcome]).div(100);
|
|
37
|
-
let unlock = betAmount.mul([10, 1, 0, 0][event.args.outcome]);
|
|
38
|
-
return {
|
|
39
|
-
player: event.args.player,
|
|
40
|
-
lostAmount: new TokenAmount(this.plyToken, lostAmount.toString()),
|
|
41
|
-
unlockedPulpAmount: new TokenAmount(this.pulpToken, unlock.toString()),
|
|
42
|
-
outcome: outcome,
|
|
43
|
-
transactionHash: event.transactionHash,
|
|
44
|
-
block: event.blockNumber,
|
|
45
|
-
timestamp: 0, // will be filled later
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private async attachTimestamp(results: PlyGameBetResult[]): Promise<PlyGameBetResult[]> {
|
|
50
|
-
let blockNumbers = results.map((e) => e.block);
|
|
51
|
-
let blockstimestamp = await getBlocksTimestamp(this._networkConnection.provider, blockNumbers);
|
|
52
|
-
return results.map((e, i) => ({ ...e, timestamp: blockstimestamp[i] }));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get 100 most recent bets of the market users
|
|
57
|
-
*/
|
|
58
|
-
public async getUserPlyGameHistory(user: Address): Promise<PlyGameBetResult[]> {
|
|
59
|
-
let block100 = await this.env.plygame.callStatic.getLastBlock(user, 100);
|
|
60
|
-
|
|
61
|
-
if (block100.eq(0)) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let filter = this.env.plygame.raw.filters.BetMade(user);
|
|
66
|
-
let events = await this.env.plygame.raw.queryFilter(filter, block100.toNumber());
|
|
67
|
-
// Sort descending by block number
|
|
68
|
-
sortEvents(events).reverse();
|
|
69
|
-
return this.attachTimestamp(events.map((event) => this.parseBetMakeEvent(event)));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get current jackpot amount
|
|
74
|
-
*/
|
|
75
|
-
public async currentJackpotAmount(): Promise<TokenAmount> {
|
|
76
|
-
let jackpot = await this.env.plygame.callStatic.currentJackpotAmount();
|
|
77
|
-
return new TokenAmount(this.plyToken, jackpot.toString());
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public async earlyUnlockedPulpAmount(user: Address): Promise<TokenAmount> {
|
|
81
|
-
let earlyUnlockedPulpAmount = await this.env.plygame.callStatic.totalPlyUnlockedEarly(user);
|
|
82
|
-
return new TokenAmount(this.pulpToken, earlyUnlockedPulpAmount.toString());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public async getPlyGameResultsInTransaction(txHash: Address): Promise<PlyGameBetResult[]> {
|
|
86
|
-
// wait for the tx to be mined if needed.
|
|
87
|
-
// Don't use `waitForTransaction` because it will wait for longer than needed.
|
|
88
|
-
let tx = await this._networkConnection.provider.getTransactionReceipt(txHash);
|
|
89
|
-
|
|
90
|
-
for (let i = 0; i < 100 && !tx; i++) {
|
|
91
|
-
await sleep(1000); // Sleep for 1 second before retrying
|
|
92
|
-
tx = await this._networkConnection.provider.getTransactionReceipt(txHash);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!tx) {
|
|
96
|
-
throw new Error(`Transaction ${txHash} takes too long to be mined`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let filter = this.env.plygame.raw.filters.BetMade();
|
|
100
|
-
let betMadeEvents: PlyBetMadeEvent[] = tx.logs
|
|
101
|
-
.filter((log) => isSameAddress(log.topics[0], filter.topics![0] as string))
|
|
102
|
-
.map((log) => ({
|
|
103
|
-
...this.env.plygame.raw.interface.parseLog(log),
|
|
104
|
-
blockNumber: tx.blockNumber,
|
|
105
|
-
transactionHash: txHash,
|
|
106
|
-
})) as unknown as PlyBetMadeEvent[];
|
|
107
|
-
|
|
108
|
-
return this.attachTimestamp(betMadeEvents.map((e) => this.parseBetMakeEvent(e)));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Top 100 users by amount of PULP unlocked
|
|
113
|
-
*/
|
|
114
|
-
public async leaderboard(): Promise<PlyGameLeaderboardItem[]> {
|
|
115
|
-
const result = await AuriAPI.getPaginatedApi('/plygame/leaderboard');
|
|
116
|
-
return result.items.map((item, i) => ({
|
|
117
|
-
player: item.user!,
|
|
118
|
-
unlockedPulpAmount: new TokenAmount(this.pulpToken, item.unlockedAmount!),
|
|
119
|
-
gamesPlayed: item.count!,
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public async getLastJackpotResult(): Promise<{ winner: Address; amount: TokenAmount }> {
|
|
124
|
-
// 158 is the storage slot of the jackpot length
|
|
125
|
-
let round = BN.from(
|
|
126
|
-
await this._networkConnection.provider.getStorageAt(this.env.plygame.address, 158)
|
|
127
|
-
);
|
|
128
|
-
let result = await this.env.plygame.callStatic.jackpotHistory(round.sub(1));
|
|
129
|
-
return {
|
|
130
|
-
winner: result.winner.slice(0, 5) + '...' + result.winner.slice(-3),
|
|
131
|
-
amount: new TokenAmount(this.plyToken, result.amount.toString()),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public async overallLeaderboard(): Promise<PlyGameLeaderboardItem[]> {
|
|
136
|
-
const result = await AuriAPI.getPaginatedApi('/plygame/overallLeaderboard');
|
|
137
|
-
return result.items.map((item) => ({
|
|
138
|
-
player: item.user,
|
|
139
|
-
unlockedPulpAmount: new TokenAmount(this.pulpToken, item.unlockedAmount!),
|
|
140
|
-
gamesPlayed: item.count!,
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export class PlyGameReadWrite extends PlyGameRead {
|
|
146
|
-
/**
|
|
147
|
-
* Make a single bet
|
|
148
|
-
*/
|
|
149
|
-
public async makeBetOnce(amount: TokenAmount): Promise<TransactionResponse> {
|
|
150
|
-
return this.env.plygame.raw
|
|
151
|
-
.connect(this._networkConnection.signer!)
|
|
152
|
-
.makeBetOnce(amount.rawAmount());
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public async approve(amount: TokenAmount): Promise<TransactionResponse> {
|
|
156
|
-
return this.env.ply.raw
|
|
157
|
-
.connect(this._networkConnection.signer!)
|
|
158
|
-
.approve(this.env.plygame.address, amount.rawAmount());
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export class PlyGame extends BlockchainEntity {
|
|
163
|
-
constructor() {
|
|
164
|
-
super();
|
|
165
|
-
}
|
|
166
|
-
public read(networkConnection: NetworkConnection): PlyGameRead {
|
|
167
|
-
return new PlyGameRead(networkConnection);
|
|
168
|
-
}
|
|
169
|
-
public readWrite(networkConnection: NetworkConnection): PlyGameReadWrite {
|
|
170
|
-
return new PlyGameReadWrite(networkConnection);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
-
import { BigNumber as BN } from 'ethers';
|
|
3
|
-
import {
|
|
4
|
-
AuriEnv,
|
|
5
|
-
BlockchainEntity,
|
|
6
|
-
BlockchainEntityRead,
|
|
7
|
-
PLYToken,
|
|
8
|
-
Token,
|
|
9
|
-
TokenAmount,
|
|
10
|
-
} from '../entities';
|
|
11
|
-
import { Address, NetworkConnection } from '../types';
|
|
12
|
-
|
|
13
|
-
export class PlyTokenLockRead extends BlockchainEntityRead {
|
|
14
|
-
public readonly env: AuriEnv;
|
|
15
|
-
|
|
16
|
-
public constructor(networkConnection: NetworkConnection) {
|
|
17
|
-
super(networkConnection);
|
|
18
|
-
this.env = new AuriEnv(networkConnection);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async getClaimableAmount(recipient: Address): Promise<TokenAmount> {
|
|
22
|
-
const claimableAmount = await this.env.plyTokenLock.callStatic.claimableBalance(recipient);
|
|
23
|
-
return new TokenAmount(new Token(PLYToken.address, 18), claimableAmount.toString(), true);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class PlyTokenLockReadWrite extends PlyTokenLockRead {
|
|
28
|
-
public async claim(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
|
|
29
|
-
const amountToClaim = BN.from(amount.rawAmount());
|
|
30
|
-
return await this.env.plyTokenLock.raw
|
|
31
|
-
.connect(this._networkConnection.signer!)
|
|
32
|
-
.claim(recipient, amountToClaim);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class PlyTokenLock extends BlockchainEntity {
|
|
37
|
-
constructor() {
|
|
38
|
-
super();
|
|
39
|
-
}
|
|
40
|
-
public read(networkConnection: NetworkConnection): PlyTokenLockRead {
|
|
41
|
-
return new PlyTokenLockRead(networkConnection);
|
|
42
|
-
}
|
|
43
|
-
public readWrite(networkConnection: NetworkConnection): PlyTokenLockReadWrite {
|
|
44
|
-
return new PlyTokenLockReadWrite(networkConnection);
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/interactors/Pulp.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
-
import { BigNumber as BN } from 'ethers';
|
|
3
|
-
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
|
|
4
|
-
import { Address, NetworkConnection } from '../types';
|
|
5
|
-
|
|
6
|
-
export class PulpRead extends BlockchainEntityRead {
|
|
7
|
-
public readonly env: AuriEnv;
|
|
8
|
-
|
|
9
|
-
public constructor(networkConnection: NetworkConnection) {
|
|
10
|
-
super(networkConnection);
|
|
11
|
-
this.env = new AuriEnv(networkConnection);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public async remainingEarlyUnlockPulp(user: Address): Promise<BN> {
|
|
15
|
-
return this.env.pulp.callStatic.earlyRedeems(user);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class PulpReadWrite extends PulpRead {
|
|
20
|
-
public async convertEarlyPulp(
|
|
21
|
-
recipient: Address,
|
|
22
|
-
amount: TokenAmount
|
|
23
|
-
): Promise<TransactionResponse> {
|
|
24
|
-
const amountToRedeem = BN.from(amount.rawAmount());
|
|
25
|
-
return this.env.pulp.raw
|
|
26
|
-
.connect(this._networkConnection.signer!)
|
|
27
|
-
.redeem(recipient, amountToRedeem);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class Pulp extends BlockchainEntity {
|
|
32
|
-
constructor() {
|
|
33
|
-
super();
|
|
34
|
-
}
|
|
35
|
-
public read(networkConnection: NetworkConnection): PulpRead {
|
|
36
|
-
return new PulpRead(networkConnection);
|
|
37
|
-
}
|
|
38
|
-
public readWrite(networkConnection: NetworkConnection): PulpReadWrite {
|
|
39
|
-
return new PulpReadWrite(networkConnection);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
|
-
import { AURORA_PLUS_API_PREFIX, REFERRAL_CAMPAIGNS } from '../consts';
|
|
5
|
-
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
|
|
6
|
-
import { getBlocksTimestamp } from '../helpers';
|
|
7
|
-
import * as AuriAPI from '../helpers/aurigami-api';
|
|
8
|
-
import { Address, NetworkConnection, ReferralReward } from '../types';
|
|
9
|
-
import { AirdropReadWrite } from './Airdrop';
|
|
10
|
-
|
|
11
|
-
export class ReferralRead extends BlockchainEntityRead {
|
|
12
|
-
public readonly env: AuriEnv;
|
|
13
|
-
constructor(networkConnection: NetworkConnection) {
|
|
14
|
-
super(networkConnection);
|
|
15
|
-
this.env = new AuriEnv(networkConnection);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Generate a 10-character referral code
|
|
20
|
-
* containing alphanumeric characters.
|
|
21
|
-
*/
|
|
22
|
-
protected generateReferralCode(): string {
|
|
23
|
-
let letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
24
|
-
let numbers = '1234567890';
|
|
25
|
-
let charset = letters + letters.toUpperCase() + numbers;
|
|
26
|
-
let R = '';
|
|
27
|
-
for (var i = 0; i < 10; i++) R += charset[Math.floor(Math.random() * charset.length)];
|
|
28
|
-
return R;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Get the referral code for a given address, returns empty string if not found.
|
|
33
|
-
*
|
|
34
|
-
* Called to check if a user has a referral code.
|
|
35
|
-
*/
|
|
36
|
-
public async getUserReferralCode(userAddr: Address): Promise<string> {
|
|
37
|
-
const result = await this.env.referralDirectoryV2.raw.userReferralCode(userAddr);
|
|
38
|
-
return ethers.utils.parseBytes32String(result);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Get referral code that a user was referred by, returns empty string if not found.
|
|
43
|
-
*/
|
|
44
|
-
public async getReferralCodeUsed(userAddr: Address): Promise<string> {
|
|
45
|
-
const result = await this.env.referralDirectoryV2.raw.referralCodeUsed(userAddr);
|
|
46
|
-
return ethers.utils.parseBytes32String(result);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Get owner of a referral code, returns zero address if not found.
|
|
51
|
-
*/
|
|
52
|
-
public async getReferralCodeOwner(code: string): Promise<Address> {
|
|
53
|
-
const referralCode = ethers.utils.formatBytes32String(code);
|
|
54
|
-
return this.env.referralDirectoryV2.raw.referralCodeOwner(referralCode);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Get referrals of a user, sorted descending by timestamp.
|
|
59
|
-
*/
|
|
60
|
-
public async getReferralsList(userAddr: Address): Promise<{ user: string; timestamp: number }[]> {
|
|
61
|
-
const result = await AuriAPI.getPaginatedApi('/referral/list', { address: userAddr });
|
|
62
|
-
const blocks = result.items.map((item) => item.blockNumber!);
|
|
63
|
-
const blocksTimestamp = await getBlocksTimestamp(this._networkConnection.provider, blocks);
|
|
64
|
-
const items = result.items.map((item, i) => ({
|
|
65
|
-
user: item.user!,
|
|
66
|
-
timestamp: blocksTimestamp[i],
|
|
67
|
-
}));
|
|
68
|
-
return items;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Array of rewards, sorted by time of the referral period (from latest to oldest)
|
|
73
|
-
*/
|
|
74
|
-
public async referralRewards(userAddr: Address): Promise<ReferralReward[]> {
|
|
75
|
-
const result = await AuriAPI.getPaginatedApi('/referral/rewards', { address: userAddr });
|
|
76
|
-
let items: ReferralReward[] = result.items.map((item, i) => ({
|
|
77
|
-
campaign: item.campaign!,
|
|
78
|
-
userAddr: userAddr,
|
|
79
|
-
isReferrer: (item.campaign as string).includes('referrer'),
|
|
80
|
-
rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
|
|
81
|
-
startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
|
|
82
|
-
endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
|
|
83
|
-
transactionHash: item.transactionHash ?? null,
|
|
84
|
-
refereeAddress: null,
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
return items;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Top 50 reward earners from the last round, sorted by token amount
|
|
92
|
-
*/
|
|
93
|
-
public async leaderboard(campaign: string): Promise<ReferralReward[]> {
|
|
94
|
-
const result = await AuriAPI.getPaginatedApi('/referral/leaderboard', { campaign: campaign });
|
|
95
|
-
const items: ReferralReward[] = result.items.map((item, i) => ({
|
|
96
|
-
campaign: campaign,
|
|
97
|
-
userAddr: item.user!,
|
|
98
|
-
isReferrer: (item.campaign as string).includes('referrer'),
|
|
99
|
-
rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
|
|
100
|
-
startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
|
|
101
|
-
endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
|
|
102
|
-
transactionHash: null,
|
|
103
|
-
refereeAddress: null,
|
|
104
|
-
}));
|
|
105
|
-
items.sort((a, b) => b.rewardTokenAmount.compare(a.rewardTokenAmount));
|
|
106
|
-
return items;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* current number of slots under a referral code being used that exceed minimum deposit amount
|
|
111
|
-
*/
|
|
112
|
-
public async slotsInUse(): Promise<number> {
|
|
113
|
-
let result = await AuriAPI.getApi('/referral/slotsInUse');
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public totalReferralSlots() {
|
|
118
|
-
return 500;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public async queuePosition(address: Address): Promise<number> {
|
|
122
|
-
let result = await AuriAPI.getApi('/referral/queuePosition', { address: address });
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* a way to determine qualification status of a user. null if not referred yet,
|
|
128
|
-
* qualified if referred + min deposit, notQualified if referred + min deposit
|
|
129
|
-
* not reached or withdrew too early
|
|
130
|
-
*/
|
|
131
|
-
public async userReferralStatus(userAddr: Address): Promise<string> {
|
|
132
|
-
let result: number = await AuriAPI.getApi('/referral/referralStatus', { address: userAddr });
|
|
133
|
-
switch (result) {
|
|
134
|
-
case -1:
|
|
135
|
-
return 'notReferred';
|
|
136
|
-
case 0:
|
|
137
|
-
return 'notQualified';
|
|
138
|
-
case 1:
|
|
139
|
-
return 'Qualified';
|
|
140
|
-
default:
|
|
141
|
-
return 'Withdrawn';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public async isWhitelistedAddress(address: Address): Promise<boolean> {
|
|
146
|
-
let result = await this.env.referralDirectoryV2.raw.isUserWhitelisted(address);
|
|
147
|
-
return result.eq(1);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public async isOnAuroraPlus(address: Address): Promise<boolean> {
|
|
151
|
-
let resp = await axios.get(AURORA_PLUS_API_PREFIX + address);
|
|
152
|
-
|
|
153
|
-
return resp.data.status == 'active';
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public async isNewUserAtReferralTime(address: Address): Promise<boolean> {
|
|
157
|
-
let result: boolean = await AuriAPI.getApi('/referral/isNewUser', { address: address });
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public async depositedMoreThanMinimumAmount(address: Address): Promise<boolean> {
|
|
162
|
-
let result: boolean = await AuriAPI.getApi('/referral/depositedEnough', { address: address });
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export class ReferralReadWrite extends ReferralRead {
|
|
168
|
-
/**
|
|
169
|
-
* Generate a referral code for a given address.
|
|
170
|
-
*
|
|
171
|
-
* Called when an user want to creates his own referral code
|
|
172
|
-
*/
|
|
173
|
-
public async registerNewReferralCode(): Promise<TransactionResponse> {
|
|
174
|
-
const referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
|
|
175
|
-
return this.env.referralDirectoryV2.raw
|
|
176
|
-
.connect(this._networkConnection.signer!)
|
|
177
|
-
.registerNewUserReferralCode(referralCode);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Called when an user confirms he is referred by a specified code
|
|
182
|
-
*/
|
|
183
|
-
public async useReferralCode(code: string): Promise<TransactionResponse> {
|
|
184
|
-
const referralCode = ethers.utils.formatBytes32String(code);
|
|
185
|
-
return this.env.referralDirectoryV2.raw
|
|
186
|
-
.connect(this._networkConnection.signer!)
|
|
187
|
-
.registerReferralCodeUsed(referralCode);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Claim all unclaimed rewards for a given user
|
|
192
|
-
*/
|
|
193
|
-
public async claimReferralRewards(): Promise<TransactionResponse> {
|
|
194
|
-
const unclaimedRewards = (
|
|
195
|
-
await this.referralRewards(await this._networkConnection.signer!.getAddress())
|
|
196
|
-
).filter((reward) => reward.transactionHash == null);
|
|
197
|
-
const campaigns = unclaimedRewards.map((reward) => reward.campaign);
|
|
198
|
-
const tokens = unclaimedRewards.map((reward) => reward.rewardTokenAmount.token.address);
|
|
199
|
-
return new AirdropReadWrite(this._networkConnection).redeemMultiple(campaigns, tokens);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export class Referral extends BlockchainEntity {
|
|
204
|
-
constructor() {
|
|
205
|
-
super();
|
|
206
|
-
}
|
|
207
|
-
public read(networkConnection: NetworkConnection): ReferralRead {
|
|
208
|
-
return new ReferralRead(networkConnection);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public readWrite(networkConnection: NetworkConnection): ReferralReadWrite {
|
|
212
|
-
return new ReferralReadWrite(networkConnection);
|
|
213
|
-
}
|
|
214
|
-
}
|