@snapshot-labs/snapshot.js 0.2.2 → 0.2.6

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.
Files changed (287) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/plugins/charts/index.d.ts +5 -0
  5. package/dist/plugins/commentBox/index.d.ts +5 -0
  6. package/dist/plugins/index.d.ts +4 -0
  7. package/dist/rollup.cjs.config.dev.js +43 -0
  8. package/dist/rollup.config.dev.js +75 -0
  9. package/dist/sign/eip1271.d.ts +1 -1
  10. package/dist/sign/index.d.ts +2 -2
  11. package/dist/snapshot.cjs.js +73 -34
  12. package/dist/snapshot.esm.js +73 -34
  13. package/dist/snapshot.min.js +1 -1
  14. package/dist/strategies/aave-governance-power/index.d.ts +3 -0
  15. package/dist/strategies/aavegotchi/index.d.ts +6 -0
  16. package/dist/strategies/aavegotchi-agip/index.d.ts +3 -0
  17. package/dist/strategies/apescape/index.d.ts +6 -0
  18. package/dist/strategies/api/index.d.ts +6 -0
  19. package/dist/strategies/avn-balance-of-staked/index.d.ts +3 -0
  20. package/dist/strategies/badgeth/index.d.ts +3 -0
  21. package/dist/strategies/balance-of-with-min/index.d.ts +3 -0
  22. package/dist/strategies/balance-of-with-thresholds/index.d.ts +25 -0
  23. package/dist/strategies/balancer/index.d.ts +3 -0
  24. package/dist/strategies/balancer-delegation/index.d.ts +6 -0
  25. package/dist/strategies/balancer-smart-pool/index.d.ts +6 -0
  26. package/dist/strategies/balancer-unipool/index.d.ts +6 -0
  27. package/dist/strategies/brightid/index.d.ts +6 -0
  28. package/dist/strategies/cake/index.d.ts +3 -0
  29. package/dist/strategies/celer-sgn-delegation/index.d.ts +3 -0
  30. package/dist/strategies/comp-like-votes/index.d.ts +6 -0
  31. package/dist/strategies/contract-call/index.d.ts +6 -0
  32. package/dist/strategies/cream/index.d.ts +3 -0
  33. package/dist/strategies/ctoken/index.d.ts +3 -0
  34. package/dist/strategies/curio-cards-erc20-weighted/index.d.ts +3 -0
  35. package/dist/strategies/decentraland-estate-size/index.d.ts +3 -0
  36. package/dist/strategies/defidollar/index.d.ts +3 -0
  37. package/dist/strategies/delegation/index.d.ts +6 -0
  38. package/dist/strategies/dittomoney/index.d.ts +3 -0
  39. package/dist/strategies/ens-domains-owned/index.d.ts +3 -0
  40. package/dist/strategies/ens-reverse-record/index.d.ts +6 -0
  41. package/dist/strategies/erc1155-all-balances-of/index.d.ts +6 -0
  42. package/dist/strategies/erc1155-balance-of/index.d.ts +6 -0
  43. package/dist/strategies/erc1155-balance-of-cv/index.d.ts +6 -0
  44. package/dist/strategies/erc20-balance-of/index.d.ts +3 -0
  45. package/dist/strategies/erc20-balance-of-coeff/index.d.ts +3 -0
  46. package/dist/strategies/erc20-balance-of-cv/index.d.ts +6 -0
  47. package/dist/strategies/erc20-balance-of-delegation/index.d.ts +6 -0
  48. package/dist/strategies/erc20-balance-of-fixed-total/index.d.ts +6 -0
  49. package/dist/strategies/erc20-balance-of-quadratic-delegation/index.d.ts +6 -0
  50. package/dist/strategies/erc20-price/index.d.ts +3 -0
  51. package/dist/strategies/erc20-received/index.d.ts +10 -0
  52. package/dist/strategies/erc20-with-balance/index.d.ts +3 -0
  53. package/dist/strategies/erc721/index.d.ts +6 -0
  54. package/dist/strategies/erc721-enumerable/index.d.ts +3 -0
  55. package/dist/strategies/erc721-with-multiplier/index.d.ts +6 -0
  56. package/dist/strategies/erc721-with-tokenid/index.d.ts +21 -0
  57. package/dist/strategies/esd/index.d.ts +3 -0
  58. package/dist/strategies/esd-delegation/index.d.ts +6 -0
  59. package/dist/strategies/eth-balance/index.d.ts +6 -0
  60. package/dist/strategies/eth-philanthropy/index.d.ts +6 -0
  61. package/dist/strategies/eth-received/ElasticSearchTxResult.d.ts +71 -0
  62. package/dist/strategies/eth-received/index.d.ts +7 -0
  63. package/dist/strategies/eth-wallet-age/index.d.ts +3 -0
  64. package/dist/strategies/eth-with-balance/index.d.ts +3 -0
  65. package/dist/strategies/flashstake/index.d.ts +3 -0
  66. package/dist/strategies/frax-finance/index.d.ts +3 -0
  67. package/dist/strategies/governor-alpha/index.d.ts +6 -0
  68. package/dist/strategies/hopr-uni-lp-farm/index.d.ts +3 -0
  69. package/dist/strategies/ilv/index.d.ts +6 -0
  70. package/dist/strategies/impossible-finance/index.d.ts +6 -0
  71. package/dist/strategies/index.d.ts +243 -0
  72. package/dist/strategies/infinityprotocol-liquidity-pools/index.d.ts +3 -0
  73. package/dist/strategies/inverse-xinv/index.d.ts +6 -0
  74. package/dist/strategies/iotex-balance/index.d.ts +3 -0
  75. package/dist/strategies/iotex-staked-balance/index.d.ts +3 -0
  76. package/dist/strategies/liftkitchen/index.d.ts +3 -0
  77. package/dist/strategies/maker-ds-chief/index.d.ts +6 -0
  78. package/dist/strategies/masterchef/index.d.ts +3 -0
  79. package/dist/strategies/masterchef-pool-balance/index.d.ts +3 -0
  80. package/dist/strategies/masterchef-pool-balance-price/index.d.ts +6 -0
  81. package/dist/strategies/mithcash/index.d.ts +3 -0
  82. package/dist/strategies/modefi/index.d.ts +6 -0
  83. package/dist/strategies/modefi-staking/index.d.ts +6 -0
  84. package/dist/strategies/moloch/index.d.ts +6 -0
  85. package/dist/strategies/moloch-all/index.d.ts +6 -0
  86. package/dist/strategies/moloch-loot/index.d.ts +6 -0
  87. package/dist/strategies/multichain/index.d.ts +3 -0
  88. package/dist/strategies/multisig-owners/index.d.ts +6 -0
  89. package/dist/strategies/mushrooms/index.d.ts +6 -0
  90. package/dist/strategies/niu-staked/index.d.ts +6 -0
  91. package/dist/strategies/ocean-marketplace/index.d.ts +8 -0
  92. package/dist/strategies/ocean-marketplace/oceanUtils.d.ts +2 -0
  93. package/dist/strategies/ogn/index.d.ts +3 -0
  94. package/dist/strategies/opium/index.d.ts +3 -0
  95. package/dist/strategies/pagination/index.d.ts +3 -0
  96. package/dist/strategies/pancake/index.d.ts +6 -0
  97. package/dist/strategies/pepemon/index.d.ts +6 -0
  98. package/dist/strategies/piedao/index.d.ts +3 -0
  99. package/dist/strategies/planet-finance/index.d.ts +4 -0
  100. package/dist/strategies/pob-hash/index.d.ts +9 -0
  101. package/dist/strategies/rebased/index.d.ts +3 -0
  102. package/dist/strategies/ren-nodes/index.d.ts +3 -0
  103. package/dist/strategies/rnbw-balance/index.d.ts +3 -0
  104. package/dist/strategies/ruler-staked-lp/index.d.ts +6 -0
  105. package/dist/strategies/ruler-staked-token/index.d.ts +6 -0
  106. package/dist/strategies/saffron-finance/index.d.ts +6 -0
  107. package/dist/strategies/spookyswap/index.d.ts +6 -0
  108. package/dist/strategies/stablexswap/index.d.ts +6 -0
  109. package/dist/strategies/staked-keep/index.d.ts +3 -0
  110. package/dist/strategies/staked-uniswap/index.d.ts +6 -0
  111. package/dist/strategies/strategiesFull.d.ts +245 -0
  112. package/dist/strategies/sushiswap/index.d.ts +3 -0
  113. package/dist/strategies/synthetix/index.d.ts +3 -0
  114. package/dist/strategies/the-graph/baseStrategy.d.ts +4 -0
  115. package/dist/strategies/the-graph/graphUtils.d.ts +12 -0
  116. package/dist/strategies/the-graph/tokenLockWallets.d.ts +9 -0
  117. package/dist/strategies/the-graph-balance/balances.d.ts +2 -0
  118. package/dist/strategies/the-graph-balance/index.d.ts +6 -0
  119. package/dist/strategies/the-graph-delegation/delegators.d.ts +2 -0
  120. package/dist/strategies/the-graph-delegation/index.d.ts +6 -0
  121. package/dist/strategies/the-graph-indexing/index.d.ts +6 -0
  122. package/dist/strategies/the-graph-indexing/indexers.d.ts +2 -0
  123. package/dist/strategies/ticket/index.d.ts +6 -0
  124. package/dist/strategies/ticket-validity/index.d.ts +3 -0
  125. package/dist/strategies/tokenlon/index.d.ts +3 -0
  126. package/dist/strategies/tomb-finance/index.d.ts +6 -0
  127. package/dist/strategies/total-axion-shares/index.d.ts +3 -0
  128. package/dist/strategies/tranche-staking/index.d.ts +6 -0
  129. package/dist/strategies/tranche-staking-lp/index.d.ts +6 -0
  130. package/dist/strategies/tranche-staking-slice/index.d.ts +3 -0
  131. package/dist/strategies/typhoon/index.d.ts +3 -0
  132. package/dist/strategies/uni/index.d.ts +6 -0
  133. package/dist/strategies/unipool-same-token/index.d.ts +6 -0
  134. package/dist/strategies/unipool-univ2-lp/index.d.ts +6 -0
  135. package/dist/strategies/uniswap/index.d.ts +3 -0
  136. package/dist/strategies/whitelist/index.d.ts +6 -0
  137. package/dist/strategies/work/index.d.ts +6 -0
  138. package/dist/strategies/xcover/index.d.ts +6 -0
  139. package/dist/strategies/xdai-easy-staking/index.d.ts +3 -0
  140. package/dist/strategies/xdai-easy-staking/utils.d.ts +3 -0
  141. package/dist/strategies/xdai-posdao-staking/index.d.ts +3 -0
  142. package/dist/strategies/xdai-stake-delegation/index.d.ts +6 -0
  143. package/dist/strategies/xdai-stake-holders/index.d.ts +3 -0
  144. package/dist/strategies/xdai-stakers-and-holders/index.d.ts +3 -0
  145. package/dist/strategies/xrc20-balance-of/index.d.ts +3 -0
  146. package/dist/strategies/xseen/index.d.ts +6 -0
  147. package/dist/strategies/yearn-vault/index.d.ts +3 -0
  148. package/dist/strategies/zrx-voting-power/index.d.ts +3 -0
  149. package/dist/utils/contentHash.d.ts +28 -0
  150. package/package.json +2 -2
  151. package/src/client.ts +0 -0
  152. package/src/dist/index.js +14 -0
  153. package/src/dist/utils.js +291 -0
  154. package/src/networks/{fuse.png → 122.png} +0 -0
  155. package/src/networks/43114.png +0 -0
  156. package/src/networks.json +2 -2
  157. package/src/plugins/charts/index.ts +5 -0
  158. package/src/plugins/charts/logo.png +0 -0
  159. package/src/plugins/commentBox/index.ts +5 -0
  160. package/src/plugins/commentBox/logo.png +0 -0
  161. package/src/plugins/index.ts +5 -1
  162. package/src/plugins/safeSnap/dist/index.js +585 -0
  163. package/src/plugins/safeSnap/index.ts +22 -7
  164. package/src/sign/eip1271.ts +2 -2
  165. package/src/sign/index.ts +9 -5
  166. package/src/strategies/aave-governance-power/dist/index.js +110 -0
  167. package/src/strategies/aavegotchi/dist/index.js +156 -0
  168. package/src/strategies/aavegotchi-agip/dist/index.js +168 -0
  169. package/src/strategies/apescape/dist/index.js +164 -0
  170. package/src/strategies/api/dist/index.js +76 -0
  171. package/src/strategies/avn-balance-of-staked/dist/index.js +173 -0
  172. package/src/strategies/badgeth/dist/index.js +86 -0
  173. package/src/strategies/balance-of-with-min/dist/index.js +64 -0
  174. package/src/strategies/balance-of-with-thresholds/dist/index.js +73 -0
  175. package/src/strategies/balancer/dist/index.js +121 -0
  176. package/src/strategies/balancer-delegation/dist/index.js +62 -0
  177. package/src/strategies/balancer-smart-pool/dist/index.js +85 -0
  178. package/src/strategies/balancer-unipool/dist/index.js +141 -0
  179. package/src/strategies/brightid/dist/index.js +69 -0
  180. package/src/strategies/cake/dist/index.js +146 -0
  181. package/src/strategies/celer-sgn-delegation/dist/index.js +199 -0
  182. package/src/strategies/comp-like-votes/dist/index.js +91 -0
  183. package/src/strategies/contract-call/dist/index.js +76 -0
  184. package/src/strategies/cream/dist/index.js +310 -0
  185. package/src/strategies/ctoken/dist/index.js +145 -0
  186. package/src/strategies/curio-cards-erc20-weighted/dist/index.js +188 -0
  187. package/src/strategies/decentraland-estate-size/dist/index.js +101 -0
  188. package/src/strategies/defidollar/dist/index.js +106 -0
  189. package/src/strategies/delegation/dist/index.js +71 -0
  190. package/src/strategies/dist/index.js +248 -0
  191. package/src/strategies/dist/strategiesFull.js +246 -0
  192. package/src/strategies/dittomoney/dist/index.js +167 -0
  193. package/src/strategies/ens-domains-owned/dist/index.js +105 -0
  194. package/src/strategies/ens-reverse-record/dist/index.js +98 -0
  195. package/src/strategies/erc1155-all-balances-of/dist/index.js +99 -0
  196. package/src/strategies/erc1155-balance-of/dist/index.js +94 -0
  197. package/src/strategies/erc1155-balance-of-cv/dist/index.js +58 -0
  198. package/src/strategies/erc20-balance-of/dist/index.js +76 -0
  199. package/src/strategies/erc20-balance-of-delegation/dist/index.js +73 -0
  200. package/src/strategies/erc20-balance-of-quadratic-delegation/dist/index.js +75 -0
  201. package/src/strategies/erc20-price/dist/index.js +107 -0
  202. package/src/strategies/erc20-received/dist/index.js +166 -0
  203. package/src/strategies/erc20-with-balance/dist/index.js +61 -0
  204. package/src/strategies/erc721/dist/index.js +69 -0
  205. package/src/strategies/erc721-enumerable/dist/index.js +57 -0
  206. package/src/strategies/erc721-with-multiplier/dist/index.js +70 -0
  207. package/src/strategies/erc721-with-tokenid/dist/index.js +68 -0
  208. package/src/strategies/esd/dist/index.js +125 -0
  209. package/src/strategies/esd-delegation/dist/index.js +73 -0
  210. package/src/strategies/eth-balance/dist/index.js +72 -0
  211. package/src/strategies/eth-philanthropy/dist/index.js +81 -0
  212. package/src/strategies/eth-received/dist/index.js +127 -0
  213. package/src/strategies/eth-wallet-age/dist/index.js +126 -0
  214. package/src/strategies/eth-with-balance/dist/index.js +63 -0
  215. package/src/strategies/flashstake/dist/index.js +138 -0
  216. package/src/strategies/frax-finance/dist/index.js +236 -0
  217. package/src/strategies/governor-alpha/dist/index.js +71 -0
  218. package/src/strategies/hopr-uni-lp-farm/dist/index.js +232 -0
  219. package/src/strategies/ilv/dist/index.js +58 -0
  220. package/src/strategies/impossible-finance/dist/index.js +126 -0
  221. package/src/strategies/infinityprotocol-liquidity-pools/dist/index.js +120 -0
  222. package/src/strategies/inverse-xinv/dist/index.js +76 -0
  223. package/src/strategies/iotex-balance/dist/index.js +82 -0
  224. package/src/strategies/iotex-staked-balance/dist/index.js +79 -0
  225. package/src/strategies/liftkitchen/dist/index.js +167 -0
  226. package/src/strategies/masterchef/dist/index.js +183 -0
  227. package/src/strategies/masterchef-pool-balance/dist/index.js +190 -0
  228. package/src/strategies/masterchef-pool-balance-price/dist/index.js +442 -0
  229. package/src/strategies/mithcash/dist/index.js +133 -0
  230. package/src/strategies/modefi/dist/index.js +120 -0
  231. package/src/strategies/modefi-staking/dist/index.js +115 -0
  232. package/src/strategies/moloch-all/dist/index.js +154 -0
  233. package/src/strategies/moloch-loot/dist/index.js +153 -0
  234. package/src/strategies/multichain/dist/index.js +149 -0
  235. package/src/strategies/multisig-owners/dist/index.js +85 -0
  236. package/src/strategies/mushrooms/dist/index.js +202 -0
  237. package/src/strategies/niu-staked/dist/index.js +83 -0
  238. package/src/strategies/ocean-marketplace/dist/index.js +155 -0
  239. package/src/strategies/ogn/dist/index.js +105 -0
  240. package/src/strategies/opium/dist/index.js +153 -0
  241. package/src/strategies/pagination/dist/index.js +78 -0
  242. package/src/strategies/pancake/dist/index.js +140 -0
  243. package/src/strategies/pepemon/dist/index.js +177 -0
  244. package/src/strategies/piedao/dist/index.js +156 -0
  245. package/src/strategies/planet-finance/dist/index.js +190 -0
  246. package/src/strategies/pob-hash/dist/index.js +95 -0
  247. package/src/strategies/rebased/dist/index.js +134 -0
  248. package/src/strategies/ren-nodes/dist/index.js +148 -0
  249. package/src/strategies/rnbw-balance/dist/index.js +107 -0
  250. package/src/strategies/ruler-staked-lp/dist/index.js +156 -0
  251. package/src/strategies/ruler-staked-token/dist/index.js +100 -0
  252. package/src/strategies/saffron-finance/dist/index.js +293 -0
  253. package/src/strategies/spookyswap/dist/index.js +161 -0
  254. package/src/strategies/stablexswap/dist/index.js +153 -0
  255. package/src/strategies/staked-keep/dist/index.js +90 -0
  256. package/src/strategies/staked-uniswap/dist/index.js +112 -0
  257. package/src/strategies/sushiswap/dist/index.js +120 -0
  258. package/src/strategies/synthetix/dist/index.js +233 -0
  259. package/src/strategies/the-graph-balance/dist/index.js +55 -0
  260. package/src/strategies/the-graph-delegation/dist/index.js +55 -0
  261. package/src/strategies/the-graph-indexing/dist/index.js +55 -0
  262. package/src/strategies/ticket/dist/index.js +51 -0
  263. package/src/strategies/ticket-validity/dist/index.js +63 -0
  264. package/src/strategies/tokenlon/dist/index.js +211 -0
  265. package/src/strategies/tomb-finance/dist/index.js +130 -0
  266. package/src/strategies/total-axion-shares/dist/index.js +93 -0
  267. package/src/strategies/tranche-staking/dist/index.js +96 -0
  268. package/src/strategies/tranche-staking-lp/dist/index.js +133 -0
  269. package/src/strategies/tranche-staking-slice/dist/index.js +164 -0
  270. package/src/strategies/typhoon/dist/index.js +124 -0
  271. package/src/strategies/uni/dist/index.js +93 -0
  272. package/src/strategies/unipool-same-token/dist/index.js +98 -0
  273. package/src/strategies/unipool-univ2-lp/dist/index.js +105 -0
  274. package/src/strategies/uniswap/dist/index.js +120 -0
  275. package/src/strategies/whitelist/dist/index.js +56 -0
  276. package/src/strategies/work/dist/index.js +90 -0
  277. package/src/strategies/xcover/dist/index.js +95 -0
  278. package/src/strategies/xdai-easy-staking/dist/index.js +193 -0
  279. package/src/strategies/xdai-posdao-staking/dist/index.js +63 -0
  280. package/src/strategies/xdai-stake-delegation/dist/index.js +93 -0
  281. package/src/strategies/xdai-stake-holders/dist/index.js +63 -0
  282. package/src/strategies/xdai-stakers-and-holders/dist/index.js +137 -0
  283. package/src/strategies/xrc20-balance-of/dist/index.js +83 -0
  284. package/src/strategies/xseen/dist/index.js +121 -0
  285. package/src/strategies/zrx-voting-power/dist/index.js +104 -0
  286. package/src/utils/dist/provider.js +12 -0
  287. package/src/utils/dist/web3.js +73 -0
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.strategy = exports.examples = exports.version = exports.author = void 0;
40
+ var units_1 = require("@ethersproject/units");
41
+ var multicaller_1 = require("../../utils/multicaller");
42
+ var examples_json_1 = require("./examples.json");
43
+ exports.author = 'mystbrent';
44
+ exports.version = '0.1.0';
45
+ exports.examples = examples_json_1["default"];
46
+ var abi = [
47
+ {
48
+ constant: true,
49
+ inputs: [
50
+ {
51
+ internalType: 'address',
52
+ name: '',
53
+ type: 'address'
54
+ }
55
+ ],
56
+ name: 'balanceOf',
57
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
58
+ payable: false,
59
+ stateMutability: 'view',
60
+ type: 'function'
61
+ },
62
+ {
63
+ inputs: [],
64
+ name: 'getCurrentHaloHaloPrice',
65
+ outputs: [
66
+ {
67
+ internalType: 'uint256',
68
+ name: '',
69
+ type: 'uint256'
70
+ }
71
+ ],
72
+ stateMutability: 'view',
73
+ type: 'function'
74
+ }
75
+ ];
76
+ function strategy(space, network, provider, addresses, options, snapshot) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var blockTag, multi, result, dsrtPrice;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
83
+ multi = new multicaller_1["default"](network, provider, abi, { blockTag: blockTag });
84
+ addresses.forEach(function (address) {
85
+ multi.call("scores." + address + ".dsrtBalance", options.token, 'balanceOf', [
86
+ address
87
+ ]);
88
+ });
89
+ multi.call('dsrtPrice', options.token, 'getCurrentHaloHaloPrice');
90
+ return [4 /*yield*/, multi.execute()];
91
+ case 1:
92
+ result = _a.sent();
93
+ dsrtPrice = result.dsrtPrice;
94
+ return [2 /*return*/, Object.fromEntries(Array(addresses.length)
95
+ .fill('')
96
+ .map(function (_, i) {
97
+ var dsrtBalances = result.scores[addresses[i]].dsrtBalance;
98
+ return [
99
+ addresses[i],
100
+ parseFloat(units_1.formatUnits(dsrtBalances.mul(dsrtPrice), 36))
101
+ ];
102
+ }))];
103
+ }
104
+ });
105
+ });
106
+ }
107
+ exports.strategy = strategy;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.strategy = exports.examples = exports.version = exports.author = void 0;
40
+ var utils_1 = require("../../utils");
41
+ var examples_json_1 = require("./examples.json");
42
+ exports.author = 'vfatouros';
43
+ exports.version = '0.1.0';
44
+ exports.examples = examples_json_1["default"];
45
+ var tokenAbi = [
46
+ {
47
+ constant: true,
48
+ inputs: [
49
+ {
50
+ internalType: 'address',
51
+ name: 'account',
52
+ type: 'address'
53
+ }
54
+ ],
55
+ name: 'balanceOf',
56
+ outputs: [
57
+ {
58
+ internalType: 'uint256',
59
+ name: '',
60
+ type: 'uint256'
61
+ }
62
+ ],
63
+ payable: false,
64
+ stateMutability: 'view',
65
+ type: 'function'
66
+ },
67
+ {
68
+ constant: true,
69
+ inputs: [],
70
+ name: 'totalSupply',
71
+ outputs: [
72
+ {
73
+ internalType: 'uint256',
74
+ name: '',
75
+ type: 'uint256'
76
+ }
77
+ ],
78
+ payable: false,
79
+ stateMutability: 'view',
80
+ type: 'function'
81
+ },
82
+ {
83
+ inputs: [
84
+ {
85
+ internalType: 'address',
86
+ name: '_lpToken',
87
+ type: 'address'
88
+ },
89
+ {
90
+ internalType: 'address',
91
+ name: '_account',
92
+ type: 'address'
93
+ }
94
+ ],
95
+ name: 'getUser',
96
+ outputs: [
97
+ {
98
+ components: [
99
+ {
100
+ internalType: 'uint256',
101
+ name: 'amount',
102
+ type: 'uint256'
103
+ },
104
+ {
105
+ internalType: 'uint256[]',
106
+ name: 'rewardsWriteoffs',
107
+ type: 'uint256[]'
108
+ }
109
+ ],
110
+ internalType: 'struct IBonusRewards.User',
111
+ name: '',
112
+ type: 'tuple'
113
+ },
114
+ {
115
+ internalType: 'uint256[]',
116
+ name: '',
117
+ type: 'uint256[]'
118
+ }
119
+ ],
120
+ stateMutability: 'view',
121
+ type: 'function'
122
+ }
123
+ ];
124
+ function strategy(_space, network, provider, addresses, options, snapshot) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var blockTag, res, totalSupply, tokenBalanceInLP, tokensPerLP, response;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
131
+ return [4 /*yield*/, utils_1.multicall(network, provider, tokenAbi, [
132
+ [options.sushiPoolAddress, 'totalSupply', []],
133
+ [options.tokenAddress, 'balanceOf', [options.sushiPoolAddress]]
134
+ ].concat(addresses.map(function (address) { return [
135
+ options.stakingAddress,
136
+ 'getUser',
137
+ [options.sushiPoolAddress, address]
138
+ ]; })), { blockTag: blockTag })];
139
+ case 1:
140
+ res = _a.sent();
141
+ totalSupply = res[0];
142
+ tokenBalanceInLP = res[1];
143
+ tokensPerLP = tokenBalanceInLP / Math.pow(10, options.decimals) / (totalSupply / 1e18);
144
+ response = res.slice(2);
145
+ return [2 /*return*/, Object.fromEntries(response.map(function (_a, i) {
146
+ var userInfo = _a[0];
147
+ return [
148
+ addresses[i],
149
+ (userInfo.amount / Math.pow(10, options.decimals)) * tokensPerLP
150
+ ];
151
+ }))];
152
+ }
153
+ });
154
+ });
155
+ }
156
+ exports.strategy = strategy;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.strategy = exports.about = exports.examples = exports.version = exports.author = void 0;
40
+ var units_1 = require("@ethersproject/units");
41
+ var utils_1 = require("../../utils");
42
+ var examples_json_1 = require("./examples.json");
43
+ var README_md_1 = require("./README.md");
44
+ exports.author = 'drop-out-dev';
45
+ exports.version = '0.1.0';
46
+ exports.examples = examples_json_1["default"];
47
+ exports.about = README_md_1["default"];
48
+ var abi = [
49
+ {
50
+ inputs: [
51
+ { internalType: 'address', name: '_lpToken', type: 'address' },
52
+ { internalType: 'address', name: '_account', type: 'address' }
53
+ ],
54
+ name: 'getUser',
55
+ outputs: [
56
+ {
57
+ components: [
58
+ { internalType: 'uint256', name: 'amount', type: 'uint256' },
59
+ {
60
+ internalType: 'uint256[]',
61
+ name: 'rewardsWriteoffs',
62
+ type: 'uint256[]'
63
+ }
64
+ ],
65
+ internalType: 'struct IBonusRewards.User',
66
+ name: '',
67
+ type: 'tuple'
68
+ },
69
+ { internalType: 'uint256[]', name: '', type: 'uint256[]' }
70
+ ],
71
+ stateMutability: 'view',
72
+ type: 'function'
73
+ }
74
+ ];
75
+ function strategy(space, network, provider, addresses, options, snapshot) {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var blockTag, response;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
82
+ return [4 /*yield*/, utils_1.multicall(network, provider, abi, addresses.map(function (address) { return [
83
+ options.stakingAddress,
84
+ 'getUser',
85
+ [options.tokenAddress, address]
86
+ ]; }), { blockTag: blockTag })];
87
+ case 1:
88
+ response = _a.sent();
89
+ return [2 /*return*/, Object.fromEntries(response.map(function (_a, i) {
90
+ var userInfo = _a[0];
91
+ return [
92
+ addresses[i],
93
+ parseFloat(units_1.formatUnits(userInfo.amount, options.decimals))
94
+ ];
95
+ }))];
96
+ }
97
+ });
98
+ });
99
+ }
100
+ exports.strategy = strategy;
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.strategy = exports.examples = exports.version = exports.author = void 0;
40
+ var units_1 = require("@ethersproject/units");
41
+ var bignumber_1 = require("@ethersproject/bignumber");
42
+ var utils_1 = require("../../utils");
43
+ var examples_json_1 = require("./examples.json");
44
+ exports.author = 'saffron.finance';
45
+ exports.version = '0.1.0';
46
+ exports.examples = examples_json_1["default"];
47
+ var BIG18 = bignumber_1.BigNumber.from('1000000000000000000');
48
+ var VOTE_BOOST_DIV_1000 = bignumber_1.BigNumber.from(1000);
49
+ var DECIMALS = 18;
50
+ var QUERIES_PER_DEX_LP_PAIR = 2;
51
+ var abi = [
52
+ {
53
+ constant: true,
54
+ inputs: [
55
+ {
56
+ internalType: 'address',
57
+ name: 'account',
58
+ type: 'address'
59
+ }
60
+ ],
61
+ name: 'balanceOf',
62
+ outputs: [
63
+ {
64
+ internalType: 'uint256',
65
+ name: '',
66
+ type: 'uint256'
67
+ }
68
+ ],
69
+ payable: false,
70
+ stateMutability: 'view',
71
+ type: 'function'
72
+ },
73
+ {
74
+ inputs: [],
75
+ name: 'getReserves',
76
+ outputs: [
77
+ {
78
+ internalType: 'uint112',
79
+ name: '_reserve0',
80
+ type: 'uint112'
81
+ },
82
+ {
83
+ internalType: 'uint112',
84
+ name: '_reserve1',
85
+ type: 'uint112'
86
+ },
87
+ {
88
+ internalType: 'uint32',
89
+ name: '_blockTimestampLast',
90
+ type: 'uint32'
91
+ }
92
+ ],
93
+ stateMutability: 'view',
94
+ type: 'function',
95
+ constant: true
96
+ },
97
+ {
98
+ constant: true,
99
+ inputs: [],
100
+ name: 'totalSupply',
101
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
102
+ payable: false,
103
+ stateMutability: 'view',
104
+ type: 'function'
105
+ }
106
+ ];
107
+ // DirectBoostScheme provides logic to apply a multiplier, or boost, to a raw balance value. This gives
108
+ // Saffron Finance the ability to adjust the voting power a token holder has depending external configuration.
109
+ //
110
+ // name ... unique string that identifies the instance of the VotingScheme
111
+ // multiplier ... the raw balance value is multiplied by the multiplier such that: score = (multiplier)(balance).
112
+ // If this value is 1.0, it is equivalent to score = balance.
113
+ // If this value is less than 1.0 and greater than 0.0, then the token holder's voting power is reduced.
114
+ // If this value is 0.0, then the token holder has no voting power.
115
+ var DirectBoostScheme = /** @class */ (function () {
116
+ function DirectBoostScheme(name, multiplier) {
117
+ this.name = name;
118
+ this.multiplier = multiplier;
119
+ }
120
+ DirectBoostScheme.prototype.doAlgorithm = function (balance) {
121
+ var voteBoost1000 = bignumber_1.BigNumber.from(this.multiplier * 1000);
122
+ return balance.mul(voteBoost1000).div(VOTE_BOOST_DIV_1000);
123
+ };
124
+ return DirectBoostScheme;
125
+ }());
126
+ // LPReservePairScheme provides logic to apply a voting score to only the SFI side of a Uniswap or Sushiswap LP token
127
+ // pair.
128
+ //
129
+ // name ... unique string that identifies the instance of the VotingScheme
130
+ // multiplier ... the raw balance value is multiplied by the multiplier such that: score = (multiplier)(balance).
131
+ // If this value is 1.0, it is equivalent to score = balance.
132
+ // If this value is less than 1.0 and greater than 0.0, then the token holder's voting power is reduced.
133
+ // If this value is 0.0, then the token holder has no voting power.
134
+ // saffLpToSfi_E18 ... Conversion of the Saffron LP Pair Token holding to SFI value with expected value to be in wei.
135
+ var LPReservePairScheme = /** @class */ (function () {
136
+ function LPReservePairScheme(name, multiplier, saffLpToSfi_E18) {
137
+ this.name = name;
138
+ this.multiplier = multiplier;
139
+ this.saffLpToSfi_E18 = saffLpToSfi_E18;
140
+ }
141
+ LPReservePairScheme.prototype.doAlgorithm = function (balance) {
142
+ var voteMult1000 = bignumber_1.BigNumber.from(this.multiplier * 1000);
143
+ var calculatedScore = balance.mul(this.saffLpToSfi_E18).div(BIG18);
144
+ return calculatedScore.mul(voteMult1000).div(VOTE_BOOST_DIV_1000);
145
+ };
146
+ return LPReservePairScheme;
147
+ }());
148
+ // VoteScorer acts as the context to invoke the relevant VotingScheme by way of its calculateScore method.
149
+ // It assumes all VotingScheme's are created by the createVotingScheme method prior to invocation of calculateScore.
150
+ //
151
+ // votingSchemes ... A Map that provides keyed access to a VotingScheme instance.
152
+ // dexReserveData ... An Array that holds necessary Uniswap and Sushiswap LP Pair Token data for LPReservePairScheme.
153
+ var VoteScorer = /** @class */ (function () {
154
+ function VoteScorer(dexReserveData) {
155
+ this.votingSchemes = new Map();
156
+ this.dexReserveData = new Array();
157
+ this.dexReserveData = dexReserveData;
158
+ this.votingSchemes.set('default', new DirectBoostScheme('default', 1.0));
159
+ }
160
+ VoteScorer.prototype.createVotingScheme = function (name, type, multiplier) {
161
+ var votingScheme = new DirectBoostScheme('no-vote-scheme', 0.0);
162
+ if (type === 'DirectBoostScheme') {
163
+ votingScheme = new DirectBoostScheme(name, multiplier);
164
+ }
165
+ else if (type === 'LPReservePairScheme') {
166
+ var lpReservePairData = this.dexReserveData.find(function (e) { return e.name === name; });
167
+ if (lpReservePairData === undefined) {
168
+ throw Error("Failed to locate token LP Pair data for " + name + ".");
169
+ }
170
+ votingScheme = new LPReservePairScheme(name, multiplier, lpReservePairData.saffLpToSFI_E18);
171
+ }
172
+ else {
173
+ throw new Error("Unsupported voting scheme type, " + type + ".");
174
+ }
175
+ this.votingSchemes.set(name, votingScheme);
176
+ };
177
+ VoteScorer.prototype.calculateScore = function (schemeName, balance) {
178
+ var votingScheme = this.votingSchemes.get(schemeName);
179
+ if (votingScheme === undefined) {
180
+ throw new Error("Failed to locate voting scheme, " + schemeName + ". Check initialization of votingSchemes.");
181
+ }
182
+ return votingScheme.doAlgorithm(balance);
183
+ };
184
+ return VoteScorer;
185
+ }());
186
+ function strategy(space, network, provider, addresses, options, snapshot) {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var blockTag, callQueries, callResponses, holdersQueryBatches, votingScores, callQueryIndex, dexReserveData, voteScorer, emptyVotingScoreCountToAdd, emptyVote, i, addressVotingScore;
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0:
192
+ blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
193
+ callQueries = new Array();
194
+ callResponses = new Array();
195
+ holdersQueryBatches = new Array();
196
+ votingScores = new Array();
197
+ callQueryIndex = 0;
198
+ dexReserveData = new Array();
199
+ options.dexLpTypes.forEach(function (dexToken) {
200
+ var d = {
201
+ name: dexToken.name,
202
+ reservesQuery: [dexToken.lpToken, 'getReserves'],
203
+ reserveQueryIdx: 0,
204
+ reserve: bignumber_1.BigNumber.from(0),
205
+ supplyQuery: [dexToken.lpToken, 'totalSupply'],
206
+ supplyQueryIdx: 0,
207
+ supply: bignumber_1.BigNumber.from(0),
208
+ saffLpToSFI_E18: bignumber_1.BigNumber.from(0)
209
+ };
210
+ callQueries.push(d.reservesQuery);
211
+ d.reserveQueryIdx = callQueryIndex++;
212
+ callQueries.push(d.supplyQuery);
213
+ d.supplyQueryIdx = callQueryIndex++;
214
+ dexReserveData.push(d);
215
+ });
216
+ // ============= Multicall queries ==============
217
+ options.contracts.forEach(function (contract) {
218
+ var queries = addresses.map(function (address) {
219
+ return [contract.tokenAddress, 'balanceOf', [address]];
220
+ });
221
+ var queriesLength = callQueries.push.apply(callQueries, queries);
222
+ var batch = {
223
+ tag: contract.label,
224
+ votingScheme: contract.votingScheme,
225
+ qIdxStart: callQueryIndex,
226
+ qIdxEnd: queriesLength
227
+ };
228
+ callQueryIndex = queriesLength;
229
+ holdersQueryBatches.push(batch);
230
+ });
231
+ return [4 /*yield*/, utils_1.multicall(network, provider, abi, callQueries, {
232
+ blockTag: blockTag
233
+ })];
234
+ case 1:
235
+ // Run queries
236
+ callResponses = _a.sent();
237
+ // ========== Extract and process query responses ==========
238
+ dexReserveData.forEach(function (drd) {
239
+ drd.reserve = callResponses[drd.reserveQueryIdx][0];
240
+ drd.supply = callResponses[drd.supplyQueryIdx][0];
241
+ drd.saffLpToSFI_E18 = drd.reserve.mul(BIG18).div(drd.supply);
242
+ });
243
+ voteScorer = new VoteScorer(dexReserveData);
244
+ options.votingSchemes.forEach(function (scheme) {
245
+ voteScorer.createVotingScheme(scheme.name, scheme.type, scheme.multiplier);
246
+ });
247
+ emptyVotingScoreCountToAdd = dexReserveData.length * QUERIES_PER_DEX_LP_PAIR;
248
+ emptyVote = { address: '0x00', score: 0.0 };
249
+ for (i = 0; i < emptyVotingScoreCountToAdd; i++) {
250
+ votingScores.push(emptyVote);
251
+ }
252
+ options.contracts.forEach(function (contract) {
253
+ var batch = holdersQueryBatches.find(function (e) { return e.tag === contract.label; });
254
+ if (batch === undefined) {
255
+ throw new Error("Failed to locate tag, " + contract.label + ", in queryBatches.");
256
+ }
257
+ var idxStart = batch.qIdxStart;
258
+ var batchScores = addresses.map(function (address, index) {
259
+ return {
260
+ address: address,
261
+ score: voteScorer.calculateScore(contract.votingScheme, callResponses[idxStart + index][0])
262
+ };
263
+ });
264
+ votingScores.push.apply(votingScores, batchScores);
265
+ });
266
+ addressVotingScore = addresses.map(function (address, addressIndex) {
267
+ var total = bignumber_1.BigNumber.from(0);
268
+ holdersQueryBatches.forEach(function (batch) {
269
+ var votingScore = votingScores[batch.qIdxStart + addressIndex];
270
+ if (votingScore === undefined) {
271
+ throw new Error("Expected a votingScore at batch.qIdxStart: " + batch.qIdxStart + ", addressIndex: " + addressIndex);
272
+ }
273
+ if (votingScore.address === address) {
274
+ total = total.add(votingScore.score);
275
+ }
276
+ else {
277
+ throw new Error(batch.tag + " expected address, " + address + ", found " + votingScore.address);
278
+ }
279
+ });
280
+ // Return single record { address, score } where score should have exponent of 18
281
+ return { address: address, score: total };
282
+ });
283
+ return [2 /*return*/, Object.fromEntries(addressVotingScore.map(function (addressVote) {
284
+ return [
285
+ addressVote.address,
286
+ parseFloat(units_1.formatUnits(addressVote.score, DECIMALS))
287
+ ];
288
+ }))];
289
+ }
290
+ });
291
+ });
292
+ }
293
+ exports.strategy = strategy;