@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.
@@ -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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.8-dummy",
2
+ "version": "1.8.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -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
+ ]);
@@ -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 { referralRewardDummy1, referralRewardDummy2 } from '../consts';
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
- // TODO: Fix this
75
- return [referralRewardDummy1, referralRewardDummy2];
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
- // TODO: Fix this
83
- return [referralRewardDummy2, referralRewardDummy1];
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,
@@ -124,6 +124,10 @@ export type AuTokenWithUnderlying = AuToken & {
124
124
 
125
125
  export type ReferralReward = {
126
126
  campaign: string;
127
+ /**
128
+ * Truncated user address.
129
+ */
130
+ userAddr: string;
127
131
  /**
128
132
  * start timetamp of the referral round
129
133
  */