@aurigami/sdk 1.5.9 → 1.6.0-no-src
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 +23 -16
- package/dist/consts/deployments.d.ts +3 -0
- package/dist/{dummy.d.ts → consts/dummy.d.ts} +3 -3
- package/dist/consts/index.d.ts +4 -0
- package/dist/{MoneyMarket.d.ts → contracts/MoneyMarket.d.ts} +3 -5
- package/dist/{Papermill.d.ts → contracts/Papermill.d.ts} +25 -4
- package/dist/{Staking.d.ts → contracts/Staking.d.ts} +8 -3
- package/dist/{airdrop-lottery.d.ts → contracts/airdrop-lottery.d.ts} +12 -4
- package/dist/contracts/index.d.ts +4 -0
- package/dist/{BlockchainEntity.d.ts → entities/BlockchainEntity.d.ts} +1 -1
- package/dist/entities/index.d.ts +3 -0
- package/dist/{tokenAmount.d.ts → entities/tokenAmount.d.ts} +1 -1
- package/dist/{helpers.d.ts → helpers/helpers.d.ts} +10 -1
- package/dist/helpers/index.d.ts +4 -0
- package/dist/{priceFetcher.d.ts → helpers/priceFetcher.d.ts} +2 -2
- package/dist/{transfer-event-query.d.ts → helpers/transfer-event-query.d.ts} +11 -2
- package/dist/index.d.ts +4 -11
- package/dist/sdk.cjs.development.js +2007 -104379
- 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 +2004 -104383
- package/dist/sdk.esm.js.map +1 -1
- package/dist/{types.d.ts → types/index.d.ts} +15 -1
- package/package.json +12 -13
- package/src/BlockchainEntity.ts +0 -33
- package/src/MoneyMarket.ts +0 -510
- package/src/Papermill.ts +0 -262
- package/src/SDK.ts +0 -366
- package/src/Staking.ts +0 -174
- package/src/abis/Faucet.json +0 -157
- package/src/abis/IUniswapV2Pair.json +0 -663
- package/src/abis/Oracle.json +0 -247
- package/src/abis/dummy.json +0 -3
- package/src/airdrop-lottery.ts +0 -327
- package/src/airdrop_misc/auTokensInfo.json +0 -34
- package/src/airdrop_misc/whitelist.example.txt +0 -4
- package/src/airdrop_misc/whitelist.json +0 -102629
- package/src/aurora-api-helpers.ts +0 -20
- package/src/constants.ts +0 -143
- package/src/decimals.ts +0 -24
- package/src/deployments/aurora_mainnet.json +0 -31
- package/src/deployments/aurora_testnet.json +0 -31
- package/src/dummy.ts +0 -38
- package/src/helpers.ts +0 -91
- package/src/index.ts +0 -20
- package/src/priceFetcher.ts +0 -309
- package/src/token.ts +0 -21
- package/src/tokenAmount.ts +0 -42
- package/src/transfer-event-query.ts +0 -70
- package/src/types.ts +0 -106
- /package/dist/{constants.d.ts → consts/constants.d.ts} +0 -0
- /package/dist/{decimals.d.ts → consts/decimals.d.ts} +0 -0
- /package/dist/{token.d.ts → entities/token.d.ts} +0 -0
- /package/dist/{aurora-api-helpers.d.ts → helpers/aurora-api-helpers.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { providers, Signer } from 'ethers';
|
|
2
|
-
import { TokenAmount } from '
|
|
2
|
+
import { TokenAmount } from '../entities/tokenAmount';
|
|
3
3
|
export declare enum ComptrollerRewardType {
|
|
4
4
|
PLY = 0,
|
|
5
5
|
AURORA = 1
|
|
@@ -40,12 +40,26 @@ export declare type UserDetails = {
|
|
|
40
40
|
};
|
|
41
41
|
export declare type UserLockingDetails = {
|
|
42
42
|
vestingStart: number;
|
|
43
|
+
/** % of reward they will receive in PLY, if they claim this week */
|
|
43
44
|
currentUnlockPortion: number;
|
|
44
45
|
accruedPly: TokenAmount;
|
|
46
|
+
/** Amount of PLY they will receive, if they claim this week */
|
|
45
47
|
currentPly: TokenAmount;
|
|
48
|
+
/** Amount of PULP they will receive, if they claim this week */
|
|
46
49
|
currentPulp: TokenAmount;
|
|
50
|
+
/** % of reward they will receive in PLY, if they claim next week */
|
|
47
51
|
nextUnlockPortion: number;
|
|
52
|
+
/**
|
|
53
|
+
* Amount of PLY they will receive, if they claim next week.
|
|
54
|
+
* This doesn't include the additional reward that they will earn
|
|
55
|
+
* in the next week.
|
|
56
|
+
*/
|
|
48
57
|
nextPly: TokenAmount;
|
|
58
|
+
/**
|
|
59
|
+
* Amount of PULP they will receive, if they claim next week.
|
|
60
|
+
* This doesn't include the additional reward that they will earn
|
|
61
|
+
* in the next week.
|
|
62
|
+
*/
|
|
49
63
|
nextPulp: TokenAmount;
|
|
50
64
|
};
|
|
51
65
|
export declare type UserMarketDetails = {
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.6.0-no-src",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
"src"
|
|
7
|
+
"dist"
|
|
9
8
|
],
|
|
10
9
|
"engines": {
|
|
11
10
|
"node": ">=10"
|
|
@@ -41,29 +40,29 @@
|
|
|
41
40
|
}
|
|
42
41
|
],
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"@
|
|
43
|
+
"@nomiclabs/hardhat-ethers": "^2.0.5",
|
|
44
|
+
"@nomiclabs/hardhat-etherscan": "^3.0.3",
|
|
45
|
+
"@nomiclabs/hardhat-waffle": "^2.0.3",
|
|
46
|
+
"@size-limit/preset-small-lib": "^7.0.8",
|
|
47
|
+
"@types/mocha": "^9.1.0",
|
|
48
|
+
"chai": "^4.3.6",
|
|
45
49
|
"eslint-config-prettier": "^8.3.0",
|
|
46
50
|
"eslint-plugin-prettier": "^4.0.0",
|
|
51
|
+
"ethereum-waffle": "^3.4.4",
|
|
52
|
+
"hardhat": "^2.9.3",
|
|
47
53
|
"husky": "^7.0.4",
|
|
48
54
|
"prettier": "^2.5.1",
|
|
49
55
|
"size-limit": "^7.0.5",
|
|
56
|
+
"ts-node": "^10.7.0",
|
|
50
57
|
"tsdx": "^0.14.1",
|
|
51
58
|
"tslib": "^2.3.1",
|
|
52
59
|
"typescript": "^4.5.4"
|
|
53
60
|
},
|
|
54
61
|
"dependencies": {
|
|
55
62
|
"@aurigami/contracts": "3.3.0",
|
|
56
|
-
"@nomiclabs/hardhat-ethers": "^2.0.5",
|
|
57
|
-
"@nomiclabs/hardhat-etherscan": "^3.0.3",
|
|
58
|
-
"@nomiclabs/hardhat-waffle": "^2.0.3",
|
|
59
|
-
"@types/mocha": "^9.1.0",
|
|
60
63
|
"axios": "^0.26.1",
|
|
61
64
|
"bignumber.js": "^9.0.2",
|
|
62
|
-
"chai": "^4.3.6",
|
|
63
65
|
"dotenv": "^16.0.0",
|
|
64
|
-
"
|
|
65
|
-
"ethers": "^5.6.4",
|
|
66
|
-
"hardhat": "^2.9.3",
|
|
67
|
-
"ts-node": "^10.7.0"
|
|
66
|
+
"ethers": "^5.6.4"
|
|
68
67
|
}
|
|
69
68
|
}
|
package/src/BlockchainEntity.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
-
import { NetworkConnection } from './types';
|
|
3
|
-
|
|
4
|
-
export class BlockchainEntityRead {
|
|
5
|
-
protected _networkConnection: NetworkConnection;
|
|
6
|
-
public constructor(networkConnection: NetworkConnection) {
|
|
7
|
-
this._networkConnection = networkConnection;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class BlockchainEntityReadWrite extends BlockchainEntityRead {
|
|
12
|
-
public constructor(networkConnection: NetworkConnection) {
|
|
13
|
-
if (!(networkConnection.signer instanceof Signer)) {
|
|
14
|
-
throw Error(
|
|
15
|
-
'Signer is not provided when constructing BlockchainEntityReadWrite'
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
super(networkConnection);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class BlockchainEntity {
|
|
23
|
-
constructor() {}
|
|
24
|
-
public read(networkConnection: NetworkConnection): BlockchainEntityRead {
|
|
25
|
-
return new BlockchainEntityRead(networkConnection);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public readWrite(
|
|
29
|
-
networkConnection: NetworkConnection
|
|
30
|
-
): BlockchainEntityReadWrite {
|
|
31
|
-
return new BlockchainEntityReadWrite(networkConnection);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/MoneyMarket.ts
DELETED
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import {
|
|
3
|
-
MoneyMarketDetails,
|
|
4
|
-
NetworkConnection,
|
|
5
|
-
Address,
|
|
6
|
-
ComptrollerRewardType,
|
|
7
|
-
} from './types';
|
|
8
|
-
import { Contract, BigNumber as BN } from 'ethers';
|
|
9
|
-
import AuErc20ABI from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
|
|
10
|
-
import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
|
|
11
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
12
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
13
|
-
import EthRepayHelperABI from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
|
|
14
|
-
import {
|
|
15
|
-
AuErc20,
|
|
16
|
-
AuETH,
|
|
17
|
-
AuriLens,
|
|
18
|
-
Comptroller,
|
|
19
|
-
EthRepayHelper,
|
|
20
|
-
} from '@aurigami/contracts/typechain';
|
|
21
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
22
|
-
import {
|
|
23
|
-
networkAddresses,
|
|
24
|
-
ETHAddress,
|
|
25
|
-
ONE_YEAR,
|
|
26
|
-
INF,
|
|
27
|
-
ONE_DAY,
|
|
28
|
-
DEPOSIT_NEAR_REWARDS_PER_WEEK,
|
|
29
|
-
BORROW_NEAR_REWARDS_PER_WEEK,
|
|
30
|
-
} from './constants';
|
|
31
|
-
import BigNumber from 'bignumber.js';
|
|
32
|
-
import {
|
|
33
|
-
decimalFactor,
|
|
34
|
-
isSameAddress,
|
|
35
|
-
calcLMRewardApr,
|
|
36
|
-
getCurrentTimestamp,
|
|
37
|
-
} from './helpers';
|
|
38
|
-
import { Token, PLYToken } from './token';
|
|
39
|
-
import { TokenAmount } from './tokenAmount';
|
|
40
|
-
import { getDecimal, validateAndParseAddress } from './helpers';
|
|
41
|
-
import { fetchPrice, calcValuation, fetchValuation } from './priceFetcher';
|
|
42
|
-
|
|
43
|
-
type RewardSpeeds = {
|
|
44
|
-
plyRewardSupplySpeed: BN;
|
|
45
|
-
plyRewardBorrowSpeed: BN;
|
|
46
|
-
auroraRewardSupplySpeed: BN;
|
|
47
|
-
auroraRewardBorrowSpeed: BN;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export class MoneyMarketRead extends BlockchainEntityRead {
|
|
51
|
-
public underlying: Token;
|
|
52
|
-
public auToken: AuErc20 | AuETH;
|
|
53
|
-
protected _comptroller: Comptroller;
|
|
54
|
-
|
|
55
|
-
protected _auriLens: AuriLens;
|
|
56
|
-
constructor(
|
|
57
|
-
networkConnection: NetworkConnection,
|
|
58
|
-
auToken: Address,
|
|
59
|
-
underlyingAsset: Address
|
|
60
|
-
) {
|
|
61
|
-
super(networkConnection);
|
|
62
|
-
if (isSameAddress(underlyingAsset, ETHAddress)) {
|
|
63
|
-
this.auToken = new Contract(
|
|
64
|
-
auToken,
|
|
65
|
-
AuETHABI.abi,
|
|
66
|
-
networkConnection.provider
|
|
67
|
-
) as AuETH;
|
|
68
|
-
} else {
|
|
69
|
-
this.auToken = new Contract(
|
|
70
|
-
auToken,
|
|
71
|
-
AuErc20ABI.abi,
|
|
72
|
-
networkConnection.provider
|
|
73
|
-
) as AuErc20;
|
|
74
|
-
}
|
|
75
|
-
this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
|
|
76
|
-
this._comptroller = new Contract(
|
|
77
|
-
networkAddresses.misc.COMPTROLLER,
|
|
78
|
-
ComptrollerABI.abi,
|
|
79
|
-
networkConnection.provider
|
|
80
|
-
) as Comptroller;
|
|
81
|
-
this._auriLens = new Contract(
|
|
82
|
-
networkAddresses.misc.AURILENS,
|
|
83
|
-
AuriLensABI.abi,
|
|
84
|
-
networkConnection.provider
|
|
85
|
-
) as AuriLens;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
protected async getRewardSpeeds(): Promise<RewardSpeeds> {
|
|
89
|
-
var speeds = await this._auriLens.getRewardSpeeds(
|
|
90
|
-
this._comptroller.address,
|
|
91
|
-
this.auToken.address
|
|
92
|
-
);
|
|
93
|
-
return speeds;
|
|
94
|
-
}
|
|
95
|
-
public async getTotalTokenBorrowed(): Promise<TokenAmount> {
|
|
96
|
-
return new TokenAmount(
|
|
97
|
-
this.underlying,
|
|
98
|
-
(await this.auToken.totalBorrows()).toString()
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
102
|
-
var promises = [];
|
|
103
|
-
var totalBorrow: TokenAmount, totalCash: TokenAmount;
|
|
104
|
-
promises.push(
|
|
105
|
-
this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
106
|
-
totalBorrow = res;
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
promises.push(
|
|
110
|
-
this.auToken.getCash().then((res: BN) => {
|
|
111
|
-
totalCash = new TokenAmount(this.underlying, res.toString());
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
await Promise.all(promises);
|
|
115
|
-
return new TokenAmount(
|
|
116
|
-
this.underlying,
|
|
117
|
-
BN.from(totalCash!.rawAmount()).add(totalBorrow!.rawAmount()).toString()
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public async getDepositAPY(): Promise<BigNumber> {
|
|
122
|
-
const supplyRatePerTimestamp = await this.auToken.supplyRatePerTimestamp();
|
|
123
|
-
return new BigNumber(supplyRatePerTimestamp.toString())
|
|
124
|
-
.multipliedBy(60 * 60 * 24 * 365)
|
|
125
|
-
.div(decimalFactor(18));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public async getBorrowAPY(): Promise<BigNumber> {
|
|
129
|
-
const borrowRatePerTimestamp = await this.auToken.borrowRatePerTimestamp();
|
|
130
|
-
return new BigNumber(borrowRatePerTimestamp.toString())
|
|
131
|
-
.multipliedBy(60 * 60 * 24 * 365)
|
|
132
|
-
.div(decimalFactor(18));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public async getCollateralRatio(): Promise<BigNumber> {
|
|
136
|
-
return this._comptroller.markets(this.auToken.address).then((res: any) => {
|
|
137
|
-
return new BigNumber(res.collateralFactorMantissa.toString()).div(
|
|
138
|
-
decimalFactor(18)
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public async getBorrowPlyAPY(): Promise<BigNumber> {
|
|
144
|
-
var promises = [];
|
|
145
|
-
var totalBorrowed: TokenAmount,
|
|
146
|
-
rewardSpeed: TokenAmount,
|
|
147
|
-
plyPrice: BigNumber,
|
|
148
|
-
underlyingPrice: BigNumber;
|
|
149
|
-
promises.push(
|
|
150
|
-
this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
151
|
-
totalBorrowed = res;
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
promises.push(
|
|
155
|
-
this._comptroller
|
|
156
|
-
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, false)
|
|
157
|
-
.then((res) => {
|
|
158
|
-
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
promises.push(
|
|
162
|
-
fetchPrice(
|
|
163
|
-
networkAddresses.tokens.PLY,
|
|
164
|
-
this._networkConnection.provider
|
|
165
|
-
).then((res) => {
|
|
166
|
-
plyPrice = res;
|
|
167
|
-
})
|
|
168
|
-
);
|
|
169
|
-
promises.push(
|
|
170
|
-
fetchPrice(
|
|
171
|
-
this.underlying.address,
|
|
172
|
-
this._networkConnection.provider
|
|
173
|
-
).then((res) => {
|
|
174
|
-
underlyingPrice = res;
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
await Promise.all(promises);
|
|
178
|
-
return calcLMRewardApr(
|
|
179
|
-
plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
180
|
-
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
|
|
181
|
-
ONE_YEAR
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public async getDepositPlyAPY(): Promise<BigNumber> {
|
|
186
|
-
var promises = [];
|
|
187
|
-
var totalDeposited: TokenAmount,
|
|
188
|
-
rewardSpeed: TokenAmount,
|
|
189
|
-
plyPrice: BigNumber,
|
|
190
|
-
underlyingPrice: BigNumber;
|
|
191
|
-
promises.push(
|
|
192
|
-
this.getTotalTokenDeposited().then((res: TokenAmount) => {
|
|
193
|
-
totalDeposited = res;
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
promises.push(
|
|
197
|
-
this._comptroller
|
|
198
|
-
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, true)
|
|
199
|
-
.then((res) => {
|
|
200
|
-
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
201
|
-
})
|
|
202
|
-
);
|
|
203
|
-
promises.push(
|
|
204
|
-
fetchPrice(
|
|
205
|
-
networkAddresses.tokens.PLY,
|
|
206
|
-
this._networkConnection.provider
|
|
207
|
-
).then((res) => {
|
|
208
|
-
plyPrice = res;
|
|
209
|
-
})
|
|
210
|
-
);
|
|
211
|
-
promises.push(
|
|
212
|
-
fetchPrice(
|
|
213
|
-
this.underlying.address,
|
|
214
|
-
this._networkConnection.provider
|
|
215
|
-
).then((res) => {
|
|
216
|
-
underlyingPrice = res;
|
|
217
|
-
})
|
|
218
|
-
);
|
|
219
|
-
await Promise.all(promises);
|
|
220
|
-
return calcLMRewardApr(
|
|
221
|
-
plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
222
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
223
|
-
ONE_YEAR
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
227
|
-
var promises = [],
|
|
228
|
-
totalDeposited: TokenAmount,
|
|
229
|
-
totalBorrowed: TokenAmount,
|
|
230
|
-
depositAPY: number,
|
|
231
|
-
borrowAPY: number,
|
|
232
|
-
collateralRatio: number;
|
|
233
|
-
promises.push(
|
|
234
|
-
this.getTotalTokenDeposited().then((res: TokenAmount) => {
|
|
235
|
-
totalDeposited = res;
|
|
236
|
-
})
|
|
237
|
-
);
|
|
238
|
-
promises.push(
|
|
239
|
-
this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
240
|
-
totalBorrowed = res;
|
|
241
|
-
})
|
|
242
|
-
);
|
|
243
|
-
promises.push(
|
|
244
|
-
this.getDepositAPY().then((res: BigNumber) => {
|
|
245
|
-
depositAPY = res.toNumber();
|
|
246
|
-
})
|
|
247
|
-
);
|
|
248
|
-
promises.push(
|
|
249
|
-
this.getBorrowAPY().then((res: BigNumber) => {
|
|
250
|
-
borrowAPY = res.toNumber();
|
|
251
|
-
})
|
|
252
|
-
);
|
|
253
|
-
promises.push(
|
|
254
|
-
this.getCollateralRatio().then((res: BigNumber) => {
|
|
255
|
-
collateralRatio = res.toNumber();
|
|
256
|
-
})
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
var plyPrice: BigNumber,
|
|
260
|
-
underlyingPrice: BigNumber,
|
|
261
|
-
rewardSpeeds: RewardSpeeds;
|
|
262
|
-
promises.push(
|
|
263
|
-
this.getRewardSpeeds().then((res) => {
|
|
264
|
-
rewardSpeeds = res;
|
|
265
|
-
})
|
|
266
|
-
);
|
|
267
|
-
promises.push(
|
|
268
|
-
fetchPrice(
|
|
269
|
-
networkAddresses.tokens.PLY,
|
|
270
|
-
this._networkConnection.provider
|
|
271
|
-
).then((res) => {
|
|
272
|
-
plyPrice = res;
|
|
273
|
-
})
|
|
274
|
-
);
|
|
275
|
-
promises.push(
|
|
276
|
-
fetchPrice(
|
|
277
|
-
this.underlying.address,
|
|
278
|
-
this._networkConnection.provider
|
|
279
|
-
).then((res) => {
|
|
280
|
-
underlyingPrice = res;
|
|
281
|
-
})
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
await Promise.all(promises);
|
|
285
|
-
|
|
286
|
-
var borrowPlyApy = calcLMRewardApr(
|
|
287
|
-
calcValuation(
|
|
288
|
-
new TokenAmount(
|
|
289
|
-
PLYToken,
|
|
290
|
-
rewardSpeeds!.plyRewardBorrowSpeed.toString()
|
|
291
|
-
),
|
|
292
|
-
plyPrice!
|
|
293
|
-
),
|
|
294
|
-
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
|
|
295
|
-
ONE_YEAR
|
|
296
|
-
);
|
|
297
|
-
var depositPlyApy = calcLMRewardApr(
|
|
298
|
-
calcValuation(
|
|
299
|
-
new TokenAmount(
|
|
300
|
-
PLYToken,
|
|
301
|
-
rewardSpeeds!.plyRewardSupplySpeed.toString()
|
|
302
|
-
),
|
|
303
|
-
plyPrice!
|
|
304
|
-
),
|
|
305
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
306
|
-
ONE_YEAR
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
var depositNEARApy = calcLMRewardApr(
|
|
310
|
-
await fetchValuation(
|
|
311
|
-
this.getDepositNEARRewardPerWeek(),
|
|
312
|
-
this._networkConnection.provider
|
|
313
|
-
),
|
|
314
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
315
|
-
52
|
|
316
|
-
);
|
|
317
|
-
var borrowNEARApy = calcLMRewardApr(
|
|
318
|
-
await fetchValuation(
|
|
319
|
-
this.getBorrowNEARRewardPerWeek(),
|
|
320
|
-
this._networkConnection.provider
|
|
321
|
-
),
|
|
322
|
-
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
|
|
323
|
-
52
|
|
324
|
-
);
|
|
325
|
-
var depositMETAApy;
|
|
326
|
-
if (
|
|
327
|
-
isSameAddress(this.underlying.address, networkAddresses.tokens.stNEAR)
|
|
328
|
-
) {
|
|
329
|
-
depositMETAApy = calcLMRewardApr(
|
|
330
|
-
new BigNumber(50000),
|
|
331
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
332
|
-
12
|
|
333
|
-
);
|
|
334
|
-
} else {
|
|
335
|
-
depositMETAApy = new BigNumber(0);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return {
|
|
339
|
-
auTokenAddress: this.auToken.address,
|
|
340
|
-
totalTokenDeposited: totalDeposited!,
|
|
341
|
-
totalTokenBorrowed: totalBorrowed!,
|
|
342
|
-
depositApy: depositAPY!,
|
|
343
|
-
depositPlyApy: depositPlyApy.toNumber(),
|
|
344
|
-
borrowApy: borrowAPY!,
|
|
345
|
-
borrowPlyApy: borrowPlyApy.toNumber() * -1,
|
|
346
|
-
collateralRatio: collateralRatio!,
|
|
347
|
-
depositPlyPerWeek: new TokenAmount(
|
|
348
|
-
PLYToken,
|
|
349
|
-
rewardSpeeds!.plyRewardSupplySpeed.mul(ONE_DAY).mul(7).toString()
|
|
350
|
-
),
|
|
351
|
-
borrowPlyPerWeek: new TokenAmount(
|
|
352
|
-
PLYToken,
|
|
353
|
-
rewardSpeeds!.plyRewardBorrowSpeed.mul(ONE_DAY).mul(7).toString()
|
|
354
|
-
),
|
|
355
|
-
depositNEARApy: depositNEARApy.toNumber(),
|
|
356
|
-
borrowNEARApy: borrowNEARApy.toNumber() * -1,
|
|
357
|
-
depositMETAApy: depositMETAApy.toNumber(),
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
public async getUserBorrowBalance(userAddress: string): Promise<TokenAmount> {
|
|
362
|
-
const totalBorrow: BN = await this.auToken.callStatic.borrowBalanceCurrent(
|
|
363
|
-
userAddress
|
|
364
|
-
);
|
|
365
|
-
return new TokenAmount(this.underlying, totalBorrow.toString());
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
public async getUserDepositBalance(
|
|
369
|
-
userAddress: string
|
|
370
|
-
): Promise<TokenAmount> {
|
|
371
|
-
const totalDeposit: BN = await this.auToken.callStatic.balanceOfUnderlying(
|
|
372
|
-
userAddress
|
|
373
|
-
);
|
|
374
|
-
return new TokenAmount(this.underlying, totalDeposit.toString());
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
private getDepositNEARRewardPerWeek(): TokenAmount {
|
|
378
|
-
const NEARToken = new Token(
|
|
379
|
-
networkAddresses.tokens.WNEAR,
|
|
380
|
-
getDecimal(networkAddresses.tokens.WNEAR)
|
|
381
|
-
);
|
|
382
|
-
const rewardStartTime = 1650636000;
|
|
383
|
-
const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
|
|
384
|
-
const currentTime = getCurrentTimestamp();
|
|
385
|
-
if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
|
|
386
|
-
const reward =
|
|
387
|
-
DEPOSIT_NEAR_REWARDS_PER_WEEK[
|
|
388
|
-
this.underlying.address.toLocaleLowerCase()
|
|
389
|
-
] ?? '0';
|
|
390
|
-
return new TokenAmount(NEARToken, reward, false);
|
|
391
|
-
} else {
|
|
392
|
-
return new TokenAmount(NEARToken, '0');
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
private getBorrowNEARRewardPerWeek(): TokenAmount {
|
|
397
|
-
const NEARToken = new Token(
|
|
398
|
-
networkAddresses.tokens.WNEAR,
|
|
399
|
-
getDecimal(networkAddresses.tokens.WNEAR)
|
|
400
|
-
);
|
|
401
|
-
const rewardStartTime = 1650636000;
|
|
402
|
-
const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
|
|
403
|
-
const currentTime = getCurrentTimestamp();
|
|
404
|
-
if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
|
|
405
|
-
const reward =
|
|
406
|
-
BORROW_NEAR_REWARDS_PER_WEEK[
|
|
407
|
-
this.underlying.address.toLocaleLowerCase()
|
|
408
|
-
] ?? '0';
|
|
409
|
-
return new TokenAmount(NEARToken, reward, false);
|
|
410
|
-
} else {
|
|
411
|
-
return new TokenAmount(NEARToken, '0');
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
417
|
-
protected _EthRepayHelper: EthRepayHelper;
|
|
418
|
-
constructor(
|
|
419
|
-
networkConnection: NetworkConnection,
|
|
420
|
-
auToken: Address,
|
|
421
|
-
underlyingAsset: Address
|
|
422
|
-
) {
|
|
423
|
-
super(networkConnection, auToken, underlyingAsset);
|
|
424
|
-
this._EthRepayHelper = new Contract(
|
|
425
|
-
networkAddresses.misc.ETHREPAYHELPER,
|
|
426
|
-
EthRepayHelperABI.abi,
|
|
427
|
-
networkConnection.provider
|
|
428
|
-
) as EthRepayHelper;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
public async deposit(amount: TokenAmount): Promise<TransactionResponse> {
|
|
432
|
-
if (isSameAddress(amount.token.address, ETHAddress)) {
|
|
433
|
-
return (this.auToken as AuETH)
|
|
434
|
-
.connect(this._networkConnection.signer!)
|
|
435
|
-
.mint({ value: amount.rawAmount() });
|
|
436
|
-
} else {
|
|
437
|
-
return (this.auToken as AuErc20)
|
|
438
|
-
.connect(this._networkConnection.signer!)
|
|
439
|
-
.mint(amount.rawAmount());
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
|
|
443
|
-
return this.auToken
|
|
444
|
-
.connect(this._networkConnection.signer!)
|
|
445
|
-
.borrow(amount.rawAmount());
|
|
446
|
-
}
|
|
447
|
-
public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
|
|
448
|
-
if (new BigNumber(amount.rawAmount()).lt(0)) {
|
|
449
|
-
return this.auToken
|
|
450
|
-
.connect(this._networkConnection.signer!)
|
|
451
|
-
.redeemUnderlying(INF);
|
|
452
|
-
}
|
|
453
|
-
return this.auToken
|
|
454
|
-
.connect(this._networkConnection.signer!)
|
|
455
|
-
.redeemUnderlying(amount.rawAmount());
|
|
456
|
-
}
|
|
457
|
-
public async repay(amount: TokenAmount): Promise<TransactionResponse> {
|
|
458
|
-
if (isSameAddress(amount.token.address, ETHAddress)) {
|
|
459
|
-
return this._EthRepayHelper
|
|
460
|
-
.connect(this._networkConnection.signer!)
|
|
461
|
-
.repayBorrow({ value: amount.rawAmount() });
|
|
462
|
-
} else {
|
|
463
|
-
if (new BigNumber(amount.rawAmount()).lt(0)) {
|
|
464
|
-
return this.auToken
|
|
465
|
-
.connect(this._networkConnection.signer!)
|
|
466
|
-
.repayBorrow(INF);
|
|
467
|
-
} else {
|
|
468
|
-
return this.auToken
|
|
469
|
-
.connect(this._networkConnection.signer!)
|
|
470
|
-
.repayBorrow(amount.rawAmount());
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
public async enableCollateral(): Promise<TransactionResponse> {
|
|
475
|
-
return this._comptroller
|
|
476
|
-
.connect(this._networkConnection.signer!)
|
|
477
|
-
.enterMarkets([this.auToken.address]);
|
|
478
|
-
}
|
|
479
|
-
public async disableCollateral(): Promise<TransactionResponse> {
|
|
480
|
-
return this._comptroller
|
|
481
|
-
.connect(this._networkConnection.signer!)
|
|
482
|
-
.exitMarket(this.auToken.address);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export class MoneyMarket extends BlockchainEntity {
|
|
487
|
-
protected address: Address;
|
|
488
|
-
|
|
489
|
-
protected underlying: Address;
|
|
490
|
-
constructor(address: string, underlying: string) {
|
|
491
|
-
super();
|
|
492
|
-
this.address = validateAndParseAddress(address);
|
|
493
|
-
this.underlying = validateAndParseAddress(underlying);
|
|
494
|
-
}
|
|
495
|
-
public read(networkConnection: NetworkConnection): MoneyMarketRead {
|
|
496
|
-
return new MoneyMarketRead(
|
|
497
|
-
networkConnection,
|
|
498
|
-
this.address,
|
|
499
|
-
this.underlying
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
public readWrite(networkConnection: NetworkConnection): MoneyMarketReadWrite {
|
|
504
|
-
return new MoneyMarketReadWrite(
|
|
505
|
-
networkConnection,
|
|
506
|
-
this.address,
|
|
507
|
-
this.underlying
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
}
|