@aurigami/sdk 1.13.1 → 1.15.0
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/ChangeLog.md +376 -0
- package/dist/SDK.d.ts +2 -0
- package/dist/helpers/helpers.d.ts +0 -1
- package/dist/helpers/notification-api.d.ts +2 -0
- package/dist/sdk.cjs.development.js +217 -79
- 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 +218 -79
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/.DS_Store +0 -0
- package/src/SDK.ts +35 -0
- package/src/consts/constants.ts +0 -1
- package/src/helpers/helpers.ts +19 -19
- package/src/helpers/notification-api.ts +22 -0
- package/src/helpers/priceFetcher.ts +2 -0
- package/src/interactors/MoneyMarket.ts +15 -14
- package/src/interactors/PlyGame.ts +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.15.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"@aurigami/contracts": "3.11.3",
|
|
66
66
|
"axios": "^0.26.1",
|
|
67
67
|
"bignumber.js": "^9.0.2",
|
|
68
|
+
"cache-decorator": "^0.1.6",
|
|
68
69
|
"ethers": "^5.6.4"
|
|
69
70
|
},
|
|
70
71
|
"jest": {
|
package/src/.DS_Store
ADDED
|
Binary file
|
package/src/SDK.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ALL_STAKING_POOLS } from './consts';
|
|
|
4
4
|
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
|
|
5
5
|
import { MiscRead, StakingRead, StakingReadWrite } from './interactors';
|
|
6
6
|
import * as types from './types';
|
|
7
|
+
import * as NotificationApi from './helpers/notification-api';
|
|
7
8
|
|
|
8
9
|
export class SdkRead extends BlockchainEntityRead {
|
|
9
10
|
protected env: AuriEnv;
|
|
@@ -101,6 +102,40 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
101
102
|
const miscRead = new MiscRead(this._networkConnection);
|
|
102
103
|
return miscRead.getNetApyWithIncentive(userAddress);
|
|
103
104
|
}
|
|
105
|
+
|
|
106
|
+
public async setUserNotificationSettings(
|
|
107
|
+
address: types.Address,
|
|
108
|
+
mail: string,
|
|
109
|
+
utilisation: number,
|
|
110
|
+
liquidation: boolean,
|
|
111
|
+
captchaResponse: string
|
|
112
|
+
) {
|
|
113
|
+
const body = {
|
|
114
|
+
address,
|
|
115
|
+
mail,
|
|
116
|
+
setting: {
|
|
117
|
+
utilisation,
|
|
118
|
+
liquidation,
|
|
119
|
+
},
|
|
120
|
+
captchaResponse,
|
|
121
|
+
};
|
|
122
|
+
const response = await NotificationApi.postApi('alert-setting/set', body);
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public async unsetUserNotificationSettings(address: types.Address, captchaResponse: string) {
|
|
127
|
+
const body = {
|
|
128
|
+
address,
|
|
129
|
+
mail: '',
|
|
130
|
+
setting: {
|
|
131
|
+
utilisation: null,
|
|
132
|
+
liquidation: false,
|
|
133
|
+
},
|
|
134
|
+
captchaResponse,
|
|
135
|
+
};
|
|
136
|
+
const response = await NotificationApi.postApi('alert-setting/set', body);
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
104
139
|
}
|
|
105
140
|
|
|
106
141
|
export class SdkReadWrite extends SdkRead {
|
package/src/consts/constants.ts
CHANGED
|
@@ -113,7 +113,6 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
export const DEPOSIT_ONLY_TOKENS = [
|
|
116
|
-
MAINNET_ADDRESSES.auTokens.STNEAR.toLowerCase(),
|
|
117
116
|
MAINNET_ADDRESSES.auTokens.AURORA.toLowerCase(),
|
|
118
117
|
MAINNET_ADDRESSES.auTokens.TRI.toLowerCase(),
|
|
119
118
|
MAINNET_ADDRESSES.auTokens.PLY.toLowerCase(),
|
package/src/helpers/helpers.ts
CHANGED
|
@@ -191,22 +191,22 @@ export function sortEvents<T extends Result>(events: TypedEvent<T>[]): TypedEven
|
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
export function Cache(cacheTimeout: number) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
194
|
+
// export function Cache(cacheTimeout: number) {
|
|
195
|
+
// return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
196
|
+
// const originalMethod = descriptor.value;
|
|
197
|
+
// let cache = new Map<string, any>();
|
|
198
|
+
// descriptor.value = function (...args: any[]) {
|
|
199
|
+
// let key = JSON.stringify(args);
|
|
200
|
+
// if (cache.has(key)) {
|
|
201
|
+
// let [timestamp, value] = cache.get(key);
|
|
202
|
+
// if (Date.now() - timestamp < cacheTimeout) {
|
|
203
|
+
// return value;
|
|
204
|
+
// }
|
|
205
|
+
// }
|
|
206
|
+
// let result = originalMethod.apply(this, args);
|
|
207
|
+
// cache.set(key, [Date.now(), result]);
|
|
208
|
+
// return result;
|
|
209
|
+
// };
|
|
210
|
+
// return descriptor;
|
|
211
|
+
// };
|
|
212
|
+
// }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const NOTIFICATION_API_END_POINT = 'https://api.aurigami.finance/notification/';
|
|
4
|
+
|
|
5
|
+
export async function getApi(url: string, params: Record<string, any> = {}): Promise<any> {
|
|
6
|
+
const resp = await axios.get(
|
|
7
|
+
NOTIFICATION_API_END_POINT + url + '?' + new URLSearchParams(params),
|
|
8
|
+
{
|
|
9
|
+
headers: { 'Content-Type': 'application/json' },
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return resp.data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function postApi(url: string, body: Record<string, any>): Promise<any> {
|
|
17
|
+
const resp = await axios.post(NOTIFICATION_API_END_POINT + url, body, {
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return resp.data;
|
|
22
|
+
}
|
|
@@ -24,6 +24,7 @@ export async function fetchPriceFromDefiLlamaAPI(id: string): Promise<BigNumber>
|
|
|
24
24
|
})
|
|
25
25
|
.catch((err: any) => {
|
|
26
26
|
console.log(`unable to fetch price from DefiLlama API: ${err}`);
|
|
27
|
+
console.error(err);
|
|
27
28
|
return 0;
|
|
28
29
|
});
|
|
29
30
|
return new BigNumber(price);
|
|
@@ -37,6 +38,7 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
|
|
|
37
38
|
})
|
|
38
39
|
.catch((err: any) => {
|
|
39
40
|
console.log(`Unable to fetch price from Coingecko API for ${id}`);
|
|
41
|
+
console.error(err);
|
|
40
42
|
return { usd: 0 };
|
|
41
43
|
});
|
|
42
44
|
|
|
@@ -22,7 +22,8 @@ import {
|
|
|
22
22
|
MoneyMarketDetails,
|
|
23
23
|
NetworkConnection,
|
|
24
24
|
} from '../types';
|
|
25
|
-
import {
|
|
25
|
+
import { getUnderlying } from '../helpers/helpers';
|
|
26
|
+
import { cache, CacheType } from 'cache-decorator';
|
|
26
27
|
|
|
27
28
|
type RewardSpeeds = {
|
|
28
29
|
plyRewardSupplySpeed: BN;
|
|
@@ -50,17 +51,17 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
50
51
|
this.underlying = new Token(underlyingAsset, helpers.getDecimal(underlyingAsset));
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
@
|
|
54
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
54
55
|
public async getUnderlyingPrice(): Promise<BigNumber> {
|
|
55
56
|
return fetchPrice(this.underlying.address, this._networkConnection.provider);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
@
|
|
59
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
59
60
|
public async getPlyPrice(): Promise<BigNumber> {
|
|
60
61
|
return fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
@
|
|
64
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
64
65
|
protected async getRewardSpeeds(): Promise<RewardSpeeds> {
|
|
65
66
|
var speeds = await this.env.auriLens.getRewardSpeeds(
|
|
66
67
|
this.env.comptroller.address,
|
|
@@ -69,12 +70,12 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
69
70
|
return speeds;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
@
|
|
73
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
73
74
|
public async getTotalTokenBorrowed(): Promise<TokenAmount> {
|
|
74
75
|
return new TokenAmount(this.underlying, (await this.auToken.totalBorrows()).toString());
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
@
|
|
78
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
78
79
|
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
79
80
|
const [totalBorrow, totalCash] = await Promise.all([
|
|
80
81
|
this.getTotalTokenBorrowed(),
|
|
@@ -88,7 +89,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
88
89
|
);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
@
|
|
92
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
92
93
|
public async getDepositAPY(): Promise<BigNumber> {
|
|
93
94
|
const supplyRatePerTimestamp = await this.auToken.supplyRatePerTimestamp();
|
|
94
95
|
const supplyRatePerDay = new BigNumber(supplyRatePerTimestamp.toString())
|
|
@@ -98,7 +99,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
98
99
|
return new BigNumber(supplyRatePerDay.plus(1)).pow(365).minus(1);
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
@
|
|
102
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
102
103
|
public async getBorrowAPY(): Promise<BigNumber> {
|
|
103
104
|
const borrowRatePerTimestamp = await this.auToken.borrowRatePerTimestamp();
|
|
104
105
|
const borrowRatePerDay = new BigNumber(borrowRatePerTimestamp.toString())
|
|
@@ -107,14 +108,14 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
107
108
|
return new BigNumber(borrowRatePerDay.plus(1)).pow(365).minus(1);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
@
|
|
111
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
111
112
|
public async getCollateralRatio(): Promise<BigNumber> {
|
|
112
113
|
return this.env.comptroller.markets(this.auToken.address).then((res: any) => {
|
|
113
114
|
return new BigNumber(res.collateralFactorMantissa.toString()).div(helpers.decimalFactor(18));
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
@
|
|
118
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
118
119
|
public async getBorrowPlyAPY(): Promise<BigNumber> {
|
|
119
120
|
const [totalBorrowed, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
|
|
120
121
|
this.getTotalTokenBorrowed(),
|
|
@@ -132,7 +133,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
132
133
|
);
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
@
|
|
136
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
136
137
|
public async getDepositPlyAPY(): Promise<BigNumber> {
|
|
137
138
|
const [totalDeposited, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
|
|
138
139
|
this.getTotalTokenDeposited(),
|
|
@@ -150,7 +151,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
150
151
|
);
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
@
|
|
154
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
154
155
|
public async getDepositNearAPY(): Promise<BigNumber> {
|
|
155
156
|
const [totalDeposited, underlyingPrice] = await Promise.all([
|
|
156
157
|
this.getTotalTokenDeposited(),
|
|
@@ -164,7 +165,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
164
165
|
return depositNEARApy;
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
@
|
|
168
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
168
169
|
public async getBorrowNearAPY(): Promise<BigNumber> {
|
|
169
170
|
const [totalBorrowed, underlyingPrice] = await Promise.all([
|
|
170
171
|
this.getTotalTokenBorrowed(),
|
|
@@ -178,7 +179,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
178
179
|
return borrowNEARApy;
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
@
|
|
182
|
+
@cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
|
|
182
183
|
public async getDepositMetaAPY(): Promise<BigNumber> {
|
|
183
184
|
const [totalDeposited, underlyingPrice] = await Promise.all([
|
|
184
185
|
this.getTotalTokenDeposited(),
|