@aurigami/sdk 0.2.1 → 0.2.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/MoneyMarket.d.ts +2 -0
- package/dist/constants.d.ts +1 -0
- package/dist/priceFetcher.d.ts +4 -3
- package/dist/sdk.cjs.development.js +254 -109
- 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 +254 -109
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/package.json +4 -4
- package/src/MoneyMarket.ts +55 -5
- package/src/constants.ts +12 -1
- package/src/priceFetcher.ts +28 -9
- 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
|
@@ -67,13 +67,22 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
67
67
|
COMPTROLLER: "0xb51028d4f3fc69e3f9e3118ce067a4562c595aad",
|
|
68
68
|
oracle: "0xf1ebfaa2af93f4d82215fd7817c1835853c62fb8",
|
|
69
69
|
AURIFAIRLAUNCH: "0x7942874a9ef8059c5de259625a883dc61f03320d",
|
|
70
|
-
AURILENS:
|
|
70
|
+
AURILENS: '0xa2635a23a7688cd3acdd07713c4943b2f0f9082c'
|
|
71
71
|
},
|
|
72
72
|
tokens: {
|
|
73
73
|
AURORA: "0x7a80df8230c5aa711e2702a275ab31aeb32754bf",
|
|
74
74
|
PLY: "0x6f8a1daa158e08f75711a64e5a3073e959d688a6",
|
|
75
75
|
AURPLY: dummyAddress
|
|
76
76
|
}
|
|
77
|
+
// auTokens: [
|
|
78
|
+
// {
|
|
79
|
+
// address: "0x0222cd9f9079140d12980ffcb39851694533436c",
|
|
80
|
+
// underlying: "0xb12bfca5a55806aaf64e99521918a4bf0fc40802"
|
|
81
|
+
// },
|
|
82
|
+
// {
|
|
83
|
+
// address:
|
|
84
|
+
// }
|
|
85
|
+
// ]
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
export const BORROW_LIMIT_BUFFER = new BigNumber(0.95);
|
|
@@ -82,5 +91,7 @@ export const REWARDCLAIMSTART = 1673280000;
|
|
|
82
91
|
|
|
83
92
|
export const ONE_DAY = 86400;
|
|
84
93
|
|
|
94
|
+
export const ONE_YEAR = ONE_DAY * 365;
|
|
95
|
+
|
|
85
96
|
export const AurPlyPid = 1;
|
|
86
97
|
|
package/src/priceFetcher.ts
CHANGED
|
@@ -7,9 +7,11 @@ 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 dummyABI from "./abis/dummy.json";
|
|
11
|
+
|
|
10
12
|
const axios = require('axios')
|
|
11
13
|
|
|
12
|
-
export async function
|
|
14
|
+
export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
|
|
13
15
|
const price = await axios.get(
|
|
14
16
|
`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`
|
|
15
17
|
).then((res: any) => {
|
|
@@ -19,11 +21,11 @@ export async function fetchPriceFromCoingecko(id: string): Promise<BigNumber> {
|
|
|
19
21
|
return new BigNumber(price[id].usd)
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
export async function
|
|
24
|
+
export async function fetchPriceFromCoingecko(address: Address): Promise<BigNumber> {
|
|
23
25
|
if (isSameAddress(address, networkAddresses.tokens.AURORA)) {
|
|
24
|
-
return
|
|
26
|
+
return fetchPriceFromCoingeckoAPI('aurora-near');
|
|
25
27
|
} else {
|
|
26
|
-
throw Error(`Unknown token ${address} in
|
|
28
|
+
throw Error(`Unknown token ${address} in fetchPriceFromCoingecko`);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -44,8 +46,8 @@ export async function fetchLPPositions(LPAddress: Address, provider: providers.P
|
|
|
44
46
|
return {
|
|
45
47
|
token0: values[0],
|
|
46
48
|
token1: values[1],
|
|
47
|
-
reserve0: values[2].
|
|
48
|
-
reserve1: values[2].
|
|
49
|
+
reserve0: values[2].reserve0,
|
|
50
|
+
reserve1: values[2].reserve1,
|
|
49
51
|
totalSupply: values[3]
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -66,10 +68,27 @@ export async function fetchLPPrice(address: Address, provider: providers.Provide
|
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
|
|
72
|
+
function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
|
|
73
|
+
return new BigNumber(rawPrice.toString()).div(decimalFactor(36 - underlyingDecimal));
|
|
74
|
+
}
|
|
75
|
+
export async function fetchPriceFromOracle(auTokenAddress: Address, underlyingDecimal: number, provider: providers.Provider): Promise<BigNumber> {
|
|
70
76
|
const oracleContract: PriceOracle = new Contract(networkAddresses.misc.oracle, OracleABI.abi, provider) as PriceOracle;
|
|
71
77
|
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
|
|
72
|
-
return
|
|
78
|
+
return processPriceFromOracle(rawPrice, underlyingDecimal)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function fetchUnderlyingTokensPrices(provider: providers.Provider) {
|
|
82
|
+
const auriLens: Contract = new Contract(networkAddresses.misc.AURILENS, dummyABI.abi, provider);
|
|
83
|
+
const auTokenAddresses = networkAddresses.auTokens.map((auToken) => auToken.address);
|
|
84
|
+
const underlyingDecimals = networkAddresses.auTokens.map((auToken) => getDecimal(auToken.underlying));
|
|
85
|
+
const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
|
|
86
|
+
return rawPrices.map((res: any, ind: number) => {
|
|
87
|
+
return {
|
|
88
|
+
auToken: res.auToken,
|
|
89
|
+
underlyingPrice: processPriceFromOracle(res.underlyingPrice, underlyingDecimals[ind])
|
|
90
|
+
}
|
|
91
|
+
})
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
export async function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
|
|
@@ -81,7 +100,7 @@ export async function fetchPrice(address: Address, provider: providers.Provider)
|
|
|
81
100
|
} else if (isSameAddress(address, networkAddresses.misc.AUPLYLP)) {
|
|
82
101
|
return fetchLPPrice(address, provider);
|
|
83
102
|
} else {
|
|
84
|
-
return
|
|
103
|
+
return fetchPriceFromCoingecko(address);
|
|
85
104
|
}
|
|
86
105
|
}
|
|
87
106
|
export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider, price?: BigNumber): Promise<BigNumber> {
|
package/src/types.ts
CHANGED