@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
package/src/Papermill.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import { NetworkConnection, Address, UserLockingDetails } from './types';
|
|
3
|
-
import { Contract, BigNumber as BN } from 'ethers';
|
|
4
|
-
import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
|
|
5
|
-
import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
|
|
6
|
-
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
7
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
8
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
9
|
-
import {
|
|
10
|
-
AuriFairLaunch,
|
|
11
|
-
AuriLens,
|
|
12
|
-
Comptroller,
|
|
13
|
-
IERC20,
|
|
14
|
-
PULP,
|
|
15
|
-
} from '@aurigami/contracts/typechain';
|
|
16
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
17
|
-
import {
|
|
18
|
-
networkAddresses,
|
|
19
|
-
ONE_DAY,
|
|
20
|
-
ALL_STAKING_POOLS,
|
|
21
|
-
REWARD_CLAIM_START,
|
|
22
|
-
ONE_WEEK,
|
|
23
|
-
} from './constants';
|
|
24
|
-
import { getCurrentTimestamp } from './helpers';
|
|
25
|
-
import { Token } from './token';
|
|
26
|
-
import { TokenAmount } from './tokenAmount';
|
|
27
|
-
import { getDecimal } from './helpers';
|
|
28
|
-
import BigNumber from 'bignumber.js';
|
|
29
|
-
|
|
30
|
-
const LOCKING_DENOMINATOR = BN.from(10000);
|
|
31
|
-
export class PapermillRead extends BlockchainEntityRead {
|
|
32
|
-
public plyToken: Token;
|
|
33
|
-
public pulpToken: Token;
|
|
34
|
-
|
|
35
|
-
protected _ply: IERC20;
|
|
36
|
-
protected _pulp: PULP;
|
|
37
|
-
protected _comptroller: Comptroller;
|
|
38
|
-
protected _auriFairLaunch: AuriFairLaunch;
|
|
39
|
-
protected _auriLens: AuriLens;
|
|
40
|
-
|
|
41
|
-
constructor(networkConnection: NetworkConnection) {
|
|
42
|
-
super(networkConnection);
|
|
43
|
-
|
|
44
|
-
let plyAddress = networkAddresses.tokens.PLY;
|
|
45
|
-
let pulpAddress = networkAddresses.tokens.PULP;
|
|
46
|
-
|
|
47
|
-
this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
|
|
48
|
-
this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
|
|
49
|
-
|
|
50
|
-
this._comptroller = new Contract(
|
|
51
|
-
networkAddresses.misc.COMPTROLLER,
|
|
52
|
-
ComptrollerABI.abi,
|
|
53
|
-
networkConnection.provider
|
|
54
|
-
) as Comptroller;
|
|
55
|
-
this._auriFairLaunch = new Contract(
|
|
56
|
-
networkAddresses.misc.AURIFAIRLAUNCH,
|
|
57
|
-
AuriFairLaunchABI.abi,
|
|
58
|
-
networkConnection.provider
|
|
59
|
-
) as AuriFairLaunch;
|
|
60
|
-
this._auriLens = new Contract(
|
|
61
|
-
networkAddresses.misc.AURILENS,
|
|
62
|
-
AuriLensABI.abi,
|
|
63
|
-
networkConnection.provider
|
|
64
|
-
) as AuriLens;
|
|
65
|
-
this._ply = new Contract(
|
|
66
|
-
plyAddress,
|
|
67
|
-
EIP20InterfaceABI.abi,
|
|
68
|
-
networkConnection.provider
|
|
69
|
-
) as IERC20;
|
|
70
|
-
this._pulp = new Contract(
|
|
71
|
-
pulpAddress,
|
|
72
|
-
PulpABI.abi,
|
|
73
|
-
networkConnection.provider
|
|
74
|
-
) as PULP;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
|
|
78
|
-
const plyBalance = await this._ply.balanceOf(userAddress);
|
|
79
|
-
return new TokenAmount(this.plyToken, plyBalance.toString());
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
|
|
83
|
-
const pulpBalance = await this._pulp.balanceOf(userAddress);
|
|
84
|
-
return new TokenAmount(this.pulpToken, pulpBalance.toString());
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get all unclaimed PLY reward of the user in all markets + all staking pools
|
|
89
|
-
*/
|
|
90
|
-
public async getUnclaimedPlyReward(
|
|
91
|
-
userAddress: Address
|
|
92
|
-
): Promise<TokenAmount> {
|
|
93
|
-
let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
|
|
94
|
-
this._comptroller.address,
|
|
95
|
-
this._auriFairLaunch.address,
|
|
96
|
-
ALL_STAKING_POOLS,
|
|
97
|
-
{ from: userAddress }
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return new TokenAmount(
|
|
101
|
-
this.plyToken,
|
|
102
|
-
rewardBalancesMetadata.plyAccrured.toString()
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private getWeek(timestamp: number): number {
|
|
107
|
-
return BN.from(timestamp - REWARD_CLAIM_START)
|
|
108
|
-
.div(ONE_WEEK)
|
|
109
|
-
.toNumber();
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get all locking details of the user in all markets + all staking pools
|
|
113
|
-
*/
|
|
114
|
-
public async getLockingDetails(
|
|
115
|
-
userAddress: Address
|
|
116
|
-
): Promise<UserLockingDetails> {
|
|
117
|
-
const currentWeek = this.getWeek(getCurrentTimestamp());
|
|
118
|
-
var promises: any[] = [];
|
|
119
|
-
|
|
120
|
-
promises.push(
|
|
121
|
-
this._auriLens.getPercentLock(
|
|
122
|
-
this._pulp.address,
|
|
123
|
-
userAddress,
|
|
124
|
-
currentWeek
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
promises.push(
|
|
128
|
-
this._auriLens.getPercentLock(
|
|
129
|
-
this._pulp.address,
|
|
130
|
-
userAddress,
|
|
131
|
-
currentWeek + 1
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
promises.push(this.getUnclaimedPlyReward(userAddress));
|
|
135
|
-
|
|
136
|
-
var values: any[] = await Promise.all(promises);
|
|
137
|
-
|
|
138
|
-
let percentLockCurrentWeek = BN.from(values[0]);
|
|
139
|
-
let percentLockNextWeek = BN.from(values[1]);
|
|
140
|
-
let totalRewards = values[2] as TokenAmount;
|
|
141
|
-
|
|
142
|
-
let [pulpAmountCurrentWeek, plyAmountCurrentWeek] =
|
|
143
|
-
await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
|
|
144
|
-
|
|
145
|
-
// Predict next week lock amount = totalRewards * percentLock next week
|
|
146
|
-
// This doesn't take (the reward that user might earn in the next week) into account
|
|
147
|
-
let plyAmountNextWeek = percentLockNextWeek
|
|
148
|
-
.mul(totalRewards.rawAmount())
|
|
149
|
-
.div(LOCKING_DENOMINATOR);
|
|
150
|
-
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
|
|
151
|
-
plyAmountNextWeek
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// we need to divide these two number by 10000 and multiple by 100 to get the percentage
|
|
155
|
-
// I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
|
|
156
|
-
let currentUnlockPortion = LOCKING_DENOMINATOR.sub(
|
|
157
|
-
percentLockCurrentWeek
|
|
158
|
-
).toString();
|
|
159
|
-
let nextUnlockPortion =
|
|
160
|
-
LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
vestingStart: REWARD_CLAIM_START,
|
|
164
|
-
currentUnlockPortion: new BigNumber(currentUnlockPortion)
|
|
165
|
-
.dividedBy(100)
|
|
166
|
-
.toNumber(),
|
|
167
|
-
accruedPly: totalRewards,
|
|
168
|
-
currentPly: new TokenAmount(
|
|
169
|
-
this.plyToken,
|
|
170
|
-
plyAmountCurrentWeek.toString()
|
|
171
|
-
),
|
|
172
|
-
currentPulp: new TokenAmount(
|
|
173
|
-
this.pulpToken,
|
|
174
|
-
pulpAmountCurrentWeek.toString()
|
|
175
|
-
),
|
|
176
|
-
//
|
|
177
|
-
nextUnlockPortion: new BigNumber(nextUnlockPortion)
|
|
178
|
-
.dividedBy(100)
|
|
179
|
-
.toNumber(),
|
|
180
|
-
nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
|
|
181
|
-
nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Get the first timestamp that the unlockPortion reach the target
|
|
187
|
-
*
|
|
188
|
-
* @param userAddress currently doesn't matter
|
|
189
|
-
* @param targetUnlockPortion unlockPortion target
|
|
190
|
-
*/
|
|
191
|
-
public async getTimestampToUnlock(
|
|
192
|
-
userAddress: Address,
|
|
193
|
-
targetUnlockPortion: number
|
|
194
|
-
): Promise<number> {
|
|
195
|
-
let weekId = await this._auriLens.getWeekToUnlock(
|
|
196
|
-
this._pulp.address,
|
|
197
|
-
userAddress,
|
|
198
|
-
targetUnlockPortion * 100
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
return REWARD_CLAIM_START + ONE_WEEK * weekId.toNumber();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public async getUnlockPortionAt(
|
|
205
|
-
userAddress: Address,
|
|
206
|
-
timestamp: number
|
|
207
|
-
): Promise<number> {
|
|
208
|
-
let lockPortion = await this._auriLens.getPercentLock(
|
|
209
|
-
this._pulp.address,
|
|
210
|
-
userAddress,
|
|
211
|
-
this.getWeek(timestamp)
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
let unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
|
|
215
|
-
|
|
216
|
-
return unlockPortion.toNumber() / 100;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export class PapermillReadWrite extends PapermillRead {
|
|
221
|
-
constructor(networkConnection: NetworkConnection) {
|
|
222
|
-
super(networkConnection);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Redeem PLY from PULP and transfer PLY to another address
|
|
227
|
-
* @param recipient Address that will receive the PLY.
|
|
228
|
-
* @param amount Amount of PULP to be converted to PLY.
|
|
229
|
-
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
230
|
-
*/
|
|
231
|
-
public async redeem(
|
|
232
|
-
recipient: Address,
|
|
233
|
-
amount: TokenAmount
|
|
234
|
-
): Promise<TransactionResponse> {
|
|
235
|
-
return this._pulp
|
|
236
|
-
.connect(this._networkConnection.signer!)
|
|
237
|
-
.redeem(recipient, amount.rawAmount());
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Redeem PLY from PULP and transfer PLY to msg.sender
|
|
242
|
-
* @param amount Amount of PULP to be converted to PLY.
|
|
243
|
-
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
244
|
-
*/
|
|
245
|
-
public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
|
|
246
|
-
let msgSender: string = await this._networkConnection.signer!.getAddress();
|
|
247
|
-
return this.redeem(msgSender, amount);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export class Papermill extends BlockchainEntity {
|
|
252
|
-
constructor() {
|
|
253
|
-
super();
|
|
254
|
-
}
|
|
255
|
-
public read(networkConnection: NetworkConnection): PapermillRead {
|
|
256
|
-
return new PapermillRead(networkConnection);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
|
|
260
|
-
return new PapermillReadWrite(networkConnection);
|
|
261
|
-
}
|
|
262
|
-
}
|
package/src/SDK.ts
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
|
|
2
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
3
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
4
|
-
import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
|
|
5
|
-
import {
|
|
6
|
-
AuriFairLaunch,
|
|
7
|
-
AuriLens,
|
|
8
|
-
Comptroller,
|
|
9
|
-
} from '@aurigami/contracts/typechain';
|
|
10
|
-
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
11
|
-
import BigNumber from 'bignumber.js';
|
|
12
|
-
import { BigNumber as BN, Contract } from 'ethers';
|
|
13
|
-
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
14
|
-
import {
|
|
15
|
-
ALL_STAKING_POOLS,
|
|
16
|
-
BORROW_LIMIT_BUFFER,
|
|
17
|
-
DECIMAL_PRECISION,
|
|
18
|
-
INF,
|
|
19
|
-
networkAddresses,
|
|
20
|
-
} from './constants';
|
|
21
|
-
import { decimalFactor, isSameAddress } from './helpers';
|
|
22
|
-
import { MoneyMarketRead } from './MoneyMarket';
|
|
23
|
-
import { PapermillRead } from './Papermill';
|
|
24
|
-
import { calcValuation, fetchPrice } from './priceFetcher';
|
|
25
|
-
import { StakingRead, StakingReadWrite } from './Staking';
|
|
26
|
-
import { Token } from './token';
|
|
27
|
-
import { TokenAmount } from './tokenAmount';
|
|
28
|
-
import {
|
|
29
|
-
Address,
|
|
30
|
-
CurrencyAmount,
|
|
31
|
-
HypotheticalStats,
|
|
32
|
-
MarketAction,
|
|
33
|
-
NetworkConnection,
|
|
34
|
-
PLYWNEARPoolDetails,
|
|
35
|
-
UserDetails,
|
|
36
|
-
UserMarketDetails,
|
|
37
|
-
} from './types';
|
|
38
|
-
|
|
39
|
-
export class SdkRead extends BlockchainEntityRead {
|
|
40
|
-
protected _comptroller: Comptroller;
|
|
41
|
-
protected _auriFairLaunch: AuriFairLaunch;
|
|
42
|
-
protected _auriLens: AuriLens;
|
|
43
|
-
protected _stakingRead: StakingRead;
|
|
44
|
-
constructor(networkConnection: NetworkConnection) {
|
|
45
|
-
super(networkConnection);
|
|
46
|
-
this._stakingRead = new StakingRead(networkConnection);
|
|
47
|
-
this._comptroller = new Contract(
|
|
48
|
-
networkAddresses.misc.COMPTROLLER,
|
|
49
|
-
ComptrollerABI.abi,
|
|
50
|
-
networkConnection.provider
|
|
51
|
-
) as Comptroller;
|
|
52
|
-
this._auriFairLaunch = new Contract(
|
|
53
|
-
networkAddresses.misc.AURIFAIRLAUNCH,
|
|
54
|
-
AuriFairLaunchABI.abi,
|
|
55
|
-
networkConnection.provider
|
|
56
|
-
) as AuriFairLaunch;
|
|
57
|
-
this._auriLens = new Contract(
|
|
58
|
-
networkAddresses.misc.AURILENS,
|
|
59
|
-
AuriLensABI.abi,
|
|
60
|
-
networkConnection.provider
|
|
61
|
-
) as AuriLens;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
65
|
-
const marketCount = networkAddresses.auTokens.length;
|
|
66
|
-
var userMarketDetails: UserMarketDetails[] = [],
|
|
67
|
-
assetsIn: string[];
|
|
68
|
-
var promises = [];
|
|
69
|
-
var totalBorrowLimit = new BigNumber(0);
|
|
70
|
-
var pricePromises = [];
|
|
71
|
-
for (const auToken of networkAddresses.auTokens) {
|
|
72
|
-
const userMarketDetail: UserMarketDetails = {} as UserMarketDetails;
|
|
73
|
-
userMarketDetails.push(userMarketDetail);
|
|
74
|
-
userMarketDetail.market = auToken.underlying;
|
|
75
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
76
|
-
this._networkConnection,
|
|
77
|
-
auToken.address,
|
|
78
|
-
auToken.underlying
|
|
79
|
-
);
|
|
80
|
-
promises.push(
|
|
81
|
-
moneyMarket
|
|
82
|
-
.getUserDepositBalance(userAddress)
|
|
83
|
-
.then((res: TokenAmount) => {
|
|
84
|
-
userMarketDetail.depositBalance = res;
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
promises.push(
|
|
88
|
-
moneyMarket
|
|
89
|
-
.getUserBorrowBalance(userAddress)
|
|
90
|
-
.then((res: TokenAmount) => {
|
|
91
|
-
userMarketDetail.borrowBalance = res;
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
promises.push(
|
|
95
|
-
moneyMarket.getCollateralRatio().then((res: BigNumber) => {
|
|
96
|
-
userMarketDetail.collateralRatio = res.toNumber();
|
|
97
|
-
})
|
|
98
|
-
);
|
|
99
|
-
pricePromises.push(
|
|
100
|
-
fetchPrice(
|
|
101
|
-
moneyMarket.underlying.address,
|
|
102
|
-
this._networkConnection.provider
|
|
103
|
-
).then((res) => {
|
|
104
|
-
userMarketDetail.underlyingPrice = res.toString();
|
|
105
|
-
return res;
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
promises.push(
|
|
111
|
-
this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {
|
|
112
|
-
assetsIn = res;
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
await Promise.all(promises);
|
|
117
|
-
var underlyingPrices = await Promise.all(pricePromises);
|
|
118
|
-
var depositValues = [];
|
|
119
|
-
for (var i = 0; i < marketCount; i++) {
|
|
120
|
-
const auToken = networkAddresses.auTokens[i];
|
|
121
|
-
if (
|
|
122
|
-
assetsIn!.find((auAddress: Address) =>
|
|
123
|
-
isSameAddress(auToken.address, auAddress)
|
|
124
|
-
) !== undefined
|
|
125
|
-
) {
|
|
126
|
-
userMarketDetails[i].isCollateral = true;
|
|
127
|
-
} else {
|
|
128
|
-
userMarketDetails[i].isCollateral = false;
|
|
129
|
-
}
|
|
130
|
-
depositValues.push(
|
|
131
|
-
calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i])
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
totalBorrowLimit = depositValues.reduce(
|
|
136
|
-
(p: BigNumber, v: BigNumber, index: number) => {
|
|
137
|
-
if (userMarketDetails[index].isCollateral)
|
|
138
|
-
return p.plus(
|
|
139
|
-
v.multipliedBy(userMarketDetails[index].collateralRatio)
|
|
140
|
-
);
|
|
141
|
-
return p;
|
|
142
|
-
},
|
|
143
|
-
new BigNumber(0)
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
var accountLiquidity: [BN, BN] =
|
|
147
|
-
await this._comptroller.getAccountLiquidity(userAddress);
|
|
148
|
-
|
|
149
|
-
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
150
|
-
new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (borrowedvaluation.lt('0.00001')) {
|
|
154
|
-
// Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
|
|
155
|
-
borrowedvaluation = new BigNumber(0);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const bufferedBorrowLimit: BigNumber =
|
|
159
|
-
totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
160
|
-
const minimumBorrowLimitAllowed =
|
|
161
|
-
borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
162
|
-
|
|
163
|
-
var borrowableAmount: BigNumber;
|
|
164
|
-
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
165
|
-
borrowableAmount = new BigNumber(0);
|
|
166
|
-
} else {
|
|
167
|
-
borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
for (var i = 0; i < marketCount; i++) {
|
|
171
|
-
const auToken = networkAddresses.auTokens[i];
|
|
172
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
173
|
-
this._networkConnection,
|
|
174
|
-
auToken.address,
|
|
175
|
-
auToken.underlying
|
|
176
|
-
);
|
|
177
|
-
const borrowLimitMargin = totalBorrowLimit
|
|
178
|
-
.minus(minimumBorrowLimitAllowed)
|
|
179
|
-
.gt(0)
|
|
180
|
-
? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
|
|
181
|
-
: new BigNumber(0);
|
|
182
|
-
const maxWithdrawCap: BigNumber = borrowLimitMargin
|
|
183
|
-
.div(userMarketDetails[i].collateralRatio)
|
|
184
|
-
.div(underlyingPrices[i]);
|
|
185
|
-
userMarketDetails[i].maxWithdrawableAmount =
|
|
186
|
-
userMarketDetails[i].isCollateral &&
|
|
187
|
-
maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
188
|
-
? new TokenAmount(
|
|
189
|
-
moneyMarket.underlying,
|
|
190
|
-
maxWithdrawCap.toFixed(24),
|
|
191
|
-
false
|
|
192
|
-
)
|
|
193
|
-
: new TokenAmount(
|
|
194
|
-
moneyMarket.underlying,
|
|
195
|
-
userMarketDetails[i].depositBalance.rawAmount()
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
markets: userMarketDetails,
|
|
201
|
-
borrowLimit: {
|
|
202
|
-
currency: 'USD',
|
|
203
|
-
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
204
|
-
},
|
|
205
|
-
userLockingDetails: await new PapermillRead(
|
|
206
|
-
this._networkConnection
|
|
207
|
-
).getLockingDetails(userAddress),
|
|
208
|
-
borrowableAmount: {
|
|
209
|
-
currency: 'USD',
|
|
210
|
-
amount: borrowableAmount.toFixed(DECIMAL_PRECISION),
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
public async getPLYWNEARPoolDetails(): Promise<PLYWNEARPoolDetails> {
|
|
216
|
-
return this._stakingRead.getPLYWNEARPoolDetails();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
|
|
220
|
-
const price = await fetchPrice(
|
|
221
|
-
token.address,
|
|
222
|
-
this._networkConnection.provider
|
|
223
|
-
);
|
|
224
|
-
return {
|
|
225
|
-
currency: 'USD',
|
|
226
|
-
amount: price.toFixed(DECIMAL_PRECISION),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get amount of staked LP tokens
|
|
232
|
-
*/
|
|
233
|
-
public async stakeBalanceOf(user: string): Promise<TokenAmount> {
|
|
234
|
-
return this._stakingRead.stakeBalanceOf(user);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Get amount of LP token in user wallet
|
|
239
|
-
*/
|
|
240
|
-
public async LpBalanceOf(user: string): Promise<TokenAmount> {
|
|
241
|
-
return this._stakingRead.LpBalanceOf(user);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
public async unclaimedRewardsOf(user: string): Promise<TokenAmount[]> {
|
|
245
|
-
return this._stakingRead.unclaimedRewardsOf(user);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
public calcHypotheticalStats({
|
|
249
|
-
userMarketDetail,
|
|
250
|
-
currentBorrowLimit,
|
|
251
|
-
currentBorrowValuation,
|
|
252
|
-
action,
|
|
253
|
-
tokenAmount,
|
|
254
|
-
}: {
|
|
255
|
-
userMarketDetail: UserMarketDetails;
|
|
256
|
-
currentBorrowLimit: CurrencyAmount;
|
|
257
|
-
currentBorrowValuation: CurrencyAmount;
|
|
258
|
-
action: MarketAction;
|
|
259
|
-
tokenAmount?: TokenAmount;
|
|
260
|
-
}): HypotheticalStats {
|
|
261
|
-
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
262
|
-
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
263
|
-
switch (action) {
|
|
264
|
-
case MarketAction.EnableCollateral:
|
|
265
|
-
case MarketAction.DisableCollateral:
|
|
266
|
-
var deltaBorrowLimit = calcValuation(
|
|
267
|
-
userMarketDetail.depositBalance,
|
|
268
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
269
|
-
)
|
|
270
|
-
.multipliedBy(userMarketDetail.collateralRatio)
|
|
271
|
-
.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
272
|
-
newBorrowLimit =
|
|
273
|
-
action == MarketAction.EnableCollateral
|
|
274
|
-
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
275
|
-
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
276
|
-
break;
|
|
277
|
-
|
|
278
|
-
case MarketAction.Deposit:
|
|
279
|
-
case MarketAction.Withdraw:
|
|
280
|
-
deltaBorrowLimit = calcValuation(
|
|
281
|
-
tokenAmount!,
|
|
282
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
283
|
-
)
|
|
284
|
-
.multipliedBy(userMarketDetail.collateralRatio)
|
|
285
|
-
.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
286
|
-
newBorrowLimit =
|
|
287
|
-
action == MarketAction.Deposit
|
|
288
|
-
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
289
|
-
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
290
|
-
break;
|
|
291
|
-
|
|
292
|
-
case MarketAction.Borrow:
|
|
293
|
-
case MarketAction.Repay:
|
|
294
|
-
var deltaBorrowValuation = calcValuation(
|
|
295
|
-
tokenAmount!,
|
|
296
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
297
|
-
);
|
|
298
|
-
newBorrowValuation =
|
|
299
|
-
action == MarketAction.Borrow
|
|
300
|
-
? newBorrowValuation.plus(deltaBorrowValuation)
|
|
301
|
-
: newBorrowValuation.minus(deltaBorrowValuation);
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
newBorrowLimit: {
|
|
306
|
-
amount: newBorrowLimit!.toFixed(DECIMAL_PRECISION),
|
|
307
|
-
currency: 'USD',
|
|
308
|
-
},
|
|
309
|
-
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
310
|
-
? newBorrowValuation.eq(0)
|
|
311
|
-
? 0
|
|
312
|
-
: 9999.99
|
|
313
|
-
: newBorrowValuation!.div(newBorrowLimit!).toNumber(),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export class SdkReadWrite extends SdkRead {
|
|
319
|
-
/**
|
|
320
|
-
* Claim PLY reward in all markets + staking pools
|
|
321
|
-
*/
|
|
322
|
-
public async claim(): Promise<TransactionResponse> {
|
|
323
|
-
return this._comptroller
|
|
324
|
-
.connect(this._networkConnection.signer!)
|
|
325
|
-
['claimReward(uint8,address)'](
|
|
326
|
-
0,
|
|
327
|
-
await this._networkConnection.signer!.getAddress()
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
public async claimLpRewards(): Promise<TransactionResponse> {
|
|
332
|
-
return this._auriFairLaunch
|
|
333
|
-
.connect(this._networkConnection.signer!)
|
|
334
|
-
.harvest(await this._networkConnection.signer!.getAddress(), 0, INF);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
338
|
-
return new StakingReadWrite(this._networkConnection).stake(amount);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
342
|
-
return new StakingReadWrite(this._networkConnection).unstake(amount);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
public async faucetDrip(): Promise<TransactionResponse> {
|
|
346
|
-
const faucet = new Contract(
|
|
347
|
-
networkAddresses.misc.FAUCET,
|
|
348
|
-
FaucetABI.abi,
|
|
349
|
-
this._networkConnection.provider
|
|
350
|
-
);
|
|
351
|
-
return faucet.connect(this._networkConnection.signer!).drip();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export class SDK extends BlockchainEntity {
|
|
356
|
-
constructor() {
|
|
357
|
-
super();
|
|
358
|
-
}
|
|
359
|
-
public read(networkConnection: NetworkConnection): SdkRead {
|
|
360
|
-
return new SdkRead(networkConnection);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
public readWrite(networkConnection: NetworkConnection): SdkReadWrite {
|
|
364
|
-
return new SdkReadWrite(networkConnection);
|
|
365
|
-
}
|
|
366
|
-
}
|