@aurigami/sdk 1.3.4 → 1.3.5

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/README.md CHANGED
@@ -1 +1,7 @@
1
1
  # Aurigami SDK
2
+
3
+ # Testing
4
+
5
+ For test that does not require hardhat, run `yarn test test/path_to_test`.
6
+
7
+ For test that requires hardhat, run `yarn test-hardhat test-hardhat/path_to_test`.
@@ -1,14 +1,24 @@
1
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
1
2
  import { BlockchainEntity, BlockchainEntityRead } from "./BlockchainEntity";
2
- import { NetworkConnection } from "./types";
3
+ import { Address, NetworkConnection } from "./types";
4
+ import { AuriAirdrop } from "@aurigami/contracts/typechain";
5
+ import { TokenAmount } from "./tokenAmount";
3
6
  export declare class AirdropRead extends BlockchainEntityRead {
7
+ protected _airDrop: AuriAirdrop;
4
8
  private _whitelistedAddresses;
5
9
  private keepTrackers;
6
10
  constructor(networkConnection: NetworkConnection);
7
11
  countWhitelistedAddresses(): number;
8
12
  isWhitelisted(user: string): boolean;
9
13
  hasCompletedChallenge(user: string): Promise<boolean>;
14
+ getRedeemableReward(campaign: string, token: Address, user: Address): Promise<TokenAmount>;
15
+ }
16
+ export declare class AirdropReadWrite extends AirdropRead {
17
+ redeemMultiple(campaigns: string[], tokens: Address[]): Promise<TransactionResponse>;
18
+ redeemSingle(campaign: string, token: Address): Promise<TransactionResponse>;
10
19
  }
11
20
  export declare class Airdrop extends BlockchainEntity {
12
21
  constructor();
13
22
  read(networkConnection: NetworkConnection): AirdropRead;
23
+ readWrite(networkConnection: NetworkConnection): AirdropReadWrite;
14
24
  }
package/dist/helpers.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const isSameAddress: (address1: Address, address2: Address) => bo
7
7
  export declare const getCurrentTimestamp: () => number;
8
8
  export declare function validateAndParseAddress(address: Address): Address;
9
9
  export declare function getDecimal(address: Address): number;
10
+ export declare function getDecimalsViaContract(address: Address, provider: Provider): Promise<number>;
10
11
  export declare function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNumber, frequencyPerYear: number): BigNumber;
11
12
  export declare function getBlockTimestamp(provider: Provider, blockNumber: number): Promise<number>;
12
13
  export declare function getBlockBeforeTimestamp(provider: Provider, timestamp: number, startBlock?: number): Promise<number>;
@@ -8,6 +8,7 @@ var BigNumber = _interopDefault(require('bignumber.js'));
8
8
  var ethers = require('ethers');
9
9
  var utils = require('ethers/lib/utils');
10
10
  var abstractSigner = require('@ethersproject/abstract-signer');
11
+ var EIP20InterfaceABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json'));
11
12
  var AuErc20ABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json'));
12
13
  var AuETHABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json'));
13
14
  var ComptrollerABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json'));
@@ -18,6 +19,8 @@ var TokenLockABI = _interopDefault(require('@aurigami/contracts/artifacts/contra
18
19
  var AuriFairLaunchABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json'));
19
20
  var FaucetABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json'));
20
21
  var AuTokenABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuToken.sol/AuToken.json'));
22
+ var AuriAirdropABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json'));
23
+ var assert = _interopDefault(require('assert'));
21
24
 
22
25
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
23
26
  try {
@@ -963,7 +966,8 @@ var networkAddresses = {
963
966
  AURIFAIRLAUNCH: /*#__PURE__*/"0x9F9ceE911509abC6Af899c12ED625B0A6580D6e6".toLowerCase(),
964
967
  AURILENS: /*#__PURE__*/'0xC41a5C1625d492436600789469c1CE2eA20CEA6B'.toLowerCase(),
965
968
  TOKENLOCK: /*#__PURE__*/'0xDACC02a4Ff16Ea3c1515AdbfdCeb7B1F448B79c8'.toLowerCase(),
966
- ETHREPAYHELPER: /*#__PURE__*/"0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6".toLowerCase()
969
+ ETHREPAYHELPER: /*#__PURE__*/"0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6".toLowerCase(),
970
+ AURI_AIRDROP: /*#__PURE__*/"0x6C42aA5b128B62D6CCf357726D7d13F3888335EC".toLowerCase()
967
971
  },
968
972
  tokens: {
969
973
  AURORA: /*#__PURE__*/"0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
@@ -1004,7 +1008,8 @@ var decimalRecords = {
1004
1008
  '0x8888682e24dd4df7b7ff2b91fccb575737e433bf': 8,
1005
1009
  '0xae4fac24dcdae0132c6d04f564dcf059616e9423': 8,
1006
1010
  '0xce4166363e3a584dac84a47bcd3414b43efcdd1c': 8,
1007
- '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8
1011
+ '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
1012
+ '0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24
1008
1013
  };
1009
1014
 
1010
1015
  function formatObject(object) {
@@ -1029,6 +1034,40 @@ function validateAndParseAddress(address) {
1029
1034
  function getDecimal(address) {
1030
1035
  return decimalRecords[address.toLowerCase()];
1031
1036
  }
1037
+ function getDecimalsViaContract(_x, _x2) {
1038
+ return _getDecimalsViaContract.apply(this, arguments);
1039
+ }
1040
+
1041
+ function _getDecimalsViaContract() {
1042
+ _getDecimalsViaContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(address, provider) {
1043
+ var result, token;
1044
+ return runtime_1.wrap(function _callee$(_context) {
1045
+ while (1) {
1046
+ switch (_context.prev = _context.next) {
1047
+ case 0:
1048
+ result = getDecimal(address);
1049
+
1050
+ if (!result) {
1051
+ _context.next = 3;
1052
+ break;
1053
+ }
1054
+
1055
+ return _context.abrupt("return", result);
1056
+
1057
+ case 3:
1058
+ token = new ethers.Contract(address, EIP20InterfaceABI.abi, provider);
1059
+ return _context.abrupt("return", token.decimals());
1060
+
1061
+ case 5:
1062
+ case "end":
1063
+ return _context.stop();
1064
+ }
1065
+ }
1066
+ }, _callee);
1067
+ }));
1068
+ return _getDecimalsViaContract.apply(this, arguments);
1069
+ }
1070
+
1032
1071
  function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1033
1072
  if (totalStakeValue.lte(0)) {
1034
1073
  return new BigNumber('999999999');
@@ -1036,71 +1075,71 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
1036
1075
 
1037
1076
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
1038
1077
  }
1039
- function getBlockTimestamp(_x, _x2) {
1078
+ function getBlockTimestamp(_x3, _x4) {
1040
1079
  return _getBlockTimestamp.apply(this, arguments);
1041
1080
  }
1042
1081
 
1043
1082
  function _getBlockTimestamp() {
1044
- _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, blockNumber) {
1083
+ _getBlockTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, blockNumber) {
1045
1084
  var block;
1046
- return runtime_1.wrap(function _callee$(_context) {
1085
+ return runtime_1.wrap(function _callee2$(_context2) {
1047
1086
  while (1) {
1048
- switch (_context.prev = _context.next) {
1087
+ switch (_context2.prev = _context2.next) {
1049
1088
  case 0:
1050
- _context.next = 2;
1089
+ _context2.next = 2;
1051
1090
  return provider.getBlock(blockNumber);
1052
1091
 
1053
1092
  case 2:
1054
- block = _context.sent;
1055
- return _context.abrupt("return", block.timestamp);
1093
+ block = _context2.sent;
1094
+ return _context2.abrupt("return", block.timestamp);
1056
1095
 
1057
1096
  case 4:
1058
1097
  case "end":
1059
- return _context.stop();
1098
+ return _context2.stop();
1060
1099
  }
1061
1100
  }
1062
- }, _callee);
1101
+ }, _callee2);
1063
1102
  }));
1064
1103
  return _getBlockTimestamp.apply(this, arguments);
1065
1104
  }
1066
1105
 
1067
- function getBlockBeforeTimestamp(_x3, _x4, _x5) {
1106
+ function getBlockBeforeTimestamp(_x5, _x6, _x7) {
1068
1107
  return _getBlockBeforeTimestamp.apply(this, arguments);
1069
1108
  }
1070
1109
 
1071
1110
  function _getBlockBeforeTimestamp() {
1072
- _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, timestamp, startBlock) {
1111
+ _getBlockBeforeTimestamp = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider, timestamp, startBlock) {
1073
1112
  var blockThreshold, K, leftBlock, rightBlock, size, promises, i, blockTimestamps, nextLeftBlock, _i, _i2;
1074
1113
 
1075
- return runtime_1.wrap(function _callee2$(_context2) {
1114
+ return runtime_1.wrap(function _callee3$(_context3) {
1076
1115
  while (1) {
1077
- switch (_context2.prev = _context2.next) {
1116
+ switch (_context3.prev = _context3.next) {
1078
1117
  case 0:
1079
1118
  blockThreshold = 50 * 10;
1080
1119
  K = 8;
1081
1120
  leftBlock = startBlock || 1;
1082
- _context2.next = 5;
1121
+ _context3.next = 5;
1083
1122
  return provider.getBlockNumber();
1084
1123
 
1085
1124
  case 5:
1086
- rightBlock = _context2.sent;
1087
- _context2.next = 8;
1125
+ rightBlock = _context3.sent;
1126
+ _context3.next = 8;
1088
1127
  return getBlockTimestamp(provider, rightBlock);
1089
1128
 
1090
1129
  case 8:
1091
- _context2.t0 = _context2.sent;
1092
- _context2.t1 = timestamp;
1130
+ _context3.t0 = _context3.sent;
1131
+ _context3.t1 = timestamp;
1093
1132
 
1094
- if (!(_context2.t0 < _context2.t1)) {
1095
- _context2.next = 12;
1133
+ if (!(_context3.t0 < _context3.t1)) {
1134
+ _context3.next = 12;
1096
1135
  break;
1097
1136
  }
1098
1137
 
1099
- return _context2.abrupt("return", rightBlock);
1138
+ return _context3.abrupt("return", rightBlock);
1100
1139
 
1101
1140
  case 12:
1102
1141
  if (!(rightBlock - leftBlock >= blockThreshold)) {
1103
- _context2.next = 25;
1142
+ _context3.next = 25;
1104
1143
  break;
1105
1144
  }
1106
1145
 
@@ -1111,11 +1150,11 @@ function _getBlockBeforeTimestamp() {
1111
1150
  promises.push(getBlockTimestamp(provider, leftBlock + i * size));
1112
1151
  }
1113
1152
 
1114
- _context2.next = 18;
1153
+ _context3.next = 18;
1115
1154
  return Promise.all(promises);
1116
1155
 
1117
1156
  case 18:
1118
- blockTimestamps = _context2.sent;
1157
+ blockTimestamps = _context3.sent;
1119
1158
  nextLeftBlock = leftBlock;
1120
1159
 
1121
1160
  for (_i = 1; _i < K; _i++) {
@@ -1131,18 +1170,18 @@ function _getBlockBeforeTimestamp() {
1131
1170
  }
1132
1171
 
1133
1172
  leftBlock = nextLeftBlock;
1134
- _context2.next = 12;
1173
+ _context3.next = 12;
1135
1174
  break;
1136
1175
 
1137
1176
  case 25:
1138
- return _context2.abrupt("return", leftBlock);
1177
+ return _context3.abrupt("return", leftBlock);
1139
1178
 
1140
1179
  case 26:
1141
1180
  case "end":
1142
- return _context2.stop();
1181
+ return _context3.stop();
1143
1182
  }
1144
1183
  }
1145
- }, _callee2);
1184
+ }, _callee3);
1146
1185
  }));
1147
1186
  return _getBlockBeforeTimestamp.apply(this, arguments);
1148
1187
  }
@@ -106621,6 +106660,7 @@ var AirdropRead = /*#__PURE__*/function (_BlockchainEntityRead2) {
106621
106660
 
106622
106661
  _this2 = _BlockchainEntityRead2.call(this, networkConnection) || this;
106623
106662
  _this2.keepTrackers = [];
106663
+ _this2._airDrop = new ethers.Contract(networkAddresses.misc.AURI_AIRDROP, AuriAirdropABI.abi, networkConnection.provider);
106624
106664
  _this2._whitelistedAddresses = new Set(AIRDROP_WHITELIST_ADDRESSES.map(function (e) {
106625
106665
  return e.toLocaleLowerCase();
106626
106666
  }));
@@ -106726,8 +106766,106 @@ var AirdropRead = /*#__PURE__*/function (_BlockchainEntityRead2) {
106726
106766
  return hasCompletedChallenge;
106727
106767
  }();
106728
106768
 
106769
+ _proto2.getRedeemableReward = /*#__PURE__*/function () {
106770
+ var _getRedeemableReward = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(campaign, token, user) {
106771
+ var tokenInstance, rewards;
106772
+ return runtime_1.wrap(function _callee5$(_context5) {
106773
+ while (1) {
106774
+ switch (_context5.prev = _context5.next) {
106775
+ case 0:
106776
+ tokenInstance = new Token(token, getDecimal(token));
106777
+ _context5.next = 3;
106778
+ return this._airDrop.getRedeemableReward(ethers.utils.formatBytes32String(campaign), token, user);
106779
+
106780
+ case 3:
106781
+ rewards = _context5.sent;
106782
+ return _context5.abrupt("return", new TokenAmount(tokenInstance, rewards.toString()));
106783
+
106784
+ case 5:
106785
+ case "end":
106786
+ return _context5.stop();
106787
+ }
106788
+ }
106789
+ }, _callee5, this);
106790
+ }));
106791
+
106792
+ function getRedeemableReward(_x5, _x6, _x7) {
106793
+ return _getRedeemableReward.apply(this, arguments);
106794
+ }
106795
+
106796
+ return getRedeemableReward;
106797
+ }();
106798
+
106729
106799
  return AirdropRead;
106730
106800
  }(BlockchainEntityRead);
106801
+ var AirdropReadWrite = /*#__PURE__*/function (_AirdropRead) {
106802
+ _inheritsLoose(AirdropReadWrite, _AirdropRead);
106803
+
106804
+ function AirdropReadWrite() {
106805
+ return _AirdropRead.apply(this, arguments) || this;
106806
+ }
106807
+
106808
+ var _proto3 = AirdropReadWrite.prototype;
106809
+
106810
+ _proto3.redeemMultiple = /*#__PURE__*/function () {
106811
+ var _redeemMultiple = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(campaigns, tokens) {
106812
+ return runtime_1.wrap(function _callee6$(_context6) {
106813
+ while (1) {
106814
+ switch (_context6.prev = _context6.next) {
106815
+ case 0:
106816
+ assert(campaigns.length == tokens.length, "campaigns and tokens must have the same length");
106817
+ _context6.t0 = this._airDrop.connect(this._networkConnection.signer);
106818
+ _context6.t1 = campaigns.map(function (e) {
106819
+ return ethers.utils.formatBytes32String(e);
106820
+ });
106821
+ _context6.t2 = tokens;
106822
+ _context6.next = 6;
106823
+ return this._networkConnection.signer.getAddress();
106824
+
106825
+ case 6:
106826
+ _context6.t3 = _context6.sent;
106827
+ return _context6.abrupt("return", _context6.t0.redeem.call(_context6.t0, _context6.t1, _context6.t2, _context6.t3));
106828
+
106829
+ case 8:
106830
+ case "end":
106831
+ return _context6.stop();
106832
+ }
106833
+ }
106834
+ }, _callee6, this);
106835
+ }));
106836
+
106837
+ function redeemMultiple(_x8, _x9) {
106838
+ return _redeemMultiple.apply(this, arguments);
106839
+ }
106840
+
106841
+ return redeemMultiple;
106842
+ }();
106843
+
106844
+ _proto3.redeemSingle = /*#__PURE__*/function () {
106845
+ var _redeemSingle = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(campaign, token) {
106846
+ return runtime_1.wrap(function _callee7$(_context7) {
106847
+ while (1) {
106848
+ switch (_context7.prev = _context7.next) {
106849
+ case 0:
106850
+ return _context7.abrupt("return", this.redeemMultiple([campaign], [token]));
106851
+
106852
+ case 1:
106853
+ case "end":
106854
+ return _context7.stop();
106855
+ }
106856
+ }
106857
+ }, _callee7, this);
106858
+ }));
106859
+
106860
+ function redeemSingle(_x10, _x11) {
106861
+ return _redeemSingle.apply(this, arguments);
106862
+ }
106863
+
106864
+ return redeemSingle;
106865
+ }();
106866
+
106867
+ return AirdropReadWrite;
106868
+ }(AirdropRead);
106731
106869
  var Airdrop = /*#__PURE__*/function (_BlockchainEntity) {
106732
106870
  _inheritsLoose(Airdrop, _BlockchainEntity);
106733
106871
 
@@ -106735,12 +106873,16 @@ var Airdrop = /*#__PURE__*/function (_BlockchainEntity) {
106735
106873
  return _BlockchainEntity.call(this) || this;
106736
106874
  }
106737
106875
 
106738
- var _proto3 = Airdrop.prototype;
106876
+ var _proto4 = Airdrop.prototype;
106739
106877
 
106740
- _proto3.read = function read(networkConnection) {
106878
+ _proto4.read = function read(networkConnection) {
106741
106879
  return new AirdropRead(networkConnection);
106742
106880
  };
106743
106881
 
106882
+ _proto4.readWrite = function readWrite(networkConnection) {
106883
+ return new AirdropReadWrite(networkConnection);
106884
+ };
106885
+
106744
106886
  return Airdrop;
106745
106887
  }(BlockchainEntity);
106746
106888
 
@@ -106756,6 +106898,7 @@ exports.AURORA_CHAINID = AURORA_CHAINID;
106756
106898
  exports.AURPLYToken = AURPLYToken;
106757
106899
  exports.Airdrop = Airdrop;
106758
106900
  exports.AirdropRead = AirdropRead;
106901
+ exports.AirdropReadWrite = AirdropReadWrite;
106759
106902
  exports.AurPlyPid = AurPlyPid;
106760
106903
  exports.BORROW_LIMIT_BUFFER = BORROW_LIMIT_BUFFER;
106761
106904
  exports.BlockchainEntity = BlockchainEntity;
@@ -106804,6 +106947,7 @@ exports.getBlockBeforeTimestamp = getBlockBeforeTimestamp;
106804
106947
  exports.getBlockTimestamp = getBlockTimestamp;
106805
106948
  exports.getCurrentTimestamp = getCurrentTimestamp;
106806
106949
  exports.getDecimal = getDecimal;
106950
+ exports.getDecimalsViaContract = getDecimalsViaContract;
106807
106951
  exports.isSameAddress = isSameAddress;
106808
106952
  exports.networkAddresses = networkAddresses;
106809
106953
  exports.validateAndParseAddress = validateAndParseAddress;