@aurigami/sdk 0.2.2 → 0.2.6
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 +3 -0
- package/dist/priceFetcher.d.ts +2 -2
- package/dist/sdk.cjs.development.js +192 -87
- 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 +191 -87
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/package.json +4 -4
- package/src/MoneyMarket.ts +59 -7
- package/src/constants.ts +16 -0
- package/src/priceFetcher.ts +8 -7
- 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;
|
|
@@ -41,7 +41,9 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
41
41
|
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
42
42
|
var promises = [];
|
|
43
43
|
var totalBorrow: TokenAmount, totalCash: TokenAmount;
|
|
44
|
-
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
44
|
+
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
45
|
+
totalBorrow = res
|
|
46
|
+
}));
|
|
45
47
|
promises.push(this.auToken.getCash().then((res: BN) => {
|
|
46
48
|
totalCash = new TokenAmount(
|
|
47
49
|
this.underlying,
|
|
@@ -51,7 +53,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
51
53
|
await Promise.all(promises);
|
|
52
54
|
return new TokenAmount(
|
|
53
55
|
this.underlying,
|
|
54
|
-
BN.from(totalCash!.rawAmount).add(totalBorrow!.rawAmount()).toString()
|
|
56
|
+
BN.from(totalCash!.rawAmount()).add(totalBorrow!.rawAmount()).toString()
|
|
55
57
|
)
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -70,6 +72,40 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
70
72
|
return new BigNumber(res.collateralFactorMantissa.toString()).div(decimalFactor(18));
|
|
71
73
|
})
|
|
72
74
|
}
|
|
75
|
+
|
|
76
|
+
public async getBorrowPlyAPY(): Promise<BigNumber> {
|
|
77
|
+
var promises = [];
|
|
78
|
+
var totalBorrowed: TokenAmount, rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
79
|
+
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {totalBorrowed = res}));
|
|
80
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
81
|
+
rewardSpeed = new TokenAmount(
|
|
82
|
+
PLYToken,
|
|
83
|
+
res.toString()
|
|
84
|
+
)
|
|
85
|
+
}));
|
|
86
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
87
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
88
|
+
await Promise.all(promises);
|
|
89
|
+
return calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
90
|
+
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()), ONE_YEAR);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public async getDepositPlyAPY(): Promise<BigNumber> {
|
|
94
|
+
var promises = [];
|
|
95
|
+
var totalDeposited: TokenAmount, rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
96
|
+
promises.push(this.getTotalTokenDeposited().then((res: TokenAmount) => {totalDeposited = res}));
|
|
97
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
98
|
+
rewardSpeed = new TokenAmount(
|
|
99
|
+
PLYToken,
|
|
100
|
+
res.toString()
|
|
101
|
+
)
|
|
102
|
+
}));
|
|
103
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
104
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
105
|
+
await Promise.all(promises);
|
|
106
|
+
return calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
107
|
+
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()), ONE_YEAR);
|
|
108
|
+
}
|
|
73
109
|
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
74
110
|
var promises = [], totalDeposited: TokenAmount, totalBorrowed: TokenAmount, depositAPY: number, borrowAPY: number, collateralRatio: number;
|
|
75
111
|
promises.push(this.getTotalTokenDeposited().then((res: TokenAmount) => {totalDeposited = res}));
|
|
@@ -77,16 +113,32 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
77
113
|
promises.push(this.getDepositAPY().then((res: BigNumber) => {depositAPY = res.toNumber()}));
|
|
78
114
|
promises.push(this.getBorrowAPY().then((res: BigNumber) => {borrowAPY = res.toNumber()}));
|
|
79
115
|
promises.push(this.getCollateralRatio().then((res: BigNumber) => {collateralRatio = res.toNumber()}));
|
|
80
|
-
|
|
116
|
+
|
|
117
|
+
var rewardSpeed: TokenAmount, plyPrice: BigNumber, underlyingPrice: BigNumber;
|
|
118
|
+
promises.push(this._comptroller.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address).then((res) => {
|
|
119
|
+
rewardSpeed = new TokenAmount(
|
|
120
|
+
PLYToken,
|
|
121
|
+
res.toString()
|
|
122
|
+
)
|
|
123
|
+
}));
|
|
124
|
+
promises.push(fetchPrice(networkAddresses.tokens.PLY, this._networkConnection.provider).then((res) => {plyPrice = res}));
|
|
125
|
+
promises.push(fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {underlyingPrice = res}));
|
|
126
|
+
|
|
81
127
|
await Promise.all(promises);
|
|
128
|
+
|
|
129
|
+
var borrowPlyApy = calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
130
|
+
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()), ONE_YEAR);
|
|
131
|
+
var depositPlyApy = calcLMRewardApr(plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
132
|
+
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()), ONE_YEAR);
|
|
133
|
+
|
|
82
134
|
return {
|
|
83
135
|
auTokenAddress: this.auToken.address,
|
|
84
136
|
totalTokenDeposited: totalDeposited!,
|
|
85
137
|
totalTokenBorrowed: totalBorrowed!,
|
|
86
138
|
depositApy: depositAPY!,
|
|
87
|
-
depositPlyApy:
|
|
139
|
+
depositPlyApy: depositPlyApy.toNumber(),
|
|
88
140
|
borrowApy: borrowAPY!,
|
|
89
|
-
borrowPlyApy:
|
|
141
|
+
borrowPlyApy: borrowPlyApy.toNumber(),
|
|
90
142
|
collateralRatio: collateralRatio!
|
|
91
143
|
};
|
|
92
144
|
}
|
package/src/constants.ts
CHANGED
|
@@ -9,6 +9,11 @@ export const AVAX_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
|
9
9
|
AVAX_DEFAULT_PROVIDER_URL
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
+
export const AURORA_DEFAULT_PROVIDER_URL = "https://testnet.aurora.dev";
|
|
13
|
+
|
|
14
|
+
export const AURORA_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
15
|
+
AURORA_DEFAULT_PROVIDER_URL
|
|
16
|
+
);
|
|
12
17
|
export const dummyAddress: string = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
13
18
|
export const ETHAddress: string = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
14
19
|
|
|
@@ -74,6 +79,15 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
74
79
|
PLY: "0x6f8a1daa158e08f75711a64e5a3073e959d688a6",
|
|
75
80
|
AURPLY: dummyAddress
|
|
76
81
|
}
|
|
82
|
+
// auTokens: [
|
|
83
|
+
// {
|
|
84
|
+
// address: "0x0222cd9f9079140d12980ffcb39851694533436c",
|
|
85
|
+
// underlying: "0xb12bfca5a55806aaf64e99521918a4bf0fc40802"
|
|
86
|
+
// },
|
|
87
|
+
// {
|
|
88
|
+
// address:
|
|
89
|
+
// }
|
|
90
|
+
// ]
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
export const BORROW_LIMIT_BUFFER = new BigNumber(0.95);
|
|
@@ -82,5 +96,7 @@ export const REWARDCLAIMSTART = 1673280000;
|
|
|
82
96
|
|
|
83
97
|
export const ONE_DAY = 86400;
|
|
84
98
|
|
|
99
|
+
export const ONE_YEAR = ONE_DAY * 365;
|
|
100
|
+
|
|
85
101
|
export const AurPlyPid = 1;
|
|
86
102
|
|
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
|
|
|
@@ -46,8 +46,8 @@ export async function fetchLPPositions(LPAddress: Address, provider: providers.P
|
|
|
46
46
|
return {
|
|
47
47
|
token0: values[0],
|
|
48
48
|
token1: values[1],
|
|
49
|
-
reserve0: values[2].
|
|
50
|
-
reserve1: values[2].
|
|
49
|
+
reserve0: values[2].reserve0,
|
|
50
|
+
reserve1: values[2].reserve1,
|
|
51
51
|
totalSupply: values[3]
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -74,6 +74,7 @@ function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
|
|
|
74
74
|
}
|
|
75
75
|
export async function fetchPriceFromOracle(auTokenAddress: Address, underlyingDecimal: number, provider: providers.Provider): Promise<BigNumber> {
|
|
76
76
|
const oracleContract: PriceOracle = new Contract(networkAddresses.misc.oracle, OracleABI.abi, provider) as PriceOracle;
|
|
77
|
+
console.log(oracleContract.address, auTokenAddress);
|
|
77
78
|
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
|
|
78
79
|
return processPriceFromOracle(rawPrice, underlyingDecimal)
|
|
79
80
|
}
|
|
@@ -100,7 +101,7 @@ export async function fetchPrice(address: Address, provider: providers.Provider)
|
|
|
100
101
|
} else if (isSameAddress(address, networkAddresses.misc.AUPLYLP)) {
|
|
101
102
|
return fetchLPPrice(address, provider);
|
|
102
103
|
} else {
|
|
103
|
-
return
|
|
104
|
+
return fetchPriceFromCoingecko(address);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider, price?: BigNumber): Promise<BigNumber> {
|
package/src/types.ts
CHANGED