@aurigami/sdk 1.6.10 → 1.7.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.
@@ -24,6 +24,13 @@ export declare class ReferralRead extends BlockchainEntityRead {
24
24
  * Get owner of a referral code, returns zero address if not found.
25
25
  */
26
26
  getReferralCodeOwner(code: string): Promise<Address>;
27
+ /**
28
+ * Get referrals of a user, sorted descending by timestamp.
29
+ */
30
+ getReferralsList(userAddr: Address): Promise<{
31
+ user: string;
32
+ timestamp: number;
33
+ }[]>;
27
34
  }
28
35
  export declare class ReferralReadWrite extends ReferralRead {
29
36
  /**
@@ -0,0 +1,13 @@
1
+ export declare function getApi(url: string, params?: Record<string, any>): Promise<any>;
2
+ export declare type MetaApiResponse = {
3
+ totalItems: number;
4
+ itemCount: number;
5
+ itemsPerPage: number;
6
+ totalPages: number;
7
+ currentPage: number;
8
+ };
9
+ export declare type PaginagedApiResponse<T> = {
10
+ items: T[];
11
+ meta: MetaApiResponse;
12
+ };
13
+ export declare function getPaginatedApi(url: string, params?: Record<string, any>, page?: number, pageSize?: number): Promise<PaginagedApiResponse<any>>;
@@ -1,3 +1,4 @@
1
+ export * from './aurigami-api';
1
2
  export * from './aurora-api-helpers';
2
3
  export * from './helpers';
3
4
  export * from './priceFetcher';
@@ -1343,6 +1343,91 @@ var dummyUserMarketDetails = {
1343
1343
  underlyingPrice: '1'
1344
1344
  };
1345
1345
 
1346
+ var AURIGAMI_API_END_POINT = 'https://api.aurigami.finance/app/';
1347
+ function getApi(_x, _x2) {
1348
+ return _getApi.apply(this, arguments);
1349
+ }
1350
+
1351
+ function _getApi() {
1352
+ _getApi = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(url, params) {
1353
+ var resp;
1354
+ return runtime_1.wrap(function _callee$(_context) {
1355
+ while (1) {
1356
+ switch (_context.prev = _context.next) {
1357
+ case 0:
1358
+ if (params === void 0) {
1359
+ params = {};
1360
+ }
1361
+
1362
+ _context.next = 3;
1363
+ return axios.get(AURIGAMI_API_END_POINT + url + '?' + new URLSearchParams(params), {
1364
+ headers: {
1365
+ 'Content-Type': 'application/json'
1366
+ }
1367
+ });
1368
+
1369
+ case 3:
1370
+ resp = _context.sent;
1371
+ return _context.abrupt("return", resp.data);
1372
+
1373
+ case 5:
1374
+ case "end":
1375
+ return _context.stop();
1376
+ }
1377
+ }
1378
+ }, _callee);
1379
+ }));
1380
+ return _getApi.apply(this, arguments);
1381
+ }
1382
+
1383
+ function getPaginatedApi(_x3, _x4, _x5, _x6) {
1384
+ return _getPaginatedApi.apply(this, arguments);
1385
+ }
1386
+
1387
+ function _getPaginatedApi() {
1388
+ _getPaginatedApi = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(url, params, page, pageSize) {
1389
+ var resp;
1390
+ return runtime_1.wrap(function _callee2$(_context2) {
1391
+ while (1) {
1392
+ switch (_context2.prev = _context2.next) {
1393
+ case 0:
1394
+ if (params === void 0) {
1395
+ params = {};
1396
+ }
1397
+
1398
+ if (page === void 0) {
1399
+ page = 1;
1400
+ }
1401
+
1402
+ if (pageSize === void 0) {
1403
+ pageSize = 50;
1404
+ }
1405
+
1406
+ params = _extends({}, params, {
1407
+ page: page,
1408
+ limit: pageSize
1409
+ });
1410
+ _context2.next = 6;
1411
+ return axios.get(AURIGAMI_API_END_POINT + url + '?' + new URLSearchParams(params), {
1412
+ headers: {
1413
+ 'Content-Type': 'application/json'
1414
+ }
1415
+ });
1416
+
1417
+ case 6:
1418
+ resp = _context2.sent;
1419
+ return _context2.abrupt("return", resp.data);
1420
+
1421
+ case 8:
1422
+ case "end":
1423
+ return _context2.stop();
1424
+ }
1425
+ }
1426
+ }, _callee2);
1427
+ }));
1428
+ return _getPaginatedApi.apply(this, arguments);
1429
+ }
1430
+
1346
1431
  function fetchPriceFromCoingeckoAPI(_x) {
1347
1432
  return _fetchPriceFromCoingeckoAPI.apply(this, arguments);
1348
1433
  }
@@ -2038,6 +2123,8 @@ var TransferEventQuery = /*#__PURE__*/function (_BlockchainEntityRead) {
2038
2123
 
2039
2124
  var helpers = {
2040
2125
  __proto__: null,
2126
+ getApi: getApi,
2127
+ getPaginatedApi: getPaginatedApi,
2041
2128
  getQuery: getQuery,
2042
2129
  assert: assert,
2043
2130
  formatObject: formatObject,
@@ -3976,14 +4063,14 @@ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
3976
4063
  var _sneakAccounts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(accounts, tokenAddresses) {
3977
4064
  var _this3 = this;
3978
4065
 
3979
- var _1E18, _1E9, oracle, tokens, prices, exrate, res, _iterator2, _step2, addr, infos, _i, snapshot, bal, bor, balR, borR;
4066
+ var _1E18, dust, oracle, tokens, prices, exrate, res, _iterator2, _step2, addr, infos, _i, snapshot, bal, bor, balR, borR;
3980
4067
 
3981
4068
  return runtime_1.wrap(function _callee5$(_context5) {
3982
4069
  while (1) {
3983
4070
  switch (_context5.prev = _context5.next) {
3984
4071
  case 0:
3985
4072
  _1E18 = ethers.BigNumber.from(10).pow(18);
3986
- _1E9 = ethers.BigNumber.from(10).pow(9);
4073
+ dust = new BigNumber(0.1);
3987
4074
  oracle = this.env.getContract(networkAddresses.misc.oracle, AuriOracleABI.abi);
3988
4075
  tokens = tokenAddresses.map(function (addr) {
3989
4076
  return _this3.env.getContract(addr, AuTokenABI.abi);
@@ -4024,10 +4111,10 @@ var MiscRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4024
4111
  snapshot = _context5.sent;
4025
4112
  bal = snapshot[0].mul(exrate[_i]).div(_1E18).mul(prices[_i]).div(_1E18);
4026
4113
  bor = snapshot[1].mul(prices[_i]).div(_1E18);
4027
- balR = bal.div(_1E9).toNumber() / Math.pow(10, 9);
4028
- borR = bor.div(_1E9).toNumber() / Math.pow(10, 9);
4114
+ balR = new BigNumber(bal.toString()).dividedBy(_1E18.toString());
4115
+ borR = new BigNumber(bor.toString()).dividedBy(_1E18.toString());
4029
4116
 
4030
- if (!(balR < 0.1 || borR < 0.1)) {
4117
+ if (!(balR.lt(dust) || borR.lt(dust))) {
4031
4118
  _context5.next = 26;
4032
4119
  break;
4033
4120
  }
@@ -4209,6 +4296,49 @@ var ReferralRead = /*#__PURE__*/function (_BlockchainEntityRead) {
4209
4296
  }
4210
4297
 
4211
4298
  return getReferralCodeOwner;
4299
+ }()
4300
+ /**
4301
+ * Get referrals of a user, sorted descending by timestamp.
4302
+ */
4303
+ ;
4304
+
4305
+ _proto.getReferralsList =
4306
+ /*#__PURE__*/
4307
+ function () {
4308
+ var _getReferralsList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(userAddr) {
4309
+ var result, items;
4310
+ return runtime_1.wrap(function _callee4$(_context4) {
4311
+ while (1) {
4312
+ switch (_context4.prev = _context4.next) {
4313
+ case 0:
4314
+ _context4.next = 2;
4315
+ return getPaginatedApi('/referral/list', {
4316
+ address: userAddr
4317
+ });
4318
+
4319
+ case 2:
4320
+ result = _context4.sent;
4321
+ items = result.items.map(function (item) {
4322
+ return {
4323
+ user: item.user,
4324
+ timestamp: item.blockNumber
4325
+ };
4326
+ });
4327
+ return _context4.abrupt("return", items);
4328
+
4329
+ case 5:
4330
+ case "end":
4331
+ return _context4.stop();
4332
+ }
4333
+ }
4334
+ }, _callee4);
4335
+ }));
4336
+
4337
+ function getReferralsList(_x4) {
4338
+ return _getReferralsList.apply(this, arguments);
4339
+ }
4340
+
4341
+ return getReferralsList;
4212
4342
  }();
4213
4343
 
4214
4344
  return ReferralRead;
@@ -4230,21 +4360,21 @@ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
4230
4360
  _proto2.registerNewReferralCode =
4231
4361
  /*#__PURE__*/
4232
4362
  function () {
4233
- var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
4363
+ var _registerNewReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
4234
4364
  var referralCode;
4235
- return runtime_1.wrap(function _callee4$(_context4) {
4365
+ return runtime_1.wrap(function _callee5$(_context5) {
4236
4366
  while (1) {
4237
- switch (_context4.prev = _context4.next) {
4367
+ switch (_context5.prev = _context5.next) {
4238
4368
  case 0:
4239
4369
  referralCode = ethers.ethers.utils.formatBytes32String(this.generateReferralCode());
4240
- return _context4.abrupt("return", this.referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
4370
+ return _context5.abrupt("return", this.referral.connect(this._networkConnection.signer).registerNewUserReferralCode(referralCode));
4241
4371
 
4242
4372
  case 2:
4243
4373
  case "end":
4244
- return _context4.stop();
4374
+ return _context5.stop();
4245
4375
  }
4246
4376
  }
4247
- }, _callee4, this);
4377
+ }, _callee5, this);
4248
4378
  }));
4249
4379
 
4250
4380
  function registerNewReferralCode() {
@@ -4261,24 +4391,24 @@ var ReferralReadWrite = /*#__PURE__*/function (_ReferralRead) {
4261
4391
  _proto2.useReferralCode =
4262
4392
  /*#__PURE__*/
4263
4393
  function () {
4264
- var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(code) {
4394
+ var _useReferralCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(code) {
4265
4395
  var referralCode;
4266
- return runtime_1.wrap(function _callee5$(_context5) {
4396
+ return runtime_1.wrap(function _callee6$(_context6) {
4267
4397
  while (1) {
4268
- switch (_context5.prev = _context5.next) {
4398
+ switch (_context6.prev = _context6.next) {
4269
4399
  case 0:
4270
4400
  referralCode = ethers.ethers.utils.formatBytes32String(code);
4271
- return _context5.abrupt("return", this.referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
4401
+ return _context6.abrupt("return", this.referral.connect(this._networkConnection.signer).registerReferralCodeUsed(referralCode));
4272
4402
 
4273
4403
  case 2:
4274
4404
  case "end":
4275
- return _context5.stop();
4405
+ return _context6.stop();
4276
4406
  }
4277
4407
  }
4278
- }, _callee5, this);
4408
+ }, _callee6, this);
4279
4409
  }));
4280
4410
 
4281
- function useReferralCode(_x4) {
4411
+ function useReferralCode(_x5) {
4282
4412
  return _useReferralCode.apply(this, arguments);
4283
4413
  }
4284
4414
 
@@ -4793,10 +4923,12 @@ exports.fetchToken0PriceByLP = fetchToken0PriceByLP;
4793
4923
  exports.fetchUnderlyingTokensPrices = fetchUnderlyingTokensPrices;
4794
4924
  exports.fetchValuation = fetchValuation;
4795
4925
  exports.formatObject = formatObject;
4926
+ exports.getApi = getApi;
4796
4927
  exports.getBlockBeforeTimestamp = getBlockBeforeTimestamp;
4797
4928
  exports.getBlockTimestamp = getBlockTimestamp;
4798
4929
  exports.getCurrentTimestamp = getCurrentTimestamp;
4799
4930
  exports.getDecimal = getDecimal;
4931
+ exports.getPaginatedApi = getPaginatedApi;
4800
4932
  exports.getQuery = getQuery;
4801
4933
  exports.getSymbol = getSymbol;
4802
4934
  exports.isSameAddress = isSameAddress;