@aurigami/sdk 1.7.9-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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.9-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
+ ]);
@@ -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,