@aurigami/sdk 0.4.2 → 0.5.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/types.d.ts CHANGED
@@ -52,6 +52,14 @@ export declare type PlyAuroraPoolDetails = {
52
52
  totalStakedLiquidity: TokenAmount;
53
53
  apy: string;
54
54
  };
55
+ export declare enum MarketAction {
56
+ Deposit = 0,
57
+ Borrow = 1,
58
+ Withdraw = 2,
59
+ Repay = 3,
60
+ EnableCollateral = 4,
61
+ DisableCollateral = 5
62
+ }
55
63
  export declare type HypotheticalStats = {
56
64
  newBorrowLimit: CurrencyAmount;
57
65
  newBorrowUtilization: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.2",
2
+ "version": "0.5.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -7,13 +7,13 @@ import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.
7
7
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
8
8
  import { AuErc20, AuETH, AuriLens, Comptroller } from "@aurigami/contracts/typechain";
9
9
  import { TransactionResponse } from '@ethersproject/abstract-provider';
10
- import { networkAddresses, ETHAddress, ONE_YEAR } from "./constants";
10
+ import { networkAddresses, ETHAddress, ONE_YEAR, INF } from "./constants";
11
11
  import BigNumber from "bignumber.js";
12
12
  import { decimalFactor, isSameAddress, calcLMRewardApr } from './helpers';
13
13
  import { Token, PLYToken } from './token';
14
14
  import { TokenAmount } from './tokenAmount';
15
15
  import { getDecimal, validateAndParseAddress } from './helpers';
16
- import { fetchPrice, fetchValuation } from "./priceFetcher";
16
+ import { fetchPrice, calcValuation } from "./priceFetcher";
17
17
 
18
18
 
19
19
  type RewardSpeeds = {
@@ -138,24 +138,22 @@ export class MoneyMarketRead extends BlockchainEntityRead {
138
138
  await Promise.all(promises);
139
139
 
140
140
  var borrowPlyApy = calcLMRewardApr(
141
- await fetchValuation(
141
+ await calcValuation(
142
142
  new TokenAmount(
143
143
  PLYToken,
144
144
  rewardSpeeds!.plyRewardBorrowSpeed.toString()
145
145
  ),
146
- this._networkConnection.provider,
147
146
  plyPrice!
148
147
  ),
149
148
  underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
150
149
  ONE_YEAR
151
150
  );
152
151
  var depositPlyApy = calcLMRewardApr(
153
- await fetchValuation(
152
+ await calcValuation(
154
153
  new TokenAmount(
155
154
  PLYToken,
156
155
  rewardSpeeds!.plyRewardSupplySpeed.toString()
157
156
  ),
158
- this._networkConnection.provider,
159
157
  plyPrice!
160
158
  ),
161
159
  underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
@@ -189,7 +187,6 @@ export class MoneyMarketRead extends BlockchainEntityRead {
189
187
  totalDeposit.toString()
190
188
  )
191
189
  }
192
-
193
190
 
194
191
  }
195
192
 
@@ -205,13 +202,22 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
205
202
  return this.auToken.connect(this._networkConnection.signer!).borrow(amount.rawAmount());
206
203
  }
207
204
  public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
205
+ if (new BigNumber(amount.rawAmount()).lt(0)) {
206
+ return this.auToken.connect(this._networkConnection.signer!).redeemUnderlying(INF);
207
+ }
208
208
  return this.auToken.connect(this._networkConnection.signer!).redeemUnderlying(amount.rawAmount());
209
209
  }
210
210
  public async repay(amount: TokenAmount): Promise<TransactionResponse> {
211
+ var repayAmount: BN;
212
+ if (new BigNumber(amount.rawAmount()).lt(0)) {
213
+ repayAmount = INF;
214
+ } else {
215
+ repayAmount = BN.from(amount.rawAmount());
216
+ }
211
217
  if (isSameAddress(amount.token.address, ETHAddress)) {
212
- return (this.auToken as AuETH).connect(this._networkConnection.signer!).repayBorrow({value: amount.rawAmount()});
218
+ return (this.auToken as AuETH).connect(this._networkConnection.signer!).repayBorrow({value: repayAmount});
213
219
  } else {
214
- return (this.auToken as AuErc20).connect(this._networkConnection.signer!).repayBorrow(amount.rawAmount());
220
+ return (this.auToken as AuErc20).connect(this._networkConnection.signer!).repayBorrow(repayAmount);
215
221
  }
216
222
  }
217
223
  public async enableCollateral(): Promise<TransactionResponse> {
package/src/SDK.ts CHANGED
@@ -7,14 +7,15 @@ import {
7
7
  UserMarketDetails,
8
8
  Address,
9
9
  CurrencyAmount,
10
- HypotheticalStats
10
+ HypotheticalStats,
11
+ MarketAction
11
12
  } from './types';
12
13
  import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
13
14
  import { TransactionResponse } from '@ethersproject/abstract-provider';
14
15
  import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
15
16
  import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
16
17
  import { MoneyMarketRead } from './MoneyMarket';
17
- import { fetchValuation, fetchPrice } from './priceFetcher';
18
+ import { fetchValuation, fetchPrice, calcValuation } from './priceFetcher';
18
19
  import { AuriFairLaunch, Comptroller, TokenLock, AuriLens } from '@aurigami/contracts/typechain';
19
20
  import { TokenAmount } from './tokenAmount';
20
21
  import { AURPLYToken, PLYToken, Token } from './token';
@@ -23,6 +24,7 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
23
24
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
24
25
  import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
25
26
  import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
27
+ import FaucetABI from "./abis/dummy.json"; //To-do
26
28
 
27
29
  export class SdkRead extends BlockchainEntityRead {
28
30
 
@@ -79,8 +81,7 @@ export class SdkRead extends BlockchainEntityRead {
79
81
 
80
82
  await Promise.all(promises);
81
83
  var underlyingPrices = await Promise.all(pricePromises);
82
- var depositValuationPromises = [];
83
-
84
+ var depositValues = []
84
85
  for (var i = 0; i < marketCount; i ++) {
85
86
  const auToken = networkAddresses.auTokens[i];
86
87
  if (assetsIn!.find((auAddress: Address) => isSameAddress(auToken.address, auAddress)) !== undefined) {
@@ -88,10 +89,9 @@ export class SdkRead extends BlockchainEntityRead {
88
89
  } else {
89
90
  userMarketDetails[i].isCollateral = false;
90
91
  }
91
- depositValuationPromises.push(fetchValuation(userMarketDetails[i].depositBalance, this._networkConnection.provider, underlyingPrices[i]));
92
+ depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
92
93
  }
93
94
 
94
- var depositValues = await Promise.all(depositValuationPromises);
95
95
  totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number)=> {
96
96
  if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
97
97
  return p;
@@ -196,15 +196,45 @@ export class SdkRead extends BlockchainEntityRead {
196
196
  )
197
197
  }
198
198
 
199
- public calcHypotheticalStats(args: {userMarketDetail: UserMarketDetails, currentBorrowLimit: CurrencyAmount, currentBorrowValuation: CurrencyAmount, isEnable: boolean}): HypotheticalStats {
200
- const deltaBorrowLimit = new BigNumber(args.userMarketDetail.depositBalance.formattedAmount()).multipliedBy(args.userMarketDetail.underlyingPrice).multipliedBy(args.userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
201
- const newBorrowLimit = args.isEnable ? new BigNumber(args.currentBorrowLimit.amount).plus(deltaBorrowLimit) : new BigNumber(args.currentBorrowLimit.amount).minus(deltaBorrowLimit);
199
+ public calcHypotheticalStats({
200
+ userMarketDetail,
201
+ currentBorrowLimit,
202
+ currentBorrowValuation,
203
+ action,
204
+ tokenAmount
205
+ }: {
206
+ userMarketDetail: UserMarketDetails,
207
+ currentBorrowLimit: CurrencyAmount,
208
+ currentBorrowValuation: CurrencyAmount,
209
+ action: MarketAction,
210
+ tokenAmount?: TokenAmount
211
+ }): HypotheticalStats {
212
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount), newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
213
+ switch (action) {
214
+ case MarketAction.EnableCollateral:
215
+ case MarketAction.DisableCollateral:
216
+ var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
217
+ newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
218
+ break;
219
+
220
+ case MarketAction.Deposit:
221
+ case MarketAction.Withdraw:
222
+ deltaBorrowLimit = calcValuation(tokenAmount!, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
223
+ newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
224
+ break;
225
+
226
+ case MarketAction.Borrow:
227
+ case MarketAction.Repay:
228
+ var deltaBorrowValuation = calcValuation(tokenAmount!, new BigNumber(userMarketDetail.underlyingPrice));
229
+ newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
230
+ break;
231
+ }
202
232
  return {
203
233
  newBorrowLimit: {
204
- amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
234
+ amount: newBorrowLimit!.toFixed(DECIMAL_PRECISION),
205
235
  currency: "USD"
206
236
  },
207
- newBorrowUtilization: new BigNumber(args.currentBorrowValuation.amount).div(newBorrowLimit).toNumber()
237
+ newBorrowUtilization: newBorrowValuation!.div(newBorrowLimit!).toNumber()
208
238
  }
209
239
  }
210
240
  }
@@ -223,6 +253,10 @@ export class SdkReadWrite extends SdkRead {
223
253
  public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
224
254
  return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(AurPlyPid, amount.rawAmount());
225
255
  }
256
+ public async faucetDrip(): Promise<TransactionResponse> {
257
+ const faucet = new Contract(networkAddresses.misc.FAUCET, FaucetABI.abi, this._networkConnection.provider);
258
+ return faucet.connect(this._networkConnection.signer!).drip();
259
+ }
226
260
  }
227
261
 
228
262
  export class SDK extends BlockchainEntity {
package/src/constants.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { ethers, Signer} from 'ethers';
2
+ import { ethers, Signer, BigNumber as BN} from 'ethers';
3
3
  export const dummyAddress: string = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
4
4
  export const ETHAddress: string = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
5
5
 
6
6
  export const AURORA_CHAINID = 1313161554;
7
7
 
8
- export const DECIMAL_PRECISION = 6;
8
+ export const DECIMAL_PRECISION = 10;
9
9
 
10
10
  export type NetworkAddresses = {
11
11
  auTokens: {
@@ -18,49 +18,37 @@ export type NetworkAddresses = {
18
18
  export const networkAddresses: NetworkAddresses = {
19
19
  auTokens: [
20
20
  {
21
- address: '0x2dEf6eb801757655AD227110d65C80DB595bBc60'.toLowerCase(),
21
+ address: '0x8bA0b797F3A965C12EF49d924d154B71d63316b5'.toLowerCase(),
22
22
  underlying: '0xb12bfca5a55806aaf64e99521918a4bf0fc40802'.toLowerCase()
23
23
  },
24
24
  {
25
- address: '0x7b47690b04494A628151Dbb86B4cC95CF2629B14'.toLowerCase(),
25
+ address: '0xA2926acb1BEdBC827000FCA08D4279aC3Bb6a443'.toLowerCase(),
26
26
  underlying: ETHAddress.toLowerCase()
27
27
  },
28
28
  {
29
- address: '0xFB0e4680B8b1c7B69fb6a3988029c74fea871DD9'.toLowerCase(),
29
+ address: '0x4176c37161E1873FA08C8301c45D4cC02293AF44'.toLowerCase(),
30
30
  underlying: '0xf4eb217ba2454613b15dbdea6e5f22276410e89e'.toLowerCase()
31
31
  },
32
32
  {
33
- address: '0x6bB82009b316A9098C23E3962b4371E879c8D23D'.toLowerCase(),
33
+ address: '0xaE1B4372e6881f69Caeb44D0793ed710bb345278'.toLowerCase(),
34
34
  underlying: '0x4988a896b1227218e4a686fde5eabdcabd91571f'.toLowerCase()
35
35
  },
36
36
  {
37
- address: '0xBf43057c634868251e65e39b4f27662f644454b4'.toLowerCase(),
37
+ address: '0x3d3b76B7E62a1f1bB08684933F63215e0582a149'.toLowerCase(),
38
38
  underlying: '0xe3520349f477a5f6eb06107066048508498a291b'.toLowerCase()
39
- },
40
- {
41
- address: '0x83Ae17f197C1F1260543d4D5A710772761535066'.toLowerCase(),
42
- underlying: '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79'.toLowerCase()
43
- },
44
- {
45
- address: '0xcC5CA0156317C1FF2A96E0f45659625081352071'.toLowerCase(),
46
- underlying: '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase(),
47
- },
48
- {
49
- address: '0x173Bf18675D52B4887C5d40E935C3ab1192aFb4C'.toLowerCase(),
50
- underlying: '0xb9b8d9e5557381BF025f1A59B602ad3F19A4e4Be'.toLowerCase()
51
39
  }
52
40
  ],
53
41
  misc: {
54
- COMPTROLLER: "0x3b416D37A85F7aD941e36258d4Da660A1898E181".toLowerCase(),
55
- oracle: "0x08A74ca75BAE803e92752f8d7A5cD718b1cA6509".toLowerCase(),
56
- AURIFAIRLAUNCH: "0xeed0433Cbc81F25061bb739Ff8f1D5736b16d038".toLowerCase(),
57
- AURILENS: '0xb11820C3d8ae1f6C31047644C59190280651C9da'.toLowerCase(),
58
- TOKENLOCK: '0x537754515509A83Ce2D076c0982292AC5289b408'.toLowerCase()
42
+ COMPTROLLER: "0x448717B7Be11C3fb7AA7f0284f28B399D0004fE1".toLowerCase(),
43
+ oracle: "0xfD47837a18ad6a72F564903a7E5162286E059224".toLowerCase(),
44
+ AURIFAIRLAUNCH: "0x986e3ac1bC3C02714C9Bfd73Cd6a206F10600b4c".toLowerCase(),
45
+ AURILENS: '0xE770e5f08251622F368Bf1a449E072627Ff6cB62'.toLowerCase(),
46
+ TOKENLOCK: '0xE130E307eF5b5c157FB233320b7ebD08f2fD320A'.toLowerCase()
59
47
  },
60
48
  tokens: {
61
- AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
62
- PLY: "0xb9b8d9e5557381BF025f1A59B602ad3F19A4e4Be".toLowerCase(),
63
- AURPLY: "0x822E871518C22E8570cFbEa43FddbBFF963d4bdE".toLowerCase()
49
+ AURORA: "0x8BEc47865aDe3B172A928df8f990Bc7f2A3b9f79".toLowerCase(),
50
+ PLY: "0x706bd3b9473126D2E7dCA097d7AAc5dB74918E6c".toLowerCase(),
51
+ AURPLY: "0x95890d73F2995E621F6A66EF9b71413926845542".toLowerCase()
64
52
  }
65
53
  }
66
54
 
@@ -73,4 +61,6 @@ export const ONE_DAY = 86400;
73
61
  export const ONE_YEAR = ONE_DAY * 365;
74
62
 
75
63
  export const AurPlyPid = 0;
64
+ export const INF = BN.from(2).pow(256).sub(1)
65
+
76
66
 
package/src/decimals.ts CHANGED
@@ -1,19 +1,15 @@
1
1
  export const decimalRecords: Record<string, number> = {
2
2
  '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
3
- '0xb9b8d9e5557381bf025f1a59b602ad3f19a4e4be': 18,
4
- '0x83ae17f197c1f1260543d4d5a710772761535066': 8,
3
+ '0x4176c37161e1873fa08c8301c45d4cc02293af44': 8,
4
+ '0x95890d73f2995e621f6a66ef9b71413926845542': 18,
5
+ '0x3d3b76b7e62a1f1bb08684933f63215e0582a149': 8,
5
6
  '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
6
- '0x4988a896b1227218e4a686fde5eabdcabd91571f': 6,
7
- '0xfb0e4680b8b1c7b69fb6a3988029c74fea871dd9': 8,
7
+ '0x8ba0b797f3a965c12ef49d924d154b71d63316b5': 8,
8
8
  '0xb12bfca5a55806aaf64e99521918a4bf0fc40802': 6,
9
- '0xbf43057c634868251e65e39b4f27662f644454b4': 8,
10
- '0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d': 24,
11
- '0x7b47690b04494a628151dbb86b4cc95cf2629b14': 8,
12
- '0x822e871518c22e8570cfbea43fddbbff963d4bde': 18,
13
- '0x2def6eb801757655ad227110d65c80db595bbc60': 8,
14
- '0x6bb82009b316a9098c23e3962b4371e879c8d23d': 8,
9
+ '0x706bd3b9473126d2e7dca097d7aac5db74918e6c': 18,
15
10
  '0x8bec47865ade3b172a928df8f990bc7f2a3b9f79': 18,
16
- '0xcc5ca0156317c1ff2a96e0f45659625081352071': 8,
17
- '0xe3520349f477a5f6eb06107066048508498a291b': 18,
18
- '0x173bf18675d52b4887c5d40e935c3ab1192afb4c': 8
19
- }
11
+ '0xae1b4372e6881f69caeb44d0793ed710bb345278': 8,
12
+ '0x4988a896b1227218e4a686fde5eabdcabd91571f': 6,
13
+ '0xa2926acb1bedbc827000fca08d4279ac3bb6a443': 8,
14
+ '0xe3520349f477a5f6eb06107066048508498a291b': 18
15
+ }
@@ -105,9 +105,11 @@ export async function fetchPrice(address: Address, provider: providers.Provider)
105
105
  return fetchPriceFromCoingecko(address);
106
106
  }
107
107
  }
108
- export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider, price?: BigNumber): Promise<BigNumber> {
109
- if (price === undefined) {
110
- price = await fetchPrice(tokenAmount.token.address, provider);
111
- }
112
- return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price!);
108
+ export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider): Promise<BigNumber> {
109
+ var price = await fetchPrice(tokenAmount.token.address, provider);
110
+ return calcValuation(tokenAmount, price);
111
+ }
112
+
113
+ export function calcValuation(tokenAmount: TokenAmount, price: BigNumber) {
114
+ return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
113
115
  }
package/src/types.ts CHANGED
@@ -62,6 +62,14 @@ export type PlyAuroraPoolDetails = {
62
62
  apy: string;
63
63
  };
64
64
 
65
+ export enum MarketAction {
66
+ Deposit = 0,
67
+ Borrow,
68
+ Withdraw,
69
+ Repay,
70
+ EnableCollateral,
71
+ DisableCollateral
72
+ }
65
73
  export type HypotheticalStats = {
66
74
  newBorrowLimit: CurrencyAmount;
67
75
  newBorrowUtilization: number;