@aurigami/sdk 1.0.3-fix → 1.1.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/dist/SDK.d.ts +4 -4
- package/dist/priceFetcher.d.ts +2 -1
- package/dist/sdk.cjs.development.js +128 -55
- 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 +131 -59
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
- package/src/MoneyMarket.ts +10 -2
- package/src/SDK.ts +32 -22
- package/src/constants.ts +11 -0
- package/src/priceFetcher.ts +16 -4
- package/src/types.ts +2 -0
package/dist/types.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare type MoneyMarketDetails = {
|
|
|
22
22
|
borrowApy: number;
|
|
23
23
|
borrowPlyApy: number;
|
|
24
24
|
collateralRatio: number;
|
|
25
|
+
depositPlyPerWeek: TokenAmount;
|
|
26
|
+
BorrowPlyPerWeek: TokenAmount;
|
|
25
27
|
};
|
|
26
28
|
export declare type UserDetails = {
|
|
27
29
|
markets: UserMarketDetails[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0
|
|
2
|
+
"version": "1.1.0",
|
|
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": "2.
|
|
60
|
+
"@aurigami/contracts": "2.5.0-beta",
|
|
61
61
|
"axios": "^0.24.0",
|
|
62
62
|
"bignumber.js": "^9.0.2",
|
|
63
63
|
"dotenv": "^16.0.0",
|
package/src/MoneyMarket.ts
CHANGED
|
@@ -8,7 +8,7 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
|
|
|
8
8
|
import EthRepayHelperABI from "@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json"
|
|
9
9
|
import { AuErc20, AuETH, AuriLens, Comptroller, EthRepayHelper } from "@aurigami/contracts/typechain";
|
|
10
10
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
11
|
-
import { networkAddresses, ETHAddress, ONE_YEAR, INF } from "./constants";
|
|
11
|
+
import { networkAddresses, ETHAddress, ONE_YEAR, INF, ONE_DAY } from "./constants";
|
|
12
12
|
import BigNumber from "bignumber.js";
|
|
13
13
|
import { decimalFactor, isSameAddress, calcLMRewardApr } from './helpers';
|
|
14
14
|
import { Token, PLYToken } from './token';
|
|
@@ -169,7 +169,15 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
169
169
|
depositPlyApy: depositPlyApy.toNumber(),
|
|
170
170
|
borrowApy: borrowAPY!,
|
|
171
171
|
borrowPlyApy: borrowPlyApy.toNumber(),
|
|
172
|
-
collateralRatio: collateralRatio
|
|
172
|
+
collateralRatio: collateralRatio!,
|
|
173
|
+
depositPlyPerWeek: new TokenAmount(
|
|
174
|
+
PLYToken,
|
|
175
|
+
rewardSpeeds!.plyRewardSupplySpeed.mul(ONE_DAY).mul(7).toString()
|
|
176
|
+
),
|
|
177
|
+
BorrowPlyPerWeek: new TokenAmount(
|
|
178
|
+
PLYToken,
|
|
179
|
+
rewardSpeeds!.plyRewardBorrowSpeed.mul(ONE_DAY).mul(7).toString()
|
|
180
|
+
),
|
|
173
181
|
};
|
|
174
182
|
}
|
|
175
183
|
|
package/src/SDK.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
|
|
2
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
3
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
4
|
-
import FaucetABI from "@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json";
|
|
5
|
-
import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
|
|
6
|
-
import { AuriFairLaunch, AuriLens, Comptroller, TokenLock } from '@aurigami/contracts/typechain';
|
|
7
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
8
|
-
import BigNumber from 'bignumber.js';
|
|
9
|
-
import { BigNumber as BN, Contract } from 'ethers';
|
|
10
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
11
|
-
import { AurPlyPid, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, networkAddresses, ONE_DAY, REWARDCLAIMSTART } from './constants';
|
|
12
|
-
import { calcLMRewardApr, decimalFactor, getCurrentTimestamp, isSameAddress } from './helpers';
|
|
13
|
-
import { MoneyMarketRead } from './MoneyMarket';
|
|
14
|
-
import { calcValuation, fetchPrice, fetchValuation } from './priceFetcher';
|
|
15
|
-
import { AURPLYToken, PLYToken, Token } from './token';
|
|
16
|
-
import { TokenAmount } from './tokenAmount';
|
|
17
2
|
import {
|
|
3
|
+
LockingDetails,
|
|
4
|
+
PlyAuroraPoolDetails,
|
|
5
|
+
NetworkConnection,
|
|
6
|
+
UserDetails,
|
|
7
|
+
UserMarketDetails,
|
|
18
8
|
Address,
|
|
19
9
|
CurrencyAmount,
|
|
20
|
-
HypotheticalStats,
|
|
21
|
-
|
|
10
|
+
HypotheticalStats,
|
|
11
|
+
MarketAction
|
|
22
12
|
} from './types';
|
|
13
|
+
import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
|
|
14
|
+
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
15
|
+
import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
|
|
16
|
+
import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
|
|
17
|
+
import { MoneyMarketRead } from './MoneyMarket';
|
|
18
|
+
import { fetchValuation, fetchPrice, calcValuation } from './priceFetcher';
|
|
19
|
+
import { AuriFairLaunch, Comptroller, TokenLock, AuriLens } from '@aurigami/contracts/typechain';
|
|
20
|
+
import { TokenAmount } from './tokenAmount';
|
|
21
|
+
import { AURPLYToken, PLYToken, Token } from './token';
|
|
22
|
+
import BigNumber from 'bignumber.js';
|
|
23
|
+
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
24
|
+
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
25
|
+
import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
|
|
26
|
+
import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
|
|
27
|
+
import FaucetABI from "@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json";
|
|
23
28
|
|
|
24
29
|
export class SdkRead extends BlockchainEntityRead {
|
|
25
30
|
|
|
@@ -92,9 +97,14 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
92
97
|
return p;
|
|
93
98
|
}, new BigNumber(0))
|
|
94
99
|
|
|
95
|
-
|
|
100
|
+
promises = new Array(3);
|
|
101
|
+
var accountLiquidity: [BN, BN], rewardBalancesMetadata, lockedAmount: BN;
|
|
102
|
+
promises[0] = this._comptroller.getAccountLiquidity(userAddress);
|
|
103
|
+
promises[1] = this._auriLens.callStatic.claimAndGetRewardBalancesMetadata(this._comptroller.address, this._auriFairLaunch.address, [], {from: userAddress});
|
|
104
|
+
promises[2] = this._tokenLock.lockedAmounts(userAddress);
|
|
105
|
+
var values = await Promise.all(promises);
|
|
96
106
|
|
|
97
|
-
accountLiquidity =
|
|
107
|
+
accountLiquidity = values[0]; rewardBalancesMetadata = values[1]; lockedAmount = values[2];
|
|
98
108
|
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
|
|
99
109
|
|
|
100
110
|
if (borrowedvaluation.lt("0.00001")) { // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
|
|
@@ -129,13 +139,13 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
129
139
|
}
|
|
130
140
|
|
|
131
141
|
return {
|
|
132
|
-
markets:
|
|
142
|
+
markets: userMarketDetails,
|
|
133
143
|
borrowLimit: {
|
|
134
144
|
currency: "USD",
|
|
135
145
|
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
|
|
136
146
|
},
|
|
137
|
-
accruedPly: new TokenAmount(PLYToken,
|
|
138
|
-
lockedPly: new TokenAmount(PLYToken,
|
|
147
|
+
accruedPly: new TokenAmount(PLYToken, rewardBalancesMetadata.plyAccrued.toString()),
|
|
148
|
+
lockedPly: new TokenAmount(PLYToken, lockedAmount.toString()),
|
|
139
149
|
borrowableAmount: {
|
|
140
150
|
currency: "USD",
|
|
141
151
|
amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
|
package/src/constants.ts
CHANGED
|
@@ -47,6 +47,16 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
47
47
|
name: "auWNEAR",
|
|
48
48
|
address: '0xaE4fac24dCdAE0132C6d04f564dCf059616E9423'.toLowerCase(),
|
|
49
49
|
underlying: '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase()
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "auSTNEAR",
|
|
53
|
+
address: "0x3195949f267702723bc614cAE037cdc8D1E94786".toLowerCase(),
|
|
54
|
+
underlying: '0x07f9f7f963c5cd2bbffd30ccfb964be114332e30'.toLowerCase()
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "auAURORA",
|
|
58
|
+
address: "0x8888682E24dd4Df7B7Ff2B91fccB575737E433bf".toLowerCase(),
|
|
59
|
+
underlying: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
|
|
50
60
|
}
|
|
51
61
|
],
|
|
52
62
|
misc: {
|
|
@@ -60,6 +70,7 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
60
70
|
tokens: {
|
|
61
71
|
AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
|
|
62
72
|
PLY: "0x981bD5832EAB9C8F607940E0e9faCBf8C09ee20a".toLowerCase(),
|
|
73
|
+
stNEAR: "0x07f9f7f963c5cd2bbffd30ccfb964be114332e30".toLowerCase(),
|
|
63
74
|
AURPLY: dummyAddress.toLowerCase() // This is dummy
|
|
64
75
|
}
|
|
65
76
|
}
|
package/src/priceFetcher.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import { Contract, providers, BigNumber as BN } from "ethers";
|
|
2
|
+
import { Contract, providers, BigNumber as BN, ethers } from "ethers";
|
|
3
3
|
import { networkAddresses } from "./constants";
|
|
4
4
|
import OracleABI from "./abis/Oracle.json";
|
|
5
5
|
import { isSameAddress, decimalFactor, getDecimal } from "./helpers";
|
|
@@ -21,11 +21,11 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
|
|
|
21
21
|
return new BigNumber(price[id].usd)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export async function fetchPriceFromCoingecko(
|
|
25
|
-
if (isSameAddress(
|
|
24
|
+
export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
|
|
25
|
+
if (isSameAddress(id, networkAddresses.tokens.AURORA)) {
|
|
26
26
|
return fetchPriceFromCoingeckoAPI('aurora-near');
|
|
27
27
|
} else {
|
|
28
|
-
throw Error(`Unknown token ${
|
|
28
|
+
throw Error(`Unknown token ${id} in fetchPriceFromCoingecko`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -94,8 +94,20 @@ export async function fetchUnderlyingTokensPrices(provider: providers.Provider):
|
|
|
94
94
|
})
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
export async function fetchStNEARPrice(): Promise<BigNumber> {
|
|
98
|
+
const ratioPromise = axios.get("https://validators.narwallets.com/metrics_json").then((res) => res.data);
|
|
99
|
+
const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
|
|
100
|
+
const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([ratioPromise, nearPricePromise]);
|
|
101
|
+
const ratio = new BigNumber(ratioRes.st_near_price);
|
|
102
|
+
return ratio.multipliedBy(nearPrice)
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
export async function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
|
|
98
106
|
if (hardcodePLYPrice && isSameAddress(address, networkAddresses.tokens.PLY)) return new BigNumber(0);
|
|
107
|
+
|
|
108
|
+
if (isSameAddress(address, networkAddresses.tokens.stNEAR)) return fetchStNEARPrice();
|
|
109
|
+
if (isSameAddress(address, networkAddresses.tokens.AURORA)) return fetchPriceFromCoingecko(address);
|
|
110
|
+
|
|
99
111
|
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
100
112
|
return isSameAddress(auToken.underlying, address)
|
|
101
113
|
});
|