@aurigami/sdk 0.3.1 → 0.3.5
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/priceFetcher.d.ts +4 -1
- package/dist/sdk.cjs.development.js +28 -31
- 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 +28 -31
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/MoneyMarket.ts +1 -1
- package/src/SDK.ts +18 -12
- package/src/dummy.ts +1 -0
- package/src/priceFetcher.ts +6 -3
- package/src/types.ts +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.5",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"typescript": "^4.5.4"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@aurigami/contracts": "^1.
|
|
60
|
+
"@aurigami/contracts": "^1.1.1",
|
|
61
61
|
"axios": "^0.24.0",
|
|
62
62
|
"bignumber.js": "^9.0.2",
|
|
63
63
|
"ethers": "^5.0.0"
|
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
|
@@ -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,7 +68,7 @@ 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
|
|
71
|
+
promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {userMarketDetail.collateralRatio = res.toNumber()}));
|
|
74
72
|
pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider));
|
|
75
73
|
}
|
|
76
74
|
|
|
@@ -82,19 +80,19 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
82
80
|
|
|
83
81
|
for (var i = 0; i < marketCount; i ++) {
|
|
84
82
|
const auToken = networkAddresses.auTokens[i];
|
|
85
|
-
if (assetsIn!.
|
|
86
|
-
isSameAddress(auToken.address, auAddress)
|
|
87
|
-
}).length > 0) {
|
|
83
|
+
if (assetsIn!.find((auAddress: Address) => isSameAddress(auToken.address, auAddress)) !== undefined) {
|
|
88
84
|
userMarketDetails[i].isCollateral = true;
|
|
85
|
+
} else {
|
|
86
|
+
userMarketDetails[i].isCollateral = false;
|
|
89
87
|
}
|
|
90
88
|
depositValuationPromises.push(fetchValuation(userMarketDetails[i].depositBalance, this._networkConnection.provider, underlyingPrices[i]));
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
var depositValues = await Promise.all(depositValuationPromises);
|
|
94
92
|
totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number)=> {
|
|
95
|
-
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(
|
|
93
|
+
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
96
94
|
return p;
|
|
97
|
-
})
|
|
95
|
+
}, new BigNumber(0))
|
|
98
96
|
|
|
99
97
|
promises = [];
|
|
100
98
|
var accountLiquidity: [BN, BN, BN], rewardBalancesMetadata, lockedAmount: BN;
|
|
@@ -105,6 +103,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
105
103
|
accountLiquidity = values[0]; rewardBalancesMetadata = values[1]; lockedAmount = values[2];
|
|
106
104
|
const borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[1].toString()).div(decimalFactor(18)));
|
|
107
105
|
const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
106
|
+
const minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
108
107
|
|
|
109
108
|
var borrowableAmount: BigNumber;
|
|
110
109
|
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
@@ -116,10 +115,17 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
116
115
|
for (var i = 0; i < marketCount; i ++) {
|
|
117
116
|
const auToken = networkAddresses.auTokens[i];
|
|
118
117
|
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
119
|
-
userMarketDetails[i].
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
const maxWithdrawCap: BigNumber = (totalBorrowLimit.minus(minimumBorrowLimitAllowed)).div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
|
|
119
|
+
userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
120
|
+
? new TokenAmount(
|
|
121
|
+
moneyMarket.underlying,
|
|
122
|
+
maxWithdrawCap.toFixed(24),
|
|
123
|
+
false
|
|
124
|
+
)
|
|
125
|
+
: new TokenAmount(
|
|
126
|
+
moneyMarket.underlying,
|
|
127
|
+
userMarketDetails[i].depositBalance.rawAmount()
|
|
128
|
+
);
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
return {
|
package/src/dummy.ts
CHANGED
package/src/priceFetcher.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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
|
|
10
|
+
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
11
11
|
|
|
12
12
|
const axios = require('axios')
|
|
13
13
|
|
|
@@ -78,8 +78,11 @@ export async function fetchPriceFromOracle(auTokenAddress: Address, underlyingDe
|
|
|
78
78
|
return processPriceFromOracle(rawPrice, underlyingDecimal)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export async function fetchUnderlyingTokensPrices(provider: providers.Provider) {
|
|
82
|
-
|
|
81
|
+
export async function fetchUnderlyingTokensPrices(provider: providers.Provider): Promise<{
|
|
82
|
+
auToken: string,
|
|
83
|
+
underlyingPrice: BigNumber
|
|
84
|
+
}[]> {
|
|
85
|
+
const auriLens: Contract = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, provider);
|
|
83
86
|
const auTokenAddresses = networkAddresses.auTokens.map((auToken) => auToken.address);
|
|
84
87
|
const underlyingDecimals = networkAddresses.auTokens.map((auToken) => getDecimal(auToken.underlying));
|
|
85
88
|
const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
|