@aurigami/sdk 1.4.8 → 1.5.0-dummy
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/Papermill.d.ts +30 -0
- package/dist/SDK.d.ts +5 -6
- package/dist/constants.d.ts +5 -2
- package/dist/hardhat.config.d.ts +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/priceFetcher.d.ts +3 -1
- package/dist/sdk.cjs.development.js +648 -230
- 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 +638 -228
- package/dist/sdk.esm.js.map +1 -1
- package/dist/test/constants.d.ts +6 -0
- package/dist/test-hardhat/helper.d.ts +6 -0
- package/dist/token.d.ts +1 -1
- package/dist/types.d.ts +13 -9
- package/package.json +2 -2
- package/src/Papermill.ts +162 -0
- package/src/SDK.ts +90 -76
- package/src/constants.ts +26 -5
- package/src/decimals.ts +4 -2
- package/src/helpers.ts +4 -1
- package/src/index.ts +1 -0
- package/src/priceFetcher.ts +95 -28
- package/src/token.ts +7 -7
- package/src/types.ts +31 -11
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ethers, Signer } from 'ethers';
|
|
2
|
+
export declare const AVAX_DEFAULT_PROVIDER_URL = "https://api.avax.network/ext/bc/C/rpc";
|
|
3
|
+
export declare const AVAX_DEFAULT_PROVIDER: ethers.providers.JsonRpcProvider;
|
|
4
|
+
export declare const AURORA_DEFAULT_PROVIDER_URL: string;
|
|
5
|
+
export declare const AURORA_DEFAULT_PROVIDER: ethers.providers.JsonRpcProvider;
|
|
6
|
+
export declare const AURORA_DEFAULT_SIGNER: Signer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Address } from '../src/types';
|
|
2
|
+
import { AuriFairLaunch } from '@aurigami/contracts/typechain';
|
|
3
|
+
export declare function impersonate(address: Address): Promise<void>;
|
|
4
|
+
export declare function prepareERC20Balance(tokenAddress: Address, tokenHolder: Address, receiver: Address, amount?: string): Promise<void>;
|
|
5
|
+
export declare function getFairLaunchContract(): Promise<AuriFairLaunch>;
|
|
6
|
+
export declare function createStakingPool(stakeToken: Address): Promise<void>;
|
package/dist/token.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export declare type CurrencyAmount = {
|
|
|
13
13
|
currency: string;
|
|
14
14
|
amount: string;
|
|
15
15
|
};
|
|
16
|
+
export declare type TokenValuation = {
|
|
17
|
+
tokenAmount: TokenAmount;
|
|
18
|
+
currencyAmount: CurrencyAmount;
|
|
19
|
+
};
|
|
16
20
|
export declare type MoneyMarketDetails = {
|
|
17
21
|
auTokenAddress: string;
|
|
18
22
|
totalTokenDeposited: TokenAmount;
|
|
@@ -31,18 +35,18 @@ export declare type MoneyMarketDetails = {
|
|
|
31
35
|
export declare type UserDetails = {
|
|
32
36
|
markets: UserMarketDetails[];
|
|
33
37
|
borrowLimit: CurrencyAmount;
|
|
34
|
-
|
|
35
|
-
lockedPly: TokenAmount;
|
|
38
|
+
userLockingDetails: UserLockingDetails;
|
|
36
39
|
borrowableAmount: CurrencyAmount;
|
|
37
40
|
};
|
|
38
|
-
export declare type
|
|
41
|
+
export declare type UserLockingDetails = {
|
|
39
42
|
vestingStart: number;
|
|
40
43
|
currentUnlockPortion: number;
|
|
44
|
+
accruedPly: TokenAmount;
|
|
45
|
+
currentPly: TokenAmount;
|
|
46
|
+
currentPulp: TokenAmount;
|
|
41
47
|
nextUnlockPortion: number;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
totalStakedLiquidity: CurrencyAmount;
|
|
45
|
-
apy: number;
|
|
48
|
+
nextPly: TokenAmount;
|
|
49
|
+
nextPulp: TokenAmount;
|
|
46
50
|
};
|
|
47
51
|
export declare type UserMarketDetails = {
|
|
48
52
|
market: string;
|
|
@@ -53,8 +57,8 @@ export declare type UserMarketDetails = {
|
|
|
53
57
|
collateralRatio: number;
|
|
54
58
|
underlyingPrice: string;
|
|
55
59
|
};
|
|
56
|
-
export declare type
|
|
57
|
-
totalStakedLiquidity:
|
|
60
|
+
export declare type PlyUsdcPoolDetails = {
|
|
61
|
+
totalStakedLiquidity: TokenValuation;
|
|
58
62
|
apy: string;
|
|
59
63
|
};
|
|
60
64
|
export declare enum MarketAction {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.5.0-dummy",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"start": "tsdx watch",
|
|
15
15
|
"build": "tsdx build",
|
|
16
16
|
"test": "tsdx test --no-cache",
|
|
17
|
-
"
|
|
17
|
+
"w-hardhat": "env TS_NODE_PROJECT=\"tsconfig.test.json\" yarn hardhat",
|
|
18
18
|
"lint": "tsdx lint",
|
|
19
19
|
"prepare": "tsdx build",
|
|
20
20
|
"size": "size-limit",
|
package/src/Papermill.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
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 { AuriFairLaunch, AuriLens, Comptroller, IERC20, PULP } from "@aurigami/contracts/typechain";
|
|
10
|
+
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
11
|
+
import { networkAddresses, ONE_DAY, ALL_STAKING_POOLS, REWARD_CLAIM_START } from "./constants";
|
|
12
|
+
import { getCurrentTimestamp } from './helpers';
|
|
13
|
+
import { Token } from './token';
|
|
14
|
+
import { TokenAmount } from './tokenAmount';
|
|
15
|
+
import { getDecimal } from './helpers';
|
|
16
|
+
import BigNumber from 'bignumber.js';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export class PapermillRead extends BlockchainEntityRead {
|
|
20
|
+
public plyToken: Token;
|
|
21
|
+
public pulpToken: Token;
|
|
22
|
+
|
|
23
|
+
protected _ply: IERC20;
|
|
24
|
+
protected _pulp: PULP;
|
|
25
|
+
protected _comptroller: Comptroller;
|
|
26
|
+
protected _auriFairLaunch: AuriFairLaunch;
|
|
27
|
+
protected _auriLens: AuriLens;
|
|
28
|
+
|
|
29
|
+
constructor(networkConnection: NetworkConnection) {
|
|
30
|
+
super(networkConnection);
|
|
31
|
+
|
|
32
|
+
let plyAddress = networkAddresses.tokens.PLY;
|
|
33
|
+
let pulpAddress = networkAddresses.tokens.PULP;
|
|
34
|
+
|
|
35
|
+
this.plyToken = new Token(
|
|
36
|
+
plyAddress,
|
|
37
|
+
getDecimal(plyAddress),
|
|
38
|
+
);
|
|
39
|
+
this.pulpToken = new Token(
|
|
40
|
+
pulpAddress,
|
|
41
|
+
getDecimal(pulpAddress),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
|
|
45
|
+
this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
|
|
46
|
+
this._auriLens = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider) as AuriLens;
|
|
47
|
+
this._ply = new Contract(plyAddress, EIP20InterfaceABI.abi, networkConnection.provider) as IERC20;
|
|
48
|
+
this._pulp = new Contract(pulpAddress, PulpABI.abi, networkConnection.provider) as PULP;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
|
|
52
|
+
const plyBalance = await this._ply.balanceOf(userAddress);
|
|
53
|
+
return new TokenAmount(this.plyToken, plyBalance.toString());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
|
|
57
|
+
const pulpBalance = await this._pulp.balanceOf(userAddress);
|
|
58
|
+
return new TokenAmount(this.pulpToken, pulpBalance.toString());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get all unclaimed PLY reward of the user in all markets + all staking pools
|
|
63
|
+
*/
|
|
64
|
+
public async getUnclaimedPlyReward(userAddress: Address): Promise<TokenAmount> {
|
|
65
|
+
let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
|
|
66
|
+
this._comptroller.address,
|
|
67
|
+
this._auriFairLaunch.address,
|
|
68
|
+
ALL_STAKING_POOLS,
|
|
69
|
+
{from: userAddress}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get all locking details of the user in all markets + all staking pools
|
|
77
|
+
*/
|
|
78
|
+
public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
|
|
79
|
+
const currentTime = getCurrentTimestamp();
|
|
80
|
+
const currentWeek = BN.from(currentTime - REWARD_CLAIM_START).div(7 * ONE_DAY).toNumber();
|
|
81
|
+
const denominator = BN.from(10000);
|
|
82
|
+
var promises: any[] = [];
|
|
83
|
+
|
|
84
|
+
promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek));
|
|
85
|
+
promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek + 1));
|
|
86
|
+
promises.push(this.getUnclaimedPlyReward(userAddress));
|
|
87
|
+
|
|
88
|
+
var values: any[] = await Promise.all(promises);
|
|
89
|
+
|
|
90
|
+
let percentLockCurrentWeek = BN.from(values[0]);
|
|
91
|
+
let percentLockNextWeek = BN.from(values[1]);
|
|
92
|
+
let totalRewards = values[2] as TokenAmount;
|
|
93
|
+
|
|
94
|
+
let [
|
|
95
|
+
pulpAmountCurrentWeek,
|
|
96
|
+
plyAmountCurrentWeek
|
|
97
|
+
] = await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// Predict next week lock amount = totalRewards * percentLock next week
|
|
101
|
+
// This doesn't take (the reward that user might earn in the next week) into account
|
|
102
|
+
let plyAmountNextWeek = percentLockNextWeek.mul(totalRewards.rawAmount()).div(denominator);
|
|
103
|
+
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(plyAmountNextWeek);
|
|
104
|
+
|
|
105
|
+
// we need to divide these two number by 10000 and multiple by 100 to get the percentage
|
|
106
|
+
// I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
|
|
107
|
+
let currentUnlockPortion = denominator.sub(percentLockCurrentWeek).toString();
|
|
108
|
+
let nextUnlockPortion = denominator.sub(percentLockNextWeek).toString();
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
vestingStart: REWARD_CLAIM_START,
|
|
112
|
+
currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
|
|
113
|
+
accruedPly: totalRewards,
|
|
114
|
+
currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
|
|
115
|
+
currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
|
|
116
|
+
//
|
|
117
|
+
nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
|
|
118
|
+
nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
|
|
119
|
+
nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export class PapermillReadWrite extends PapermillRead {
|
|
125
|
+
|
|
126
|
+
constructor(networkConnection: NetworkConnection) {
|
|
127
|
+
super(networkConnection);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Redeem PLY from PULP and transfer PLY to another address
|
|
132
|
+
* @param recipient Address that will receive the PLY.
|
|
133
|
+
* @param amount Amount of PULP to be converted to PLY.
|
|
134
|
+
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
135
|
+
*/
|
|
136
|
+
public async redeem(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
|
|
137
|
+
return this._pulp.redeem(recipient, amount.rawAmount());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Redeem PLY from PULP and transfer PLY to msg.sender
|
|
142
|
+
* @param amount Amount of PULP to be converted to PLY.
|
|
143
|
+
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
144
|
+
*/
|
|
145
|
+
public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
|
|
146
|
+
let msgSender: string = await this._networkConnection.signer!.getAddress();
|
|
147
|
+
return this.redeem(msgSender, amount);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class Papermill extends BlockchainEntity {
|
|
152
|
+
constructor() {
|
|
153
|
+
super();
|
|
154
|
+
}
|
|
155
|
+
public read(networkConnection: NetworkConnection): PapermillRead {
|
|
156
|
+
return new PapermillRead(networkConnection);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
|
|
160
|
+
return new PapermillReadWrite(networkConnection);
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/SDK.ts
CHANGED
|
@@ -1,62 +1,44 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
PlyAuroraPoolDetails,
|
|
3
|
+
PlyUsdcPoolDetails,
|
|
5
4
|
NetworkConnection,
|
|
6
5
|
UserDetails,
|
|
7
6
|
UserMarketDetails,
|
|
8
7
|
Address,
|
|
9
8
|
CurrencyAmount,
|
|
10
9
|
HypotheticalStats,
|
|
11
|
-
MarketAction
|
|
10
|
+
MarketAction,
|
|
11
|
+
TokenValuation
|
|
12
12
|
} from './types';
|
|
13
|
-
import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION,
|
|
13
|
+
import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, ONE_DAY, PlyUsdcPid, ALL_STAKING_POOLS, PLYUSDCRewardTokens } from './constants';
|
|
14
14
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
15
|
-
import { Contract, BigNumber as BN
|
|
16
|
-
import { isSameAddress, decimalFactor,
|
|
15
|
+
import { Contract, BigNumber as BN } from 'ethers';
|
|
16
|
+
import { isSameAddress, decimalFactor, calcLMRewardApr, getDecimal } from './helpers';
|
|
17
17
|
import { MoneyMarketRead } from './MoneyMarket';
|
|
18
|
-
import { fetchValuation, fetchPrice, calcValuation } from './priceFetcher';
|
|
19
|
-
import { AuriFairLaunch, Comptroller,
|
|
18
|
+
import { fetchValuation, fetchPrice, calcValuation, valuateToken } from './priceFetcher';
|
|
19
|
+
import { AuriFairLaunch, Comptroller, AuriLens, IERC20 } from '@aurigami/contracts/typechain';
|
|
20
20
|
import { TokenAmount } from './tokenAmount';
|
|
21
|
-
import {
|
|
21
|
+
import { PLYUSDCToken, PLYToken, Token } from './token';
|
|
22
22
|
import BigNumber from 'bignumber.js';
|
|
23
23
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
24
24
|
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
25
|
-
import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
|
|
26
25
|
import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
|
|
27
26
|
import FaucetABI from "@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json";
|
|
27
|
+
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
28
|
+
import { PapermillRead } from './Papermill';
|
|
28
29
|
|
|
29
30
|
export class SdkRead extends BlockchainEntityRead {
|
|
30
31
|
|
|
31
32
|
protected _comptroller: Comptroller;
|
|
32
|
-
protected _tokenLock: TokenLock;
|
|
33
33
|
protected _auriFairLaunch: AuriFairLaunch;
|
|
34
34
|
protected _auriLens: AuriLens;
|
|
35
35
|
constructor(networkConnection: NetworkConnection) {
|
|
36
36
|
super(networkConnection);
|
|
37
37
|
this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
|
|
38
|
-
this._tokenLock = new Contract(networkAddresses.misc.TOKENLOCK, TokenLockABI.abi, networkConnection.provider) as TokenLock;
|
|
39
38
|
this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
|
|
40
39
|
this._auriLens = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider) as AuriLens;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
public async getLockingDetails(): Promise<LockingDetails> {
|
|
44
|
-
const currentTime = getCurrentTimestamp();
|
|
45
|
-
const currentWeek = BN.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
|
|
46
|
-
const denominator = 10000;
|
|
47
|
-
var promises = [];
|
|
48
|
-
promises.push(this._tokenLock.percentageLock(currentWeek));
|
|
49
|
-
promises.push(this._tokenLock.percentageLock(currentWeek + 1).catch((err: any) => {return denominator}));
|
|
50
|
-
var values: string[] = await Promise.all(promises).then((res) => {
|
|
51
|
-
return res.map((v) => {return v.toString()})
|
|
52
|
-
});
|
|
53
|
-
return {
|
|
54
|
-
vestingStart: REWARDCLAIMSTART, // 10 Jan 2023
|
|
55
|
-
currentUnlockPortion: (new BigNumber(denominator).minus(values[0])).div(denominator).toNumber(),
|
|
56
|
-
nextUnlockPortion: (new BigNumber(denominator).minus(values[1])).div(denominator).toNumber(),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
42
|
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
61
43
|
const marketCount = networkAddresses.auTokens.length;
|
|
62
44
|
var userMarketDetails: UserMarketDetails[] = [], assetsIn: string[];
|
|
@@ -78,7 +60,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
78
60
|
}
|
|
79
61
|
|
|
80
62
|
promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
|
|
81
|
-
|
|
63
|
+
|
|
82
64
|
await Promise.all(promises);
|
|
83
65
|
var underlyingPrices = await Promise.all(pricePromises);
|
|
84
66
|
var depositValues = []
|
|
@@ -97,20 +79,14 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
97
79
|
return p;
|
|
98
80
|
}, new BigNumber(0))
|
|
99
81
|
|
|
100
|
-
|
|
101
|
-
var accountLiquidity: [BN, BN], rewardBalancesMetadata, lockedAmount: BN;
|
|
102
|
-
promises[0] = this._comptroller.getAccountLiquidity(userAddress);
|
|
103
|
-
promises[1] = this._auriLens.callStatic.claimRewards(this._comptroller.address, this._auriFairLaunch.address, [], {from: userAddress});
|
|
104
|
-
promises[2] = this._tokenLock.lockedAmounts(userAddress);
|
|
105
|
-
|
|
106
|
-
[accountLiquidity, rewardBalancesMetadata, lockedAmount] = await Promise.all(promises);
|
|
82
|
+
var accountLiquidity: [BN, BN] = await this._comptroller.getAccountLiquidity(userAddress);
|
|
107
83
|
|
|
108
84
|
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
|
|
109
85
|
|
|
110
86
|
if (borrowedvaluation.lt("0.00001")) { // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
|
|
111
87
|
borrowedvaluation = new BigNumber(0);
|
|
112
|
-
}
|
|
113
|
-
|
|
88
|
+
}
|
|
89
|
+
|
|
114
90
|
const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
115
91
|
const minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
116
92
|
|
|
@@ -126,7 +102,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
126
102
|
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
|
|
127
103
|
const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
|
|
128
104
|
const maxWithdrawCap: BigNumber = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
|
|
129
|
-
userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
105
|
+
userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
130
106
|
? new TokenAmount(
|
|
131
107
|
moneyMarket.underlying,
|
|
132
108
|
maxWithdrawCap.toFixed(24),
|
|
@@ -144,8 +120,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
144
120
|
currency: "USD",
|
|
145
121
|
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
|
|
146
122
|
},
|
|
147
|
-
|
|
148
|
-
lockedPly: new TokenAmount(PLYToken, lockedAmount.toString()),
|
|
123
|
+
userLockingDetails: await new PapermillRead(this._networkConnection).getLockingDetails(userAddress),
|
|
149
124
|
borrowableAmount: {
|
|
150
125
|
currency: "USD",
|
|
151
126
|
amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
|
|
@@ -153,33 +128,47 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
153
128
|
};
|
|
154
129
|
}
|
|
155
130
|
|
|
156
|
-
public async
|
|
157
|
-
var stakedLiquidity: BN,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}));
|
|
163
|
-
await Promise.all(promises);
|
|
131
|
+
public async getPlyUsdcPoolDetails(): Promise<PlyUsdcPoolDetails> {
|
|
132
|
+
var stakedLiquidity: BN, rewardPerSeconds: BN[];
|
|
133
|
+
await this._auriFairLaunch.getPoolInfo(PlyUsdcPid).then((res) => {
|
|
134
|
+
stakedLiquidity = res.totalStake;
|
|
135
|
+
rewardPerSeconds = res.rewardPerSeconds;
|
|
136
|
+
});
|
|
164
137
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
promises.push(fetchValuation(new TokenAmount(
|
|
168
|
-
PLYToken,
|
|
169
|
-
rewardPerSecond!.toString()
|
|
170
|
-
), this._networkConnection.provider).then((res) => rewardPerSecondValuation = res));
|
|
171
|
-
promises.push(fetchValuation(new TokenAmount(
|
|
172
|
-
AURPLYToken,
|
|
138
|
+
let stakedLiquidityAmount = new TokenAmount(
|
|
139
|
+
PLYUSDCToken,
|
|
173
140
|
stakedLiquidity!.toString()
|
|
174
|
-
)
|
|
175
|
-
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
var promises = [];
|
|
144
|
+
for (let i = 0; i < rewardPerSeconds!.length; i++) {
|
|
145
|
+
let rewardTokenAddress = PLYUSDCRewardTokens[i];
|
|
146
|
+
let rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
|
|
147
|
+
let rewardPerSecond = rewardPerSeconds![i];
|
|
148
|
+
promises.push(fetchValuation(
|
|
149
|
+
new TokenAmount(rewardToken, rewardPerSecond!.toString()),
|
|
150
|
+
this._networkConnection.provider
|
|
151
|
+
));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
|
|
155
|
+
(p: BigNumber, v: BigNumber) => p.plus(v), new BigNumber(0)
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
var totalStakeValuation: BigNumber = await fetchValuation(
|
|
159
|
+
stakedLiquidityAmount,
|
|
160
|
+
this._networkConnection.provider
|
|
161
|
+
);
|
|
176
162
|
|
|
177
163
|
return {
|
|
178
|
-
totalStakedLiquidity:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
totalStakedLiquidity: {
|
|
165
|
+
tokenAmount: stakedLiquidityAmount,
|
|
166
|
+
currencyAmount: {
|
|
167
|
+
currency: "USD",
|
|
168
|
+
amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION)
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
apy: calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION),
|
|
183
172
|
};
|
|
184
173
|
}
|
|
185
174
|
|
|
@@ -190,24 +179,43 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
190
179
|
amount: price.toFixed(DECIMAL_PRECISION)
|
|
191
180
|
}
|
|
192
181
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get amount and value in $ of staked LP tokens
|
|
185
|
+
*/
|
|
186
|
+
public async stakeBalanceOf(user: string): Promise<TokenValuation> {
|
|
187
|
+
const userInfo = await this._auriFairLaunch.getUserInfo(PlyUsdcPid, user);
|
|
188
|
+
let stakeAmount = new TokenAmount(
|
|
189
|
+
PLYUSDCToken,
|
|
197
190
|
userInfo.amount.toString()
|
|
198
|
-
)
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return valuateToken(stakeAmount, this._networkConnection.provider);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get amount and value in $ of LP token in user wallet
|
|
198
|
+
*/
|
|
199
|
+
public async LpBalanceOf(user: string): Promise<TokenValuation> {
|
|
200
|
+
let lpERC20 = new Contract(networkAddresses.tokens.PLYUSDC, EIP20InterfaceABI.abi, this._networkConnection.provider) as IERC20;
|
|
201
|
+
let balance = await lpERC20.balanceOf(user);
|
|
202
|
+
|
|
203
|
+
return valuateToken(
|
|
204
|
+
new TokenAmount(PLYUSDCToken, balance.toString()),
|
|
205
|
+
this._networkConnection.provider
|
|
206
|
+
);
|
|
199
207
|
}
|
|
200
208
|
|
|
201
209
|
public calcHypotheticalStats({
|
|
202
|
-
userMarketDetail,
|
|
210
|
+
userMarketDetail,
|
|
203
211
|
currentBorrowLimit,
|
|
204
212
|
currentBorrowValuation,
|
|
205
213
|
action,
|
|
206
214
|
tokenAmount
|
|
207
215
|
}: {
|
|
208
216
|
userMarketDetail: UserMarketDetails,
|
|
209
|
-
currentBorrowLimit: CurrencyAmount,
|
|
210
|
-
currentBorrowValuation: CurrencyAmount,
|
|
217
|
+
currentBorrowLimit: CurrencyAmount,
|
|
218
|
+
currentBorrowValuation: CurrencyAmount,
|
|
211
219
|
action: MarketAction,
|
|
212
220
|
tokenAmount?: TokenAmount
|
|
213
221
|
}): HypotheticalStats {
|
|
@@ -243,19 +251,25 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
export class SdkReadWrite extends SdkRead {
|
|
254
|
+
/**
|
|
255
|
+
* Claim PLY reward in all markets + staking pools
|
|
256
|
+
*/
|
|
246
257
|
public async claim(): Promise<TransactionResponse> {
|
|
247
258
|
return this._auriLens.connect(this._networkConnection.signer!).claimRewards(
|
|
248
259
|
this._comptroller.address,
|
|
249
260
|
this._auriFairLaunch.address,
|
|
250
|
-
|
|
261
|
+
ALL_STAKING_POOLS,
|
|
251
262
|
);
|
|
252
263
|
}
|
|
264
|
+
|
|
253
265
|
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
254
|
-
return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(
|
|
266
|
+
return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(PlyUsdcPid, amount.rawAmount());
|
|
255
267
|
}
|
|
268
|
+
|
|
256
269
|
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
257
|
-
return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(
|
|
270
|
+
return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(PlyUsdcPid, amount.rawAmount());
|
|
258
271
|
}
|
|
272
|
+
|
|
259
273
|
public async faucetDrip(): Promise<TransactionResponse> {
|
|
260
274
|
const faucet = new Contract(networkAddresses.misc.FAUCET, FaucetABI.abi, this._networkConnection.provider);
|
|
261
275
|
return faucet.connect(this._networkConnection.signer!).drip();
|
package/src/constants.ts
CHANGED
|
@@ -75,24 +75,45 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
75
75
|
},
|
|
76
76
|
tokens: {
|
|
77
77
|
AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
|
|
78
|
-
PLY: "
|
|
78
|
+
PLY: "0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f".toLowerCase(),
|
|
79
79
|
stNEAR: "0x07f9f7f963c5cd2bbffd30ccfb964be114332e30".toLowerCase(),
|
|
80
80
|
USDC: '0xb12bfca5a55806aaf64e99521918a4bf0fc40802'.toLowerCase(),
|
|
81
81
|
WNEAR: '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase(),
|
|
82
82
|
TRI: '0xFa94348467f64D5A457F75F8bc40495D33c65aBB'.toLowerCase(),
|
|
83
83
|
META: '0xc21ff01229e982d7c8b8691163b0a3cb8f357453'.toLocaleLowerCase(),
|
|
84
|
-
|
|
84
|
+
PULP: '0x04Ac48711BCdc45b4d223fb021E09DA73c71095e'.toLowerCase(),
|
|
85
|
+
PLYUSDC: '0x37cae2b29c18e05ece60111fa01d3ca217046016'.toLowerCase(),
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
// All token that we can calculate the price via oracle + coingecko
|
|
90
|
+
export const PRICE_WHITELISTED = new Set([
|
|
91
|
+
...networkAddresses.auTokens.map(t => t.underlying),
|
|
92
|
+
networkAddresses.tokens.AURORA,
|
|
93
|
+
networkAddresses.tokens.TRI,
|
|
94
|
+
networkAddresses.tokens.META,
|
|
95
|
+
networkAddresses.tokens.stNEAR,
|
|
96
|
+
]);
|
|
97
|
+
|
|
89
98
|
|
|
90
|
-
export const
|
|
99
|
+
export const REWARD_CLAIM_START = 1651762800; // 5 May 2022 15:00:00 UTC
|
|
100
|
+
|
|
101
|
+
export const BORROW_LIMIT_BUFFER = new BigNumber(1);
|
|
91
102
|
|
|
92
103
|
export const ONE_DAY = 86400;
|
|
93
104
|
export const ONE_YEAR = ONE_DAY * 365;
|
|
94
105
|
|
|
95
|
-
export const
|
|
106
|
+
export const PlyUsdcPid = 0;
|
|
107
|
+
export const PLYUSDCRewardTokens = [
|
|
108
|
+
'0x09C9D464b58d96837f8d8b6f4d9fE4aD408d3A4f', // PLY
|
|
109
|
+
'0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d', // WNEAR
|
|
110
|
+
'0x8BEc47865aDe3B172A928df8f990Bc7f2A3b9f79', // AURORA
|
|
111
|
+
'0xFa94348467f64D5A457F75F8bc40495D33c65aBB', // TRI
|
|
112
|
+
]
|
|
113
|
+
// could call RPC to get all the staking pools but it's not necessary for now
|
|
114
|
+
// export const ALL_STAKING_POOLS = [PlyUsdcPid];
|
|
115
|
+
// TODO: fix this
|
|
116
|
+
export const ALL_STAKING_POOLS = [];
|
|
96
117
|
export const INF = BN.from(2).pow(256).sub(1)
|
|
97
118
|
|
|
98
119
|
|
package/src/decimals.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const decimalRecords: Record<string, number> = {
|
|
2
2
|
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
|
|
3
|
-
'
|
|
3
|
+
'0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f': 18,
|
|
4
4
|
'0x3195949f267702723bc614cae037cdc8d1e94786': 8,
|
|
5
5
|
'0xfa94348467f64d5a457f75f8bc40495d33c65abb': 18,
|
|
6
6
|
'0x07f9f7f963c5cd2bbffd30ccfb964be114332e30': 24,
|
|
@@ -18,5 +18,7 @@ export const decimalRecords: Record<string, number> = {
|
|
|
18
18
|
'0xae4fac24dcdae0132c6d04f564dcf059616e9423': 8,
|
|
19
19
|
'0xce4166363e3a584dac84a47bcd3414b43efcdd1c': 8,
|
|
20
20
|
'0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
|
|
21
|
-
'0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24
|
|
21
|
+
'0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24,
|
|
22
|
+
'0x04ac48711bcdc45b4d223fb021e09da73c71095e': 18, // PULP
|
|
23
|
+
'0x37cae2b29c18e05ece60111fa01d3ca217046016': 18, // PLYUSDC
|
|
22
24
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { BigNumber as BN, Contract, providers, utils } from "ethers";
|
|
|
6
6
|
import { getQuery as getAuroraAPIQuery } from "./aurora-api-helpers";
|
|
7
7
|
import { decimalRecords } from "./decimals";
|
|
8
8
|
import { Address, NetworkConnection } from "./types";
|
|
9
|
+
import assert from 'assert';
|
|
9
10
|
|
|
10
11
|
export function formatObject(object: Object) {
|
|
11
12
|
return JSON.stringify(object, null, ' ');
|
|
@@ -32,7 +33,9 @@ export function validateAndParseAddress(address: Address): Address {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export function getDecimal(address: Address): number {
|
|
35
|
-
|
|
36
|
+
let addressLowercase = address.toLowerCase();
|
|
37
|
+
assert(decimalRecords[addressLowercase] != undefined, "Decimal not found for " + address);
|
|
38
|
+
return decimalRecords[addressLowercase];
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
export function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNumber, frequencyPerYear: number): BigNumber {
|
package/src/index.ts
CHANGED