Skip to content

Commit

Permalink
fix data scrubbing
Browse files Browse the repository at this point in the history
- vault balance caching
  • Loading branch information
rouzwelt committed Aug 24, 2023
1 parent 0f49d0d commit 5734569
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 60 deletions.
2 changes: 1 addition & 1 deletion arb-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const main = async argv => {
true,
options.rpc,
options.key,
options.zeroExApiKey
options.apiKey
);

// eslint-disable-next-line no-constant-condition
Expand Down
2 changes: 1 addition & 1 deletion docs/html/curve.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
24 changes: 12 additions & 12 deletions docs/html/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ <h5>Parameters:</h5>
<td class="type">


<span class="param-type">Array.&lt;any></span>
<span class="param-type">any</span>



Expand Down Expand Up @@ -624,7 +624,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line850">line 850</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line882">line 882</a>
</li></ul></dd>


Expand Down Expand Up @@ -1923,7 +1923,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line638">line 638</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line670">line 670</a>
</li></ul></dd>


Expand Down Expand Up @@ -2868,7 +2868,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line555">line 555</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line587">line 587</a>
</li></ul></dd>


Expand Down Expand Up @@ -3097,7 +3097,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line591">line 591</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line623">line 623</a>
</li></ul></dd>


Expand Down Expand Up @@ -3620,7 +3620,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line785">line 785</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line817">line 817</a>
</li></ul></dd>


Expand Down Expand Up @@ -3757,7 +3757,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line745">line 745</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line777">line 777</a>
</li></ul></dd>


Expand Down Expand Up @@ -4439,7 +4439,7 @@ <h5>Parameters:</h5>



<td class="description last">The interpreter ethersjs contract instance</td>
<td class="description last">The interpreter ethersjs contract instance with signer</td>
</tr>


Expand Down Expand Up @@ -5426,7 +5426,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line680">line 680</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line712">line 712</a>
</li></ul></dd>


Expand Down Expand Up @@ -5622,7 +5622,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line958">line 958</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line1008">line 1008</a>
</li></ul></dd>


Expand Down Expand Up @@ -6316,7 +6316,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line701">line 701</a>
<a href="utils.js.html">utils.js</a>, <a href="utils.js.html#line733">line 733</a>
</li></ul></dd>


Expand Down Expand Up @@ -6606,7 +6606,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/query.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/router.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
92 changes: 71 additions & 21 deletions docs/html/utils.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ <h1 class="page-title">Source: utils.js</h1>
/**
* Calls eval for a specific order to get its max output and ratio
*
* @param {ethers.Contract} interpreter - The interpreter ethersjs contract instance
* @param {ethers.Contract} interpreter - The interpreter ethersjs contract instance with signer
* @param {string} arbAddress - Arb contract address
* @param {string} obAddress - OrderBook contract address
* @param {object} order - The order details fetched from sg
Expand Down Expand Up @@ -479,15 +479,31 @@ <h1 class="page-title">Source: utils.js</h1>
orderbook.signer.provider
);

const vaultsCache = [];
for (let i = 0; i &lt; ordersDetails.length; i++) {
const order = ordersDetails[i];
for (let j = 0; j &lt; order.validOutputs.length; j++) {
const _output = order.validOutputs[j];
const _outputBalance = await orderbook.vaultBalance(
order.owner.id,
_output.token.id,
_output.vault.id.split("-")[0]
let ov = vaultsCache.find(e =>
e.owner === order.owner.id &amp;&amp;
e.token === _output.token.id &amp;&amp;
e.vaultId === _output.vault.id.split("-")[0]
);
if (!ov) {
const balance = await orderbook.vaultBalance(
order.owner.id,
_output.token.id,
_output.vault.id.split("-")[0]
);
ov = {
owner: order.owner.id,
token: _output.token.id,
vaultId: _output.vault.id.split("-")[0],
balance
};
vaultsCache.push(ov);
}
const _outputBalance = ov.balance;
const _outputBalanceFixed = ethers.utils.parseUnits(
ethers.utils.formatUnits(
_outputBalance,
Expand All @@ -504,11 +520,27 @@ <h1 class="page-title">Source: utils.js</h1>
for (let k = 0; k &lt; order.validInputs.length; k ++) {
if (_output.token.id !== order.validInputs[k].token.id) {
const _input = order.validInputs[k];
const _inputBalance = await orderbook.vaultBalance(
order.owner.id,
_input.token.id,
_input.vault.id.split("-")[0]
let iv = vaultsCache.find(e =>
e.owner === order.owner.id &amp;&amp;
e.token === _input.token.id &amp;&amp;
e.vaultId === _input.vault.id.split("-")[0]
);
if (!iv) {
const balance = await orderbook.vaultBalance(
order.owner.id,
_input.token.id,
_input.vault.id.split("-")[0]
);
iv = {
owner: order.owner.id,
token: _input.token.id,
vaultId: _input.vault.id.split("-")[0],
balance
};
vaultsCache.push(iv);
}
const _inputBalance = iv.balance;

const { maxOutput, ratio } = await interpreterEval(
new ethers.Contract(
order.interpreter,
Expand Down Expand Up @@ -873,7 +905,7 @@ <h1 class="page-title">Source: utils.js</h1>
* Method to shorten data fields of items that are logged and optionally hide sensitive data
*
* @param {boolean} scurb - Option to scrub sensitive data
* @param {...any[]} data - The optinnal data to hide
* @param {...any} data - The optinnal data to hide
*/
const appGlobalLogger = (scurb, ...data) => {
const largeDataPattern = /0x[a-fA-F0-9]{128,}/g;
Expand Down Expand Up @@ -901,9 +933,9 @@ <h1 class="page-title">Source: utils.js</h1>
for (let i = 0; i &lt; objKeys.length; i++) {
if (typeof logObj[objKeys[i]] === "string" &amp;&amp; logObj[objKeys[i]]) {
if (typeof searchee === "string") {
while (logObj[objKeys[i]].includes(searchee)) {
logObj[objKeys[i]] = logObj[objKeys[i]].replace(searchee, replacer);
}
// while (logObj[objKeys[i]].includes(searchee)) {
logObj[objKeys[i]] = logObj[objKeys[i]].replaceAll(searchee, replacer);
// }
}
else logObj[objKeys[i]] = logObj[objKeys[i]].replace(searchee, replacer);
}
Expand All @@ -916,11 +948,13 @@ <h1 class="page-title">Source: utils.js</h1>

// filtering unscrubable data
const _data = data.filter(
v => v !== undefined &amp;&amp; v !== null &amp;&amp; !isNaN(v)
v => v !== undefined &amp;&amp; v !== null
).map(
v => {
try {
const str = v.toString();
let str;
if (typeof v !== "string") str = v.toString();
else str = v;
if (str) return str;
else return undefined;
}
Expand All @@ -943,27 +977,43 @@ <h1 class="page-title">Source: utils.js</h1>
typeof logItem === "symbol"
) logItem = logItem.toString();

if (typeof logItem === "string" &amp;&amp; logItem) {
if (scurb) for (let j = 0; j &lt; _data.length; j++) {
while (logItem.includes(_data[i])) logItem = logItem.replace(
if (typeof logItem === "string") {
for (let j = 0; j &lt; _data.length; j++) {
// while (logItem.includes(_data[i]))
logItem = logItem.replaceAll(
_data[i],
"**********"
);
}
let _skipFirst = true;
logItem = logItem.replace(
largeDataPattern,
largeData => largeData.slice(0, 67) + "..."
largeData => {
if (_skipFirst) {
_skipFirst = false;
return largeData;
}
else return largeData.slice(0, 67) + "...";
}
);
}
else if (typeof logItem === "object" &amp;&amp; logItem !== null) {
logItem = objStringify(logItem);
if (scurb) for (let j = 0; j &lt; _data.length; j++) {
logItem = objStrReplacer(logItem, _data[j], "**********");
}
let _skipFirst = true;
logItem = objStrReplacer(
logItem,
largeDataPattern,
largeData => largeData.slice(0, 67) + "..."
largeData => {
if (_skipFirst) {
_skipFirst = false;
return largeData;
}
else return largeData.slice(0, 67) + "...";
},
true
);
}
modifiedParams.push(logItem);
Expand Down Expand Up @@ -1032,7 +1082,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/zeroex.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.htm
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Aug 04 2023 20:12:14 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Aug 24 2023 16:55:43 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit 5734569

Please sign in to comment.