@aurigami/sdk 1.6.5 → 1.6.7

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.6.5",
2
+ "version": "1.6.7",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "typescript": "^4.5.4"
63
63
  },
64
64
  "dependencies": {
65
- "@aurigami/contracts": "3.6.0",
65
+ "@aurigami/contracts": "3.8.0",
66
66
  "axios": "^0.26.1",
67
67
  "bignumber.js": "^9.0.2",
68
68
  "ethers": "^5.6.4"
package/src/SDK.ts CHANGED
@@ -1,4 +1,8 @@
1
+ import { UltilizationHelper } from '@aurigami/contracts/typechain';
1
2
  import { TransactionResponse } from '@ethersproject/abstract-provider';
3
+ import BigNumber from 'bignumber.js';
4
+ import { Contract } from 'ethers';
5
+ import * as abis from './abis';
2
6
  import * as consts from './consts';
3
7
  import { MiscRead, StakingRead, StakingReadWrite } from './contracts';
4
8
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
@@ -78,6 +82,18 @@ export class SdkRead extends BlockchainEntityRead {
78
82
  public async getPlyCirculatingSupply(): Promise<TokenAmount> {
79
83
  return this._misc.getPlyCirculatingSupply();
80
84
  }
85
+
86
+ public async getUltilizations(userAddr: types.Address): Promise<BigNumber> {
87
+ let helper: UltilizationHelper = new Contract(
88
+ consts.networkAddresses.misc.ultilizationHelper,
89
+ abis.UltilizationHelperABI.abi,
90
+ this._networkConnection.provider
91
+ ) as UltilizationHelper;
92
+ let accountDetail = await helper.getAccountLiquidity(userAddr);
93
+ let sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
94
+ let sumCol = new BigNumber(accountDetail.sumCollateral.toString());
95
+ return sumBorrow.dividedBy(sumCol);
96
+ }
81
97
  }
82
98
 
83
99
  export class SdkReadWrite extends SdkRead {
package/src/abis/index.ts CHANGED
@@ -10,6 +10,7 @@ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interface
10
10
  // import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
11
11
  import IUniswapV2PairABI from '@aurigami/contracts/artifacts/contracts/mock/IUniswapV2Pair.sol/IUniswapV2Pair.json';
12
12
  import Multicall2ABI from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
13
+ import UltilizationHelperABI from '@aurigami/contracts/artifacts/contracts/mock/UltilizationHelper.sol/UltilizationHelper.json';
13
14
  import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
14
15
  import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
15
16
  export {
@@ -27,4 +28,5 @@ export {
27
28
  EthRepayHelperABI,
28
29
  Multicall2ABI,
29
30
  PulpABI,
31
+ UltilizationHelperABI
30
32
  };
@@ -8,12 +8,12 @@ import * as helpers from '../helpers';
8
8
  import { Address, NetworkConnection } from '../types';
9
9
 
10
10
  export class AirdropRead extends BlockchainEntityRead {
11
- protected _airDrop: AuriAirdrop;
11
+ public readonly airDrop: AuriAirdrop;
12
12
 
13
13
  public constructor(networkConnection: NetworkConnection) {
14
14
  super(networkConnection);
15
15
 
16
- this._airDrop = new Contract(
16
+ this.airDrop = new Contract(
17
17
  consts.networkAddresses.misc.AURI_AIRDROP,
18
18
  AuriAirdropABI.abi,
19
19
  networkConnection.provider
@@ -30,7 +30,7 @@ export class AirdropRead extends BlockchainEntityRead {
30
30
  ): Promise<TokenAmount> {
31
31
  let tokenInstance: Token = new Token(token, helpers.getDecimal(token));
32
32
 
33
- let rewards: BN = await this._airDrop.getRedeemableReward(
33
+ let rewards: BN = await this.airDrop.getRedeemableReward(
34
34
  utils.formatBytes32String(campaign),
35
35
  token,
36
36
  user
@@ -52,7 +52,7 @@ export class AirdropReadWrite extends AirdropRead {
52
52
  campaigns.length == tokens.length,
53
53
  'campaigns and tokens must have the same length'
54
54
  );
55
- return this._airDrop.connect(this._networkConnection.signer!).redeem(
55
+ return this.airDrop.connect(this._networkConnection.signer!).redeem(
56
56
  campaigns.map((e) => utils.formatBytes32String(e)),
57
57
  tokens,
58
58
  await this._networkConnection.signer!.getAddress()
@@ -26,7 +26,7 @@ type RewardSpeeds = {
26
26
  export class MoneyMarketRead extends BlockchainEntityRead {
27
27
  public underlying: Token;
28
28
  public auToken: AuErc20 | AuETH;
29
- protected env: AuriEnv;
29
+ public readonly env: AuriEnv;
30
30
  constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
31
31
  super(networkConnection);
32
32
  this.env = new AuriEnv(networkConnection);
@@ -7,10 +7,10 @@ import { BlockchainEntityRead } from '../entities';
7
7
  import { NetworkConnection } from '../types';
8
8
 
9
9
  export class MulticallRead extends BlockchainEntityRead {
10
- protected _multicall: Multicall2;
10
+ public readonly multicall: Multicall2;
11
11
  constructor(networkConnection: NetworkConnection) {
12
12
  super(networkConnection);
13
- this._multicall = new Contract(
13
+ this.multicall = new Contract(
14
14
  consts.networkAddresses.misc.MULTICALL,
15
15
  abis.Multicall2ABI.abi,
16
16
  networkConnection.provider
@@ -36,7 +36,7 @@ export class MulticallRead extends BlockchainEntityRead {
36
36
  txns.push({ target: txn.to!, callData: txn.data! });
37
37
  }
38
38
 
39
- const response = await this._multicall.callStatic.aggregate(txns);
39
+ const response = await this.multicall.callStatic.aggregate(txns);
40
40
 
41
41
  // parse results
42
42
  const decodedReturn = [];
@@ -8,9 +8,9 @@ import { Address, NetworkConnection, UserLockingDetails } from '../types';
8
8
 
9
9
  const LOCKING_DENOMINATOR = BN.from(10000);
10
10
  export class PapermillRead extends BlockchainEntityRead {
11
- public plyToken: Token;
12
- public pulpToken: Token;
13
- protected env: AuriEnv;
11
+ public readonly plyToken: Token;
12
+ public readonly pulpToken: Token;
13
+ public readonly env: AuriEnv;
14
14
 
15
15
  constructor(networkConnection: NetworkConnection) {
16
16
  super(networkConnection);
@@ -7,10 +7,10 @@ import { BlockchainEntity, BlockchainEntityRead } from '../entities';
7
7
  import { Address, NetworkConnection } from '../types';
8
8
 
9
9
  export class ReferralRead extends BlockchainEntityRead {
10
- protected _referral: ReferralDirectory;
10
+ public readonly referral: ReferralDirectory;
11
11
  constructor(networkConnection: NetworkConnection) {
12
12
  super(networkConnection);
13
- this._referral = new Contract(
13
+ this.referral = new Contract(
14
14
  consts.networkAddresses.misc.REFERRAL,
15
15
  abis.ReferralDirectoryABI.abi,
16
16
  networkConnection.provider
@@ -36,7 +36,7 @@ export class ReferralRead extends BlockchainEntityRead {
36
36
  * Called to check if a user has a referral code.
37
37
  */
38
38
  public async getUserReferralCode(userAddr: Address): Promise<string> {
39
- const result = await this._referral.userReferralCode(userAddr);
39
+ const result = await this.referral.userReferralCode(userAddr);
40
40
  return ethers.utils.parseBytes32String(result);
41
41
  }
42
42
 
@@ -44,7 +44,7 @@ export class ReferralRead extends BlockchainEntityRead {
44
44
  * Get referral code that a user was referred by, returns empty string if not found.
45
45
  */
46
46
  public async getReferralCodeUsed(userAddr: Address): Promise<string> {
47
- const result = await this._referral.referralCodeUsed(userAddr);
47
+ const result = await this.referral.referralCodeUsed(userAddr);
48
48
  return ethers.utils.parseBytes32String(result);
49
49
  }
50
50
 
@@ -53,7 +53,7 @@ export class ReferralRead extends BlockchainEntityRead {
53
53
  */
54
54
  public async getReferralCodeOwner(code: string): Promise<Address> {
55
55
  const referralCode = ethers.utils.formatBytes32String(code);
56
- return this._referral.referralCodeOwner(referralCode);
56
+ return this.referral.referralCodeOwner(referralCode);
57
57
  }
58
58
  }
59
59
 
@@ -65,7 +65,7 @@ export class ReferralReadWrite extends ReferralRead {
65
65
  */
66
66
  public async registerNewReferralCode(): Promise<TransactionResponse> {
67
67
  const referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
68
- return this._referral
68
+ return this.referral
69
69
  .connect(this._networkConnection.signer!)
70
70
  .registerNewUserReferralCode(referralCode);
71
71
  }
@@ -75,7 +75,7 @@ export class ReferralReadWrite extends ReferralRead {
75
75
  */
76
76
  public async useReferralCode(code: string): Promise<TransactionResponse> {
77
77
  const referralCode = ethers.utils.formatBytes32String(code);
78
- return this._referral
78
+ return this.referral
79
79
  .connect(this._networkConnection.signer!)
80
80
  .registerReferralCodeUsed(referralCode);
81
81
  }
@@ -17,7 +17,7 @@ import { fetchValuation } from '../helpers/priceFetcher';
17
17
  import { NetworkConnection, PLYWNEARPoolDetails, TokenAPY } from '../types';
18
18
 
19
19
  export class StakingRead extends BlockchainEntityRead {
20
- protected env: AuriEnv;
20
+ public readonly env: AuriEnv;
21
21
  constructor(networkConnection: NetworkConnection) {
22
22
  super(networkConnection);
23
23
  this.env = new AuriEnv(networkConnection);
@@ -1,19 +1,21 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { BigNumber as BN } from 'ethers';
3
3
  import * as consts from '../consts';
4
- import { MoneyMarketRead, PapermillRead, StakingRead } from '../contracts';
5
- import { MulticallRead } from '../contracts/Multicall';
6
4
  import { AuriEnv, BlockchainEntityRead, PLYToken, Token, TokenAmount } from '../entities';
7
5
  import { decimalFactor, isSameAddress } from '../helpers/helpers';
8
6
  import { calcValuation, fetchPrice } from '../helpers/priceFetcher';
9
7
  import * as types from '../types';
8
+ import { MoneyMarketRead } from './MoneyMarket';
9
+ import { MulticallRead } from './Multicall';
10
+ import { PapermillRead } from './Papermill';
11
+ import { StakingRead } from './Staking';
10
12
 
11
13
  export class MiscRead extends BlockchainEntityRead {
12
- protected env: AuriEnv;
13
- protected _stakingRead: StakingRead;
14
+ public readonly env: AuriEnv;
15
+ public readonly stakingRead: StakingRead;
14
16
  constructor(networkConnection: types.NetworkConnection) {
15
17
  super(networkConnection);
16
- this._stakingRead = new StakingRead(networkConnection);
18
+ this.stakingRead = new StakingRead(networkConnection);
17
19
  this.env = new AuriEnv(networkConnection);
18
20
  }
19
21
 
package/ChangeLog.md DELETED
@@ -1,159 +0,0 @@
1
- # Change Logs
2
-
3
- ## 1.6.5
4
-
5
- SDK refactor #2, remove support for loterry campaign. Package size reduced from 3MB -> 200KB
6
-
7
- ## 1.6.4
8
-
9
- Return meaningful result instead of INF in `calcLMRewardApr`
10
-
11
- ## 1.6.3
12
-
13
- Add USN supports. Hardcoded USN price to $1.
14
-
15
- ## 1.6.2
16
-
17
- - Add `ReferralRead(...).getUserReferralCode(userAddr: Address): Promise<string>`: Get the referral code for a given address, returns empty string if not found. Called to check if a user has a referral code.
18
- - Add `ReferralRead(...).getReferralCodeOwner(code: string): Promise<Address>`: Get owner of a referral code, returns zero address if not found.
19
- - Add `ReferralRead(...).getReferralCodeUsed(userAddr: Address): Promise<string>`: Get referral code that a user was referred by, returns empty string if not found.
20
- - Add `ReferralReadWrite(...).registerNewReferralCode(): Promise<TransactionResponse>`: Generate a referral code for a given address. Called when an user want to creates his own referral code
21
- - Add `ReferralReadWrite(...).useReferralCode(code: string): Promise<TransactionResponse>`: Called when an user confirms he is referred by a specified code
22
-
23
- ## 1.6.1
24
-
25
- Add `PapermillRead(...).getNextWeekTimestamp(): number`: get the start timestamp of next week of the papermill contract.
26
-
27
- Add `SdkRead(...).getPlyCirculatingSupply(): Promise<TokenAmount>`: get the ply's circulating supply
28
-
29
- ## 1.6.0
30
-
31
- SDK refactor - Why?:
32
-
33
- - more modular and less coupled.
34
- - more testable.
35
- - more maintainable.
36
-
37
- Things to do:
38
-
39
- - [x] Restructure the folder structure.
40
- - Refactor the code - Use composition pattern to SDK class
41
- - [x] Use address from contract package instead of hardcoded address.
42
-
43
- ## 1.5.8 + 1.5.9
44
-
45
- Fix gas error on claim rewards: Instead of claim all the rewards in all market in 1 txns, we will claim rewards in 2 txns.
46
-
47
- ## 1.5.7
48
-
49
- - Change return type of `SdkRead(...).LpBalanceOf` and `stakeBalanceOf` from `TokenValuation` to `TokenAmount` to match other functions in the SDK.
50
- - `totalStakedLiquidity` field in `PLYWNEARPoolDetails` is now `TokenAmount` instead of `TokenValuation`.
51
-
52
- ```ts
53
- export type PLYWNEARPoolDetails = {
54
- totalStakedLiquidity: TokenAmount;
55
- APYs: TokenAPY[];
56
- };
57
- ```
58
-
59
- ## 1.5.6
60
-
61
- Add PLYWNEAR pool to ALL_STAKING_POOLS
62
-
63
- ## 1.5.5
64
-
65
- Add auPLY market, integrate new fair launch contract
66
-
67
- Hard code PULP price to 0
68
-
69
- ## 1.5.4
70
-
71
- Use browser-friendly assert
72
-
73
- ## 1.5.2
74
-
75
- Added `SdkRead(...).unclaimedRewardsOf(userAddress: Address): Promise<TokenAmount[]>` to get unclaimed rewards of a user in LP staking.
76
-
77
- ## 1.5.1
78
-
79
- Added `PapermillRead(...).getUnlockPortionAt(userAddress: Address, timestamp: number)`
80
-
81
- ```ts
82
- export type TokenAPY = {
83
- address: string;
84
- apy: string;
85
- };
86
-
87
- export type PLYWNEARPoolDetails = {
88
- totalStakedLiquidity: TokenValuation;
89
- APYs: TokenAPY[];
90
- //apy: string; removed
91
- };
92
- ```
93
-
94
- ## 1.5.0 For staking PLYWNEAR
95
-
96
- ### Unchanged:
97
-
98
- - Stake/unstake: Use `SdkReadWrite(...).stake(amount: TokenAmount)` (or `unstake`)
99
-
100
- ### Rename:
101
-
102
- - `SdkRead(...).getPlyAuroraPoolDetails` -> `SdkRead(...).getPLYWNEARPoolDetails`
103
-
104
- ### Add
105
-
106
- - Read:
107
- - `SdkRead(...).LpBalanceOf(user: Address):TokenValuation` => amount and $ value of LP token in wallet. To get amount staked, use the old `stakeBalanceOf()` above
108
- - Type:
109
- - `TokenValuation` is a type that contains amount and $ value of token.
110
-
111
- ```ts
112
- export type TokenValuation = {
113
- tokenAmount: TokenAmount;
114
- currencyAmount: CurrencyAmount;
115
- };
116
- ```
117
-
118
- ```ts
119
- export type PLYWNEARPoolDetails = {
120
- totalStakedLiquidity: TokenValuation;
121
- apy: string;
122
- };
123
- ```
124
-
125
- ### Return type changed:
126
-
127
- - `SdkRead(...).stakeBalanceOf()` will return `TokenValuation` instead of `TokenAmount`
128
-
129
- ### Remove:
130
-
131
- - Type `PlyAuroraPoolDetails` removed.
132
-
133
- ## 1.5.0 For Papermill
134
-
135
- ### Add
136
-
137
- - Read functions:
138
-
139
- - `new PapermillRead(...).getPlyBalance(address: Address): TokenAmount` => PLY balance in user wallet
140
- - `new PapermillRead(...).getPulpBalance(address: Address): TokenAmount` => PULP balance in user wallet
141
- - `new PapermillRead(...).getLockingDetails(address: Address): UserLockingDetails`: Get locking details. This function is for convenience only, because the locking details are already available in the `UserLockingDetails` result (which you can get by calling the old `SdkRead(...).getUserDetails()`)
142
-
143
- - Write functions:
144
-
145
- - `new PapermillReadWrite(...).redeem(recipient: Address, amount: TokenAmount)` => Redeem Ply from PULP. Set `amount` to `ethers.constants.MaxUint256` for max redeem.
146
- - `new PapermillReadWrite(...).selfRedeem(amount: TokenAmount)` => Redeem Ply from PULP to msg.sender. This is just a shortcut for the redeem function above.
147
- - Collect all PLY reward from all markets + staking pool: No added functions, using the old `SdkReadWrite(...).claim()`
148
-
149
- - Type:
150
- - `UserLockingDetails` to store all user locking details
151
-
152
- ### Update
153
-
154
- - `SdkRead(...).getUserDetails()`: this will include the result from `getLockingDetails`.
155
-
156
- ### Remove
157
-
158
- - `SdkRead(...).getLockingDetails()`: Use the `getLockingDetails` in papermill instead if needed.
159
- - Remove `LockingDetails` type