@aurigami/sdk 0.1.5 → 0.2.2
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/BlockchainEntity.d.ts +6 -7
- package/dist/MoneyMarket.d.ts +19 -8
- package/dist/SDK.d.ts +11 -6
- package/dist/constants.d.ts +18 -2
- package/dist/decimals.d.ts +1 -0
- package/dist/helpers.d.ts +9 -2
- package/dist/index.d.ts +4 -1
- package/dist/priceFetcher.d.ts +18 -0
- package/dist/sdk.cjs.development.js +1506 -1259
- 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 +1483 -1259
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +3 -2
- package/dist/types.d.ts +19 -11
- package/package.json +9 -6
- package/src/BlockchainEntity.ts +13 -10
- package/src/MoneyMarket.ts +121 -37
- package/src/SDK.ts +158 -68
- package/src/abis/IUniswapV2Pair.json +663 -0
- package/src/abis/Oracle.json +247 -0
- package/src/abis/dummy.json +3 -0
- package/src/constants.ts +73 -5
- package/src/decimals.ts +18 -0
- package/src/helpers.ts +30 -8
- package/src/index.ts +4 -4
- package/src/priceFetcher.ts +108 -0
- package/src/token.ts +16 -6
- package/src/types.ts +22 -12
- package/src/abis/IERC20.json +0 -1259
- package/src/abis/auToken.json +0 -1536
package/src/MoneyMarket.ts
CHANGED
|
@@ -1,70 +1,154 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
2
|
+
import { MoneyMarketDetails, NetworkConnection, Address } from './types';
|
|
3
|
+
|
|
4
|
+
import { Contract, BigNumber as BN } from 'ethers';
|
|
5
|
+
import AuErc20ABI from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
|
|
6
|
+
import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
|
|
7
|
+
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
8
|
+
import { AuErc20, AuETH, Comptroller } from "@aurigami/contracts/typechain";
|
|
6
9
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
7
|
-
import {
|
|
10
|
+
import { networkAddresses, ETHAddress } from "./constants";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
12
|
+
import { decimalFactor, isSameAddress } from './helpers';
|
|
13
|
+
import { Token } from './token';
|
|
8
14
|
import { TokenAmount } from './tokenAmount';
|
|
9
|
-
import { validateAndParseAddress } from './helpers';
|
|
15
|
+
import { getDecimal, validateAndParseAddress } from './helpers';
|
|
10
16
|
|
|
11
17
|
export class MoneyMarketRead extends BlockchainEntityRead {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
public underlying: Token;
|
|
19
|
+
public auToken: AuErc20 | AuETH;
|
|
20
|
+
protected _comptroller: Comptroller;
|
|
21
|
+
constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
|
|
22
|
+
super(networkConnection);
|
|
23
|
+
if (isSameAddress(underlyingAsset, ETHAddress)) {
|
|
24
|
+
this.auToken = new Contract(auToken, AuETHABI.abi, networkConnection.provider) as AuETH
|
|
25
|
+
} else {
|
|
26
|
+
this.auToken = new Contract(auToken, AuErc20ABI.abi, networkConnection.provider) as AuErc20;
|
|
27
|
+
}
|
|
28
|
+
this.underlying = new Token(
|
|
29
|
+
underlyingAsset,
|
|
30
|
+
getDecimal(underlyingAsset),
|
|
31
|
+
);
|
|
32
|
+
this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async getTotalTokenBorrowed(): Promise<TokenAmount> {
|
|
36
|
+
return new TokenAmount(
|
|
37
|
+
this.underlying,
|
|
38
|
+
(await this.auToken.totalBorrows()).toString()
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
42
|
+
var promises = [];
|
|
43
|
+
var totalBorrow: TokenAmount, totalCash: TokenAmount;
|
|
44
|
+
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {totalBorrow = res}));
|
|
45
|
+
promises.push(this.auToken.getCash().then((res: BN) => {
|
|
46
|
+
totalCash = new TokenAmount(
|
|
47
|
+
this.underlying,
|
|
48
|
+
res.toString()
|
|
49
|
+
)
|
|
50
|
+
}))
|
|
51
|
+
await Promise.all(promises);
|
|
52
|
+
return new TokenAmount(
|
|
53
|
+
this.underlying,
|
|
54
|
+
BN.from(totalCash!.rawAmount).add(totalBorrow!.rawAmount()).toString()
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async getDepositAPY(): Promise<BigNumber> {
|
|
59
|
+
const supplyRatePerTimestamp = await this.auToken.supplyRatePerTimestamp();
|
|
60
|
+
return new BigNumber(supplyRatePerTimestamp.toString()).multipliedBy(60*60*24*365).div(decimalFactor(18));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async getBorrowAPY(): Promise<BigNumber> {
|
|
64
|
+
const borrowRatePerTimestamp = await this.auToken.borrowRatePerTimestamp();
|
|
65
|
+
return new BigNumber(borrowRatePerTimestamp.toString()).multipliedBy(60*60*24*365).div(decimalFactor(18));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public async getCollateralRatio(): Promise<BigNumber> {
|
|
69
|
+
return this._comptroller.markets(this.auToken.address).then((res: any) => {
|
|
70
|
+
return new BigNumber(res.collateralFactorMantissa.toString()).div(decimalFactor(18));
|
|
71
|
+
})
|
|
16
72
|
}
|
|
17
73
|
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
74
|
+
var promises = [], totalDeposited: TokenAmount, totalBorrowed: TokenAmount, depositAPY: number, borrowAPY: number, collateralRatio: number;
|
|
75
|
+
promises.push(this.getTotalTokenDeposited().then((res: TokenAmount) => {totalDeposited = res}));
|
|
76
|
+
promises.push(this.getTotalTokenBorrowed().then((res: TokenAmount) => {totalBorrowed = res}));
|
|
77
|
+
promises.push(this.getDepositAPY().then((res: BigNumber) => {depositAPY = res.toNumber()}));
|
|
78
|
+
promises.push(this.getBorrowAPY().then((res: BigNumber) => {borrowAPY = res.toNumber()}));
|
|
79
|
+
promises.push(this.getCollateralRatio().then((res: BigNumber) => {collateralRatio = res.toNumber()}));
|
|
80
|
+
|
|
81
|
+
await Promise.all(promises);
|
|
18
82
|
return {
|
|
19
|
-
auTokenAddress:
|
|
20
|
-
totalTokenDeposited:
|
|
21
|
-
totalTokenBorrowed:
|
|
22
|
-
depositApy:
|
|
23
|
-
depositPlyApy: 0.
|
|
24
|
-
borrowApy:
|
|
25
|
-
borrowPlyApy: 0.18,
|
|
26
|
-
collateralRatio:
|
|
83
|
+
auTokenAddress: this.auToken.address,
|
|
84
|
+
totalTokenDeposited: totalDeposited!,
|
|
85
|
+
totalTokenBorrowed: totalBorrowed!,
|
|
86
|
+
depositApy: depositAPY!,
|
|
87
|
+
depositPlyApy: 0.18, //To-do
|
|
88
|
+
borrowApy: borrowAPY!,
|
|
89
|
+
borrowPlyApy: 0.18, // To-d0
|
|
90
|
+
collateralRatio: collateralRatio!
|
|
27
91
|
};
|
|
28
92
|
}
|
|
93
|
+
|
|
94
|
+
public async getUserBorrowBalance(userAddress: string): Promise<TokenAmount> {
|
|
95
|
+
const totalBorrow: BN = await this.auToken.callStatic.borrowBalanceCurrent(userAddress);
|
|
96
|
+
return new TokenAmount(
|
|
97
|
+
this.underlying,
|
|
98
|
+
totalBorrow.toString()
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async getUserDepositBalance(userAddress: string): Promise<TokenAmount> {
|
|
103
|
+
const totalDeposit: BN = await this.auToken.callStatic.balanceOfUnderlying(userAddress);
|
|
104
|
+
return new TokenAmount(
|
|
105
|
+
this.underlying,
|
|
106
|
+
totalDeposit.toString()
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
29
111
|
}
|
|
30
112
|
|
|
31
113
|
export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
32
|
-
dummyTransaction = async (): Promise<TransactionResponse> => {
|
|
33
|
-
// const dummyErc20Token = new Contract(
|
|
34
|
-
// dummyToken.address,
|
|
35
|
-
// IERC20.abi,
|
|
36
|
-
// this._providerOrSigner
|
|
37
|
-
// );
|
|
38
|
-
// return await dummyErc20Token.approve(dummyToken.address, 123);
|
|
39
|
-
return {} as TransactionResponse;
|
|
40
|
-
};
|
|
41
114
|
public async deposit(amount: TokenAmount): Promise<TransactionResponse> {
|
|
42
|
-
|
|
115
|
+
if (isSameAddress(amount.token.address, ETHAddress)) {
|
|
116
|
+
return (this.auToken as AuETH).connect(this._networkConnection.signer!).mint({value: amount.rawAmount()});
|
|
117
|
+
} else {
|
|
118
|
+
return (this.auToken as AuErc20).connect(this._networkConnection.signer!).mint(amount.rawAmount());
|
|
119
|
+
}
|
|
43
120
|
}
|
|
44
121
|
public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
|
|
45
|
-
return this.
|
|
122
|
+
return this.auToken.connect(this._networkConnection.signer!).borrow(amount.rawAmount());
|
|
46
123
|
}
|
|
47
124
|
public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
|
|
48
|
-
return this.
|
|
125
|
+
return this.auToken.connect(this._networkConnection.signer!).redeemUnderlying(amount.rawAmount());
|
|
49
126
|
}
|
|
50
127
|
public async repay(amount: TokenAmount): Promise<TransactionResponse> {
|
|
51
|
-
|
|
128
|
+
if (isSameAddress(amount.token.address, ETHAddress)) {
|
|
129
|
+
return (this.auToken as AuETH).connect(this._networkConnection.signer!).repayBorrow({value: amount.rawAmount()});
|
|
130
|
+
} else {
|
|
131
|
+
return (this.auToken as AuErc20).connect(this._networkConnection.signer!).repayBorrow(amount.rawAmount());
|
|
132
|
+
}
|
|
52
133
|
}
|
|
53
134
|
public async enableCollateral(): Promise<TransactionResponse> {
|
|
54
|
-
return this.
|
|
135
|
+
return this._comptroller.connect(this._networkConnection.signer!).enterMarkets([this.auToken.address]);
|
|
55
136
|
}
|
|
56
137
|
public async disableCollateral(): Promise<TransactionResponse> {
|
|
57
|
-
return this.
|
|
138
|
+
return this._comptroller.connect(this._networkConnection.signer!).exitMarket(this.auToken.address);
|
|
58
139
|
}
|
|
59
140
|
}
|
|
60
141
|
|
|
61
142
|
export class MoneyMarket extends BlockchainEntity {
|
|
62
|
-
protected address:
|
|
63
|
-
|
|
143
|
+
protected address: Address;
|
|
144
|
+
|
|
145
|
+
protected underlying: Address;
|
|
146
|
+
constructor(address: string, underlying: string) {
|
|
64
147
|
super();
|
|
65
148
|
this.address = validateAndParseAddress(address);
|
|
149
|
+
this.underlying = validateAndParseAddress(underlying);
|
|
66
150
|
}
|
|
67
|
-
public read(
|
|
68
|
-
return new MoneyMarketRead(
|
|
151
|
+
public read(networkConnection: NetworkConnection): MoneyMarketRead {
|
|
152
|
+
return new MoneyMarketRead(networkConnection, this.address, this.underlying);
|
|
69
153
|
}
|
|
70
154
|
}
|
package/src/SDK.ts
CHANGED
|
@@ -1,110 +1,200 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import {
|
|
3
|
-
dummyPly,
|
|
4
|
-
dummyPlyAurora,
|
|
5
|
-
dummyToken,
|
|
6
|
-
dummyTokenAmount2,
|
|
7
|
-
dummyTokenAmount3,
|
|
8
|
-
dummyUserMarketDetails,
|
|
9
|
-
} from './dummy';
|
|
10
2
|
import {
|
|
11
3
|
LockingDetails,
|
|
12
4
|
PlyAuroraPoolDetails,
|
|
13
|
-
|
|
5
|
+
NetworkConnection,
|
|
14
6
|
UserDetails,
|
|
7
|
+
UserMarketDetails,
|
|
8
|
+
Address,
|
|
9
|
+
CurrencyAmount,
|
|
15
10
|
} from './types';
|
|
16
|
-
import { AVAX_DEFAULT_PROVIDER_URL,
|
|
11
|
+
import { AVAX_DEFAULT_PROVIDER_URL, networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
|
|
17
12
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
|
|
14
|
+
import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
|
|
15
|
+
import { MoneyMarketRead } from './MoneyMarket';
|
|
16
|
+
import { fetchValuation, fetchPrice } from './priceFetcher';
|
|
17
|
+
import { AuriFairLaunch, Comptroller, TokenLock } from '@aurigami/contracts/typechain';
|
|
20
18
|
import { TokenAmount } from './tokenAmount';
|
|
21
|
-
import { Token } from './token';
|
|
22
|
-
|
|
19
|
+
import { AURPLYToken, PLYToken, Token } from './token';
|
|
20
|
+
import BigNumber from 'bignumber.js';
|
|
21
|
+
import IERC20 from '@aurigami/contracts/artifacts/contracts/EIP20Interface.sol/EIP20Interface.json';
|
|
22
|
+
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
23
|
+
import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
|
|
24
|
+
import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
|
|
25
|
+
import dummyABI from "./abis/dummy.json";
|
|
23
26
|
|
|
24
27
|
export class SdkRead extends BlockchainEntityRead {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
protected _comptroller: Comptroller;
|
|
30
|
+
protected _tokenLock: TokenLock;
|
|
31
|
+
protected _auriFairLaunch: AuriFairLaunch;
|
|
32
|
+
protected _auriLens: Contract; // To-do
|
|
33
|
+
constructor(networkConnection: NetworkConnection) {
|
|
34
|
+
super(networkConnection);
|
|
35
|
+
this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
|
|
36
|
+
this._tokenLock = new Contract(networkAddresses.misc.TOKENLOCK, TokenLockABI.abi, networkConnection.provider) as TokenLock;
|
|
37
|
+
this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
|
|
38
|
+
this._auriLens = new Contract(networkAddresses.misc.AURILENS, dummyABI.abi, networkConnection.provider); //To-do
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
public async getLockingDetails(): Promise<LockingDetails> {
|
|
42
|
+
const currentTime = await getCurrentTimestamp(this._networkConnection.provider);
|
|
43
|
+
const currentWeek = BN.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
|
|
44
|
+
const denominator = 10000;
|
|
45
|
+
var promises = [];
|
|
46
|
+
promises.push(this._tokenLock.percentageLock(currentWeek));
|
|
47
|
+
promises.push(this._tokenLock.percentageLock(currentWeek + 1).catch((err: any) => {return denominator}));
|
|
48
|
+
var values: string[] = await Promise.all(promises).then((res) => {
|
|
49
|
+
return res.map((v) => {return v.toString()})
|
|
50
|
+
});
|
|
30
51
|
return {
|
|
31
|
-
vestingStart:
|
|
32
|
-
currentUnlockPortion: 0.
|
|
33
|
-
nextUnlockPortion:
|
|
52
|
+
vestingStart: REWARDCLAIMSTART, // 10 Jan 2023
|
|
53
|
+
currentUnlockPortion: new BigNumber(values[0]).div(denominator).toNumber(),
|
|
54
|
+
nextUnlockPortion: new BigNumber(values[1]).div(denominator).toNumber(),
|
|
34
55
|
};
|
|
35
56
|
}
|
|
36
57
|
|
|
37
58
|
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
59
|
+
const marketCount = networkAddresses.auTokens.length;
|
|
60
|
+
var userMarketDetails: UserMarketDetails[] = [], assetsIn: string[];
|
|
61
|
+
var collateralRatio: BigNumber[];
|
|
62
|
+
var promises = [];
|
|
63
|
+
var totalBorrowLimit = new BigNumber(0);
|
|
64
|
+
var pricePromises = [];
|
|
65
|
+
for (const auToken of networkAddresses.auTokens) {
|
|
66
|
+
const userMarketDetail: UserMarketDetails = {} as UserMarketDetails;
|
|
67
|
+
userMarketDetails.push(userMarketDetail);
|
|
68
|
+
userMarketDetail.market = auToken.underlying;
|
|
69
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
70
|
+
promises.push(moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.depositBalance = res}));
|
|
71
|
+
promises.push(moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {userMarketDetail.borrowBalance = res}));
|
|
72
|
+
promises.push(moneyMarket.getCollateralRatio().then((res: BigNumber) => {collateralRatio[i] = res}));
|
|
73
|
+
pricePromises.push(fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
|
|
77
|
+
|
|
78
|
+
await Promise.all(promises);
|
|
79
|
+
var underlyingPrices = await Promise.all(pricePromises);
|
|
80
|
+
var depositValuationPromises = [];
|
|
81
|
+
|
|
82
|
+
for (var i = 0; i < marketCount; i ++) {
|
|
83
|
+
const auToken = networkAddresses.auTokens[i];
|
|
84
|
+
if (assetsIn!.filter((auAddress: Address) => {
|
|
85
|
+
isSameAddress(auToken.address, auAddress)
|
|
86
|
+
}).length > 0) {
|
|
87
|
+
userMarketDetails[i].isCollateral = true;
|
|
88
|
+
}
|
|
89
|
+
depositValuationPromises.push(fetchValuation(userMarketDetails[i].depositBalance, this._networkConnection.provider, underlyingPrices[i]));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var depositValues = await Promise.all(depositValuationPromises);
|
|
93
|
+
totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number)=> {
|
|
94
|
+
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(collateralRatio[index]));
|
|
95
|
+
return p;
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
promises = [];
|
|
99
|
+
var accountLiquidity: [BN, BN, BN], rewardBalancesMetadata, lockedAmount: BN;
|
|
100
|
+
promises.push(this._comptroller.getAccountLiquidity(userAddress));
|
|
101
|
+
promises.push(this._auriLens.getRewardBalancesMetadata(this._comptroller.address, userAddress));
|
|
102
|
+
promises.push(this._tokenLock.lockedAmounts(userAddress));
|
|
103
|
+
var values = await Promise.all(promises);
|
|
104
|
+
accountLiquidity = values[0]; rewardBalancesMetadata = values[1]; lockedAmount = values[2];
|
|
105
|
+
const borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[1].toString()).div(decimalFactor(18)));
|
|
106
|
+
const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
107
|
+
|
|
108
|
+
var borrowableAmount: BigNumber;
|
|
109
|
+
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
110
|
+
borrowableAmount = new BigNumber(0)
|
|
111
|
+
} else {
|
|
112
|
+
borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for (var i = 0; i < marketCount; i ++) {
|
|
116
|
+
const auToken = networkAddresses.auTokens[i];
|
|
117
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
118
|
+
userMarketDetails[i].maxWithdrawableAmount = new TokenAmount(
|
|
119
|
+
moneyMarket.underlying,
|
|
120
|
+
borrowableAmount.div(underlyingPrices[i]).toFixed(18)
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
38
124
|
return {
|
|
39
|
-
markets:
|
|
40
|
-
borrowLimit:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
),
|
|
51
|
-
borrowableAmount: dummyTokenAmount2,
|
|
125
|
+
markets: userMarketDetails,
|
|
126
|
+
borrowLimit: {
|
|
127
|
+
currency: "USD",
|
|
128
|
+
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
|
|
129
|
+
},
|
|
130
|
+
accruedPly: new TokenAmount(PLYToken, rewardBalancesMetadata.plyAccrued.toString()),
|
|
131
|
+
lockedPly: new TokenAmount(PLYToken, lockedAmount.toString()),
|
|
132
|
+
borrowableAmount: {
|
|
133
|
+
currency: "USD",
|
|
134
|
+
amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
|
|
135
|
+
},
|
|
52
136
|
};
|
|
53
137
|
}
|
|
54
138
|
|
|
55
139
|
public async getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails> {
|
|
140
|
+
var stakedLiquidity: BN, rewardPerSecond: BN;
|
|
141
|
+
var promises = [];
|
|
142
|
+
promises.push(this._auriFairLaunch.getPoolInfo(AurPlyPid).then((res) => {
|
|
143
|
+
stakedLiquidity = res.totalStake;
|
|
144
|
+
rewardPerSecond = res.rewardPerSecond;
|
|
145
|
+
}));
|
|
146
|
+
await Promise.all(promises);
|
|
147
|
+
|
|
148
|
+
promises = [];
|
|
149
|
+
var rewardPerSecondValuation: BigNumber, totalStakeValuation: BigNumber;
|
|
150
|
+
promises.push(fetchValuation(new TokenAmount(
|
|
151
|
+
PLYToken,
|
|
152
|
+
rewardPerSecond!.toString()
|
|
153
|
+
), this._networkConnection.provider).then((res) => rewardPerSecondValuation = res));
|
|
154
|
+
promises.push(fetchValuation(new TokenAmount(
|
|
155
|
+
AURPLYToken,
|
|
156
|
+
stakedLiquidity!.toString()
|
|
157
|
+
), this._networkConnection.provider).then((res) => totalStakeValuation = res));
|
|
158
|
+
|
|
56
159
|
return {
|
|
57
160
|
totalStakedLiquidity: new TokenAmount(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
false,
|
|
161
|
+
AURPLYToken,
|
|
162
|
+
stakedLiquidity!.toString()
|
|
61
163
|
),
|
|
62
|
-
apy:
|
|
164
|
+
apy: calcLMRewardApr(rewardPerSecondValuation!, totalStakeValuation!, ONE_DAY * 365).toFixed(DECIMAL_PRECISION),
|
|
63
165
|
};
|
|
64
166
|
}
|
|
65
167
|
|
|
66
|
-
public async getTokenPrice(token: Token): Promise<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
false,
|
|
72
|
-
);
|
|
168
|
+
public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
|
|
169
|
+
const price = await fetchPrice(token.address, this._networkConnection.provider);
|
|
170
|
+
return {
|
|
171
|
+
currency: "USD",
|
|
172
|
+
amount: price.toFixed(DECIMAL_PRECISION)
|
|
73
173
|
}
|
|
74
|
-
|
|
75
|
-
return new TokenAmount(
|
|
76
|
-
DOLLAR,
|
|
77
|
-
'12.1',
|
|
78
|
-
false,
|
|
79
|
-
);
|
|
80
174
|
}
|
|
81
175
|
public async stakeBalanceOf(user: string): Promise<TokenAmount> {
|
|
176
|
+
const userInfo = await this._auriFairLaunch.getUserInfo(AurPlyPid, user);
|
|
82
177
|
return new TokenAmount(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
178
|
+
AURPLYToken,
|
|
179
|
+
userInfo.amount.toString()
|
|
180
|
+
)
|
|
87
181
|
}
|
|
88
182
|
}
|
|
89
183
|
|
|
90
184
|
export class SdkReadWrite extends SdkRead {
|
|
91
|
-
dummyTransaction = async (): Promise<TransactionResponse> => {
|
|
92
|
-
// const dummyErc20Token = new Contract(
|
|
93
|
-
// dummyToken.address,
|
|
94
|
-
// IERC20.abi,
|
|
95
|
-
// this._providerOrSigner
|
|
96
|
-
// );
|
|
97
|
-
// return await dummyErc20Token.approve(dummyToken.address, 123);
|
|
98
|
-
return {} as TransactionResponse;
|
|
99
|
-
};
|
|
100
185
|
public async claim(): Promise<TransactionResponse> {
|
|
101
|
-
return this.
|
|
186
|
+
return this._auriLens.connect(this._networkConnection.signer!).claimRewards(
|
|
187
|
+
this._comptroller.address,
|
|
188
|
+
this._auriFairLaunch.address,
|
|
189
|
+
await this._networkConnection.signer!.getAddress(),
|
|
190
|
+
[AurPlyPid]
|
|
191
|
+
);
|
|
102
192
|
}
|
|
103
193
|
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
104
|
-
return this.
|
|
194
|
+
return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(AurPlyPid, amount.rawAmount(), false);
|
|
105
195
|
}
|
|
106
196
|
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
107
|
-
return this.
|
|
197
|
+
return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(AurPlyPid, amount.rawAmount());
|
|
108
198
|
}
|
|
109
199
|
}
|
|
110
200
|
|
|
@@ -112,11 +202,11 @@ export class SDK extends BlockchainEntity {
|
|
|
112
202
|
constructor() {
|
|
113
203
|
super();
|
|
114
204
|
}
|
|
115
|
-
public read(
|
|
116
|
-
return new SdkRead(
|
|
205
|
+
public read(networkConnection: NetworkConnection): SdkRead {
|
|
206
|
+
return new SdkRead(networkConnection);
|
|
117
207
|
}
|
|
118
208
|
|
|
119
|
-
public static defaultProvider():
|
|
209
|
+
public static defaultProvider(): providers.Provider {
|
|
120
210
|
return new ethers.providers.JsonRpcProvider(AVAX_DEFAULT_PROVIDER_URL);
|
|
121
211
|
}
|
|
122
212
|
}
|