@aurigami/sdk 0.2.2 → 0.2.3
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/MoneyMarket.d.ts +2 -0
- package/dist/constants.d.ts +1 -0
- package/dist/priceFetcher.d.ts +2 -2
- package/dist/sdk.cjs.development.js +181 -81
- 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 +182 -81
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/MoneyMarket.ts +55 -5
- package/src/constants.ts +2 -0
- package/src/priceFetcher.ts +5 -5
- package/src/types.ts +4 -0
package/src/MoneyMarket.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import { MoneyMarketDetails, NetworkConnection, Address } from './types';
|
|
3
|
-
|
|
2
|
+
import { MoneyMarketDetails, NetworkConnection, Address, ComptrollerRewardType } from './types';
|
|
4
3
|
import { Contract, BigNumber as BN } from 'ethers';
|
|
5
4
|
import AuErc20ABI from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
|
|
6
5
|
import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
|
|
@@ -13,6 +12,7 @@ import { decimalFactor, isSameAddress } from './helpers';
|
|
|
13
12
|
import { Token } from './token';
|
|
14
13
|
import { TokenAmount } from './tokenAmount';
|
|
15
14
|
import { getDecimal, validateAndParseAddress } from './helpers';
|
|
15
|
+
import { calcLMRewardApr, DECIMAL_PRECISION, fetchPrice, fetchPriceFromCoingecko, ONE_YEAR, PLYToken } from '.';
|
|
16
16
|
|
|
17
17
|
export class MoneyMarketRead extends BlockchainEntityRead {
|
|
18
18
|
public underlying: Token;
|
|
@@ -70,6 +70,40 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
70
70
|
return new BigNumber(res.collateralFactorMantissa.toString()).div(decimalFactor(18));
|
|
71
71
|
})
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
public async getBorrowPlyAPY(): Promise<BigNumber> {
|
|
75
|
+
var promises = [];
|
|
76
|
+
var totalBorrowed: TokenAmount, rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
77
|
+
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {totalBorrowed = res}));
|
|
78
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
79
|
+
rewardSpeed = new TokenAmount(
|
|
80
|
+
PLYToken,
|
|
81
|
+
res.toString()
|
|
82
|
+
)
|
|
83
|
+
}));
|
|
84
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
85
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
86
|
+
await Promise.all(promises);
|
|
87
|
+
return calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
88
|
+
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()), ONE_YEAR);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public async getDepositPlyAPY(): Promise<BigNumber> {
|
|
92
|
+
var promises = [];
|
|
93
|
+
var totalDeposited: TokenAmount, rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
94
|
+
promises.push(this.getTotalTokenDeposited().then((res: TokenAmount) => {totalDeposited = res}));
|
|
95
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
96
|
+
rewardSpeed = new TokenAmount(
|
|
97
|
+
PLYToken,
|
|
98
|
+
res.toString()
|
|
99
|
+
)
|
|
100
|
+
}));
|
|
101
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
102
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
103
|
+
await Promise.all(promises);
|
|
104
|
+
return calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
105
|
+
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()), ONE_YEAR);
|
|
106
|
+
}
|
|
73
107
|
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
74
108
|
var promises = [], totalDeposited: TokenAmount, totalBorrowed: TokenAmount, depositAPY: number, borrowAPY: number, collateralRatio: number;
|
|
75
109
|
promises.push(this.getTotalTokenDeposited().then((res: TokenAmount) => {totalDeposited = res}));
|
|
@@ -77,16 +111,32 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
77
111
|
promises.push(this.getDepositAPY().then((res: BigNumber) => {depositAPY = res.toNumber()}));
|
|
78
112
|
promises.push(this.getBorrowAPY().then((res: BigNumber) => {borrowAPY = res.toNumber()}));
|
|
79
113
|
promises.push(this.getCollateralRatio().then((res: BigNumber) => {collateralRatio = res.toNumber()}));
|
|
80
|
-
|
|
114
|
+
|
|
115
|
+
var rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
116
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
117
|
+
rewardSpeed = new TokenAmount(
|
|
118
|
+
PLYToken,
|
|
119
|
+
res.toString()
|
|
120
|
+
)
|
|
121
|
+
}));
|
|
122
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
123
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
124
|
+
|
|
81
125
|
await Promise.all(promises);
|
|
126
|
+
|
|
127
|
+
var borrowPlyApy = calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
128
|
+
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()), ONE_YEAR);
|
|
129
|
+
var depositPlyApy = calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
130
|
+
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()), ONE_YEAR);
|
|
131
|
+
|
|
82
132
|
return {
|
|
83
133
|
auTokenAddress: this.auToken.address,
|
|
84
134
|
totalTokenDeposited: totalDeposited!,
|
|
85
135
|
totalTokenBorrowed: totalBorrowed!,
|
|
86
136
|
depositApy: depositAPY!,
|
|
87
|
-
depositPlyApy:
|
|
137
|
+
depositPlyApy: depositPlyApy.toNumber(),
|
|
88
138
|
borrowApy: borrowAPY!,
|
|
89
|
-
borrowPlyApy:
|
|
139
|
+
borrowPlyApy: borrowPlyApy.toNumber(),
|
|
90
140
|
collateralRatio: collateralRatio!
|
|
91
141
|
};
|
|
92
142
|
}
|
package/src/constants.ts
CHANGED
package/src/priceFetcher.ts
CHANGED
|
@@ -11,7 +11,7 @@ import dummyABI from "./abis/dummy.json";
|
|
|
11
11
|
|
|
12
12
|
const axios = require('axios')
|
|
13
13
|
|
|
14
|
-
export async function
|
|
14
|
+
export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
|
|
15
15
|
const price = await axios.get(
|
|
16
16
|
`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`
|
|
17
17
|
).then((res: any) => {
|
|
@@ -21,11 +21,11 @@ export async function fetchPriceFromCoingecko(id: string): Promise<BigNumber> {
|
|
|
21
21
|
return new BigNumber(price[id].usd)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export async function
|
|
24
|
+
export async function fetchPriceFromCoingecko(address: Address): Promise<BigNumber> {
|
|
25
25
|
if (isSameAddress(address, networkAddresses.tokens.AURORA)) {
|
|
26
|
-
return
|
|
26
|
+
return fetchPriceFromCoingeckoAPI('aurora-near');
|
|
27
27
|
} else {
|
|
28
|
-
throw Error(`Unknown token ${address} in
|
|
28
|
+
throw Error(`Unknown token ${address} in fetchPriceFromCoingecko`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -100,7 +100,7 @@ export async function fetchPrice(address: Address, provider: providers.Provider)
|
|
|
100
100
|
} else if (isSameAddress(address, networkAddresses.misc.AUPLYLP)) {
|
|
101
101
|
return fetchLPPrice(address, provider);
|
|
102
102
|
} else {
|
|
103
|
-
return
|
|
103
|
+
return fetchPriceFromCoingecko(address);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider, price?: BigNumber): Promise<BigNumber> {
|
package/src/types.ts
CHANGED