@aurigami/sdk 0.3.3 → 0.4.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/SDK.d.ts +9 -3
- package/dist/constants.d.ts +0 -6
- package/dist/priceFetcher.d.ts +4 -1
- package/dist/sdk.cjs.development.js +60 -64
- 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 +47 -46
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/package.json +2 -1
- package/src/MoneyMarket.ts +1 -1
- package/src/SDK.ts +36 -17
- package/src/constants.ts +1 -19
- package/src/dummy.ts +1 -0
- package/src/priceFetcher.ts +7 -5
- package/src/types.ts +9 -2
package/dist/types.d.ts
CHANGED
|
@@ -45,8 +45,14 @@ export declare type UserMarketDetails = {
|
|
|
45
45
|
borrowBalance: TokenAmount;
|
|
46
46
|
isCollateral: boolean;
|
|
47
47
|
maxWithdrawableAmount: TokenAmount;
|
|
48
|
+
collateralRatio: number;
|
|
49
|
+
underlyingPrice: string;
|
|
48
50
|
};
|
|
49
51
|
export declare type PlyAuroraPoolDetails = {
|
|
50
52
|
totalStakedLiquidity: TokenAmount;
|
|
51
53
|
apy: string;
|
|
52
54
|
};
|
|
55
|
+
export declare type HypotheticalStats = {
|
|
56
|
+
newBorrowLimit: CurrencyAmount;
|
|
57
|
+
newBorrowUtilization: number;
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.4.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@aurigami/contracts": "^1.1.1",
|
|
61
61
|
"axios": "^0.24.0",
|
|
62
62
|
"bignumber.js": "^9.0.2",
|
|
63
|
+
"dotenv": "^16.0.0",
|
|
63
64
|
"ethers": "^5.0.0"
|
|
64
65
|
}
|
|
65
66
|
}
|
package/src/MoneyMarket.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
32
32
|
constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
|
|
33
33
|
super(networkConnection);
|
|
34
34
|
if (isSameAddress(underlyingAsset, ETHAddress)) {
|
|
35
|
-
this.auToken = new Contract(auToken, AuETHABI.abi, networkConnection.provider) as AuETH
|
|
35
|
+
this.auToken = new Contract(auToken, AuETHABI.abi, networkConnection.provider) as AuETH;
|
|
36
36
|
} else {
|
|
37
37
|
this.auToken = new Contract(auToken, AuErc20ABI.abi, networkConnection.provider) as AuErc20;
|
|
38
38
|
}
|
package/src/SDK.ts
CHANGED
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
UserMarketDetails,
|
|
8
8
|
Address,
|
|
9
9
|
CurrencyAmount,
|
|
10
|
+
HypotheticalStats
|
|
10
11
|
} from './types';
|
|
11
|
-
import {
|
|
12
|
+
import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
|
|
12
13
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
13
14
|
import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
|
|
14
15
|
import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
|
|
@@ -22,7 +23,6 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
|
|
|
22
23
|
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
23
24
|
import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
|
|
24
25
|
import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
|
|
25
|
-
import dummyABI from "./abis/dummy.json";
|
|
26
26
|
|
|
27
27
|
export class SdkRead extends BlockchainEntityRead {
|
|
28
28
|
|
|
@@ -39,7 +39,6 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public async getLockingDetails(): Promise<LockingDetails> {
|
|
42
|
-
console.log(this._networkConnection.provider)
|
|
43
42
|
const currentTime = await getCurrentTimestamp(this._networkConnection.provider);
|
|
44
43
|
const currentWeek = BN.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
|
|
45
44
|
const denominator = 10000;
|
|
@@ -59,7 +58,6 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
59
58
|
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
60
59
|
const marketCount = networkAddresses.auTokens.length;
|
|
61
60
|
var userMarketDetails: UserMarketDetails[] = [], assetsIn: string[];
|
|
62
|
-
var collateralRatio: BigNumber[] = new Array(marketCount);
|
|
63
61
|
var promises = [];
|
|
64
62
|
var totalBorrowLimit = new BigNumber(0);
|
|
65
63
|
var pricePromises = [];
|
|
@@ -70,8 +68,11 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
70
68
|
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
71
69
|
promises.push(moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.depositBalance = res}));
|
|
72
70
|
promises.push(moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.borrowBalance = res}));
|
|
73
|
-
promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {collateralRatio
|
|
74
|
-
pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider))
|
|
71
|
+
promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {userMarketDetail.collateralRatio = res.toNumber()}));
|
|
72
|
+
pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
|
|
73
|
+
userMarketDetail.underlyingPrice = res.toString();
|
|
74
|
+
return res;
|
|
75
|
+
}));
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
|
|
@@ -82,9 +83,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
82
83
|
|
|
83
84
|
for (var i = 0; i < marketCount; i ++) {
|
|
84
85
|
const auToken = networkAddresses.auTokens[i];
|
|
85
|
-
if (assetsIn!.
|
|
86
|
-
isSameAddress(auToken.address, auAddress)
|
|
87
|
-
}).length > 0) {
|
|
86
|
+
if (assetsIn!.find((auAddress: Address) => isSameAddress(auToken.address, auAddress)) !== undefined) {
|
|
88
87
|
userMarketDetails[i].isCollateral = true;
|
|
89
88
|
} else {
|
|
90
89
|
userMarketDetails[i].isCollateral = false;
|
|
@@ -94,9 +93,9 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
94
93
|
|
|
95
94
|
var depositValues = await Promise.all(depositValuationPromises);
|
|
96
95
|
totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number)=> {
|
|
97
|
-
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(
|
|
96
|
+
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
98
97
|
return p;
|
|
99
|
-
})
|
|
98
|
+
}, new BigNumber(0))
|
|
100
99
|
|
|
101
100
|
promises = [];
|
|
102
101
|
var accountLiquidity: [BN, BN, BN], rewardBalancesMetadata, lockedAmount: BN;
|
|
@@ -107,6 +106,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
107
106
|
accountLiquidity = values[0]; rewardBalancesMetadata = values[1]; lockedAmount = values[2];
|
|
108
107
|
const borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[1].toString()).div(decimalFactor(18)));
|
|
109
108
|
const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
109
|
+
const minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
110
110
|
|
|
111
111
|
var borrowableAmount: BigNumber;
|
|
112
112
|
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
@@ -118,10 +118,17 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
118
118
|
for (var i = 0; i < marketCount; i ++) {
|
|
119
119
|
const auToken = networkAddresses.auTokens[i];
|
|
120
120
|
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
121
|
-
userMarketDetails[i].
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
const maxWithdrawCap: BigNumber = (totalBorrowLimit.minus(minimumBorrowLimitAllowed)).div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
|
|
122
|
+
userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
123
|
+
? new TokenAmount(
|
|
124
|
+
moneyMarket.underlying,
|
|
125
|
+
maxWithdrawCap.toFixed(24),
|
|
126
|
+
false
|
|
127
|
+
)
|
|
128
|
+
: new TokenAmount(
|
|
129
|
+
moneyMarket.underlying,
|
|
130
|
+
userMarketDetails[i].depositBalance.rawAmount()
|
|
131
|
+
);
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
return {
|
|
@@ -183,6 +190,18 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
183
190
|
userInfo.amount.toString()
|
|
184
191
|
)
|
|
185
192
|
}
|
|
193
|
+
|
|
194
|
+
public calcHypotheticalStats(args: {userMarketDetail: UserMarketDetails, currentBorrowLimit: CurrencyAmount, currentBorrowValuation: CurrencyAmount, isEnable: boolean}): HypotheticalStats {
|
|
195
|
+
const deltaBorrowLimit = new BigNumber(args.userMarketDetail.depositBalance.formattedAmount()).multipliedBy(args.userMarketDetail.underlyingPrice).multipliedBy(args.userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
|
|
196
|
+
const newBorrowLimit = args.isEnable ? new BigNumber(args.currentBorrowLimit.amount).plus(deltaBorrowLimit) : new BigNumber(args.currentBorrowLimit.amount).minus(deltaBorrowLimit);
|
|
197
|
+
return {
|
|
198
|
+
newBorrowLimit: {
|
|
199
|
+
amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
200
|
+
currency: "USD"
|
|
201
|
+
},
|
|
202
|
+
newBorrowUtilization: new BigNumber(args.currentBorrowValuation.amount).div(newBorrowLimit).toNumber()
|
|
203
|
+
}
|
|
204
|
+
}
|
|
186
205
|
}
|
|
187
206
|
|
|
188
207
|
export class SdkReadWrite extends SdkRead {
|
|
@@ -209,7 +228,7 @@ export class SDK extends BlockchainEntity {
|
|
|
209
228
|
return new SdkRead(networkConnection);
|
|
210
229
|
}
|
|
211
230
|
|
|
212
|
-
public
|
|
213
|
-
return new
|
|
231
|
+
public readWrite(networkConnection: NetworkConnection): SdkReadWrite {
|
|
232
|
+
return new SdkReadWrite(networkConnection);
|
|
214
233
|
}
|
|
215
234
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
|
|
3
|
-
const ethers = require('ethers');
|
|
4
|
-
import { Signer } from 'ethers';
|
|
5
|
-
export const AVAX_DEFAULT_PROVIDER_URL =
|
|
6
|
-
'https://api.avax.network/ext/bc/C/rpc';
|
|
7
|
-
|
|
8
|
-
export const AVAX_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
9
|
-
AVAX_DEFAULT_PROVIDER_URL
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export const AURORA_DEFAULT_PROVIDER_URL = "https://mainnet.aurora.dev";
|
|
13
|
-
|
|
14
|
-
export const AURORA_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
15
|
-
AURORA_DEFAULT_PROVIDER_URL
|
|
16
|
-
);
|
|
2
|
+
import { ethers, Signer} from 'ethers';
|
|
17
3
|
export const dummyAddress: string = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
18
4
|
export const ETHAddress: string = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
19
5
|
|
|
20
|
-
const dummyPrivateKey =
|
|
21
|
-
'1111111111111111111111111111111111111111111111111111111111111111';
|
|
22
|
-
export const AURORA_DEFAULT_SIGNER: Signer = new ethers.Wallet(dummyPrivateKey, AURORA_DEFAULT_PROVIDER);
|
|
23
|
-
|
|
24
6
|
export const AURORA_CHAINID = 1313161554;
|
|
25
7
|
|
|
26
8
|
export const DECIMAL_PRECISION = 6;
|
package/src/dummy.ts
CHANGED
package/src/priceFetcher.ts
CHANGED
|
@@ -7,9 +7,8 @@ import { PriceOracle } from "@aurigami/contracts/typechain";
|
|
|
7
7
|
import { TokenAmount } from "./tokenAmount";
|
|
8
8
|
import { Address } from "./types";
|
|
9
9
|
import IUniswapV2PairABI from './abis/IUniswapV2Pair.json';
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
const axios = require('axios')
|
|
10
|
+
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
11
|
+
import axios from 'axios';
|
|
13
12
|
|
|
14
13
|
export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
|
|
15
14
|
const price = await axios.get(
|
|
@@ -78,8 +77,11 @@ export async function fetchPriceFromOracle(auTokenAddress: Address, underlyingDe
|
|
|
78
77
|
return processPriceFromOracle(rawPrice, underlyingDecimal)
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
export async function fetchUnderlyingTokensPrices(provider: providers.Provider) {
|
|
82
|
-
|
|
80
|
+
export async function fetchUnderlyingTokensPrices(provider: providers.Provider): Promise<{
|
|
81
|
+
auToken: string,
|
|
82
|
+
underlyingPrice: BigNumber
|
|
83
|
+
}[]> {
|
|
84
|
+
const auriLens: Contract = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, provider);
|
|
83
85
|
const auTokenAddresses = networkAddresses.auTokens.map((auToken) => auToken.address);
|
|
84
86
|
const underlyingDecimals = networkAddresses.auTokens.map((auToken) => getDecimal(auToken.underlying));
|
|
85
87
|
const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { providers, Signer } from 'ethers';
|
|
1
|
+
import type { BigNumber, providers, Signer } from 'ethers';
|
|
2
2
|
import { TokenAmount } from './tokenAmount';
|
|
3
3
|
|
|
4
4
|
export enum ComptrollerRewardType {
|
|
@@ -53,9 +53,16 @@ export type UserMarketDetails = {
|
|
|
53
53
|
borrowBalance: TokenAmount;
|
|
54
54
|
isCollateral: boolean;
|
|
55
55
|
maxWithdrawableAmount: TokenAmount;
|
|
56
|
+
collateralRatio: number;
|
|
57
|
+
underlyingPrice: string;
|
|
56
58
|
};
|
|
57
59
|
|
|
58
60
|
export type PlyAuroraPoolDetails = {
|
|
59
61
|
totalStakedLiquidity: TokenAmount;
|
|
60
62
|
apy: string;
|
|
61
|
-
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type HypotheticalStats = {
|
|
66
|
+
newBorrowLimit: CurrencyAmount;
|
|
67
|
+
newBorrowUtilization: number;
|
|
68
|
+
}
|