@aurigami/sdk 1.7.8-dummy → 1.8.0
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/constants.d.ts +6 -0
- package/dist/contracts/Referral.d.ts +1 -1
- package/dist/entities/tokenAmount.d.ts +1 -0
- package/dist/sdk.cjs.development.js +64 -9
- 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 +64 -10
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/consts/constants.ts +6 -0
- package/src/consts/dummy.ts +2 -0
- package/src/contracts/Referral.ts +26 -7
- package/src/entities/tokenAmount.ts +4 -0
- package/src/types/index.ts +4 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -107,6 +107,10 @@ export declare type AuTokenWithUnderlying = AuToken & {
|
|
|
107
107
|
};
|
|
108
108
|
export declare type ReferralReward = {
|
|
109
109
|
campaign: string;
|
|
110
|
+
/**
|
|
111
|
+
* Truncated user address.
|
|
112
|
+
*/
|
|
113
|
+
userAddr: string;
|
|
110
114
|
/**
|
|
111
115
|
* start timetamp of the referral round
|
|
112
116
|
*/
|
package/package.json
CHANGED
package/src/consts/constants.ts
CHANGED
|
@@ -162,3 +162,9 @@ export const BORROW_NEAR_REWARDS_PER_WEEK: { [k: string]: string } = {
|
|
|
162
162
|
export const HARDCODE_PRICE_TOKENS: { [k: string]: string } = Object.fromEntries([
|
|
163
163
|
[networkAddresses.tokens.USN.toLowerCase(), '1'],
|
|
164
164
|
]);
|
|
165
|
+
|
|
166
|
+
export const REFERRAL_CAMPAIGNS: { [k: string]: { start: number; end: number } } =
|
|
167
|
+
Object.fromEntries([
|
|
168
|
+
['referral-1805', { start: 1652882400, end: 1653487199 }],
|
|
169
|
+
['referrer-1805', { start: 1652882400, end: 1653487199 }],
|
|
170
|
+
]);
|
package/src/consts/dummy.ts
CHANGED
|
@@ -35,6 +35,7 @@ export const referralRewardDummy1: ReferralReward = {
|
|
|
35
35
|
isReferrer: false,
|
|
36
36
|
rewardTokenAmount: dummyTokenAmount,
|
|
37
37
|
transactionHash: null,
|
|
38
|
+
userAddr: '0x...123',
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export const referralRewardDummy2: ReferralReward = {
|
|
@@ -44,4 +45,5 @@ export const referralRewardDummy2: ReferralReward = {
|
|
|
44
45
|
isReferrer: true,
|
|
45
46
|
rewardTokenAmount: dummyTokenAmount2,
|
|
46
47
|
transactionHash: '0x4da9657663b46ef18d150b897b28c7b717f16421978b52e3a06d91b54ca3548b',
|
|
48
|
+
userAddr: '0x...456',
|
|
47
49
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
|
-
import {
|
|
4
|
-
import { AuriEnv, BlockchainEntity, BlockchainEntityRead } from '../entities';
|
|
3
|
+
import { REFERRAL_CAMPAIGNS } from '../consts';
|
|
4
|
+
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, TokenAmount } from '../entities';
|
|
5
5
|
import { getBlocksTimestamp } from '../helpers';
|
|
6
6
|
import * as AuriAPI from '../helpers/aurigami-api';
|
|
7
7
|
import { Address, NetworkConnection, ReferralReward } from '../types';
|
|
@@ -71,16 +71,35 @@ export class ReferralRead extends BlockchainEntityRead {
|
|
|
71
71
|
* Array of rewards, sorted by time of the referral period (from latest to oldest)
|
|
72
72
|
*/
|
|
73
73
|
public async referralRewards(userAddr: Address): Promise<ReferralReward[]> {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const result = await AuriAPI.getPaginatedApi('/referral/rewards', { address: userAddr });
|
|
75
|
+
const items: ReferralReward[] = result.items.map((item, i) => ({
|
|
76
|
+
campaign: item.campaign!,
|
|
77
|
+
userAddr: userAddr,
|
|
78
|
+
isReferrer: (item.campaign as string).includes('referrer'),
|
|
79
|
+
rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
|
|
80
|
+
startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
|
|
81
|
+
endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
|
|
82
|
+
transactionHash: item?.transactionHash,
|
|
83
|
+
}));
|
|
84
|
+
return items;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/**
|
|
79
88
|
* Top 50 reward earners from the last round, sorted by token amount
|
|
80
89
|
*/
|
|
81
|
-
public async leaderboard(): Promise<ReferralReward[]> {
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
public async leaderboard(campaign: string): Promise<ReferralReward[]> {
|
|
91
|
+
const result = await AuriAPI.getPaginatedApi('/referral/leaderboard', { campaign: campaign });
|
|
92
|
+
const items: ReferralReward[] = result.items.map((item, i) => ({
|
|
93
|
+
campaign: campaign,
|
|
94
|
+
userAddr: item.user!,
|
|
95
|
+
isReferrer: (item.campaign as string).includes('referrer'),
|
|
96
|
+
rewardTokenAmount: TokenAmount.fromAddressAndAmount(item.token, item.amount),
|
|
97
|
+
startTime: REFERRAL_CAMPAIGNS[item.campaign].start,
|
|
98
|
+
endTime: REFERRAL_CAMPAIGNS[item.campaign].end,
|
|
99
|
+
transactionHash: null,
|
|
100
|
+
}));
|
|
101
|
+
items.sort((a, b) => b.rewardTokenAmount.compare(a.rewardTokenAmount));
|
|
102
|
+
return items;
|
|
84
103
|
}
|
|
85
104
|
}
|
|
86
105
|
|
|
@@ -28,6 +28,10 @@ export class TokenAmount {
|
|
|
28
28
|
return this.rawAmnt;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
public compare(other: TokenAmount): number {
|
|
32
|
+
return new BigNumber(this.rawAmnt).comparedTo(new BigNumber(other.rawAmnt));
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
public static fromAddressAndAmount(
|
|
32
36
|
tokenAddress: Address,
|
|
33
37
|
amount: string,
|
package/src/types/index.ts
CHANGED