Bugfixes - liquidateTokenAndPerp, tokenBalance

This commit is contained in:
Nicholas Clarke 2021-10-19 09:12:57 -07:00
parent 2fc8605bc9
commit 40970da3ff
4 changed files with 34 additions and 23 deletions

View File

@ -827,8 +827,8 @@ function parseFillLog(
let assetSymbol; let assetSymbol;
let liabSymbol; let liabSymbol;
let assetType = eventData.assetType; let assetType = eventData.assetType === 0 ? 'Token': 'Perp';
let liabType = eventData.liabType; let liabType = eventData.liabType === 0 ? 'Token': 'Perp';
let assetDecimals; let assetDecimals;
let liabDecimals; let liabDecimals;
@ -867,18 +867,17 @@ function parseFillLog(
let assetPrice = let assetPrice =
new I80F48(eventData.assetPrice).toNumber() * new I80F48(eventData.assetPrice).toNumber() *
Math.pow(10, assetToken.decimals - quoteDecimals); Math.pow(10, assetDecimals - quoteDecimals);
let liabPrice = let liabPrice =
new I80F48(eventData.liabPrice).toNumber() * new I80F48(eventData.liabPrice).toNumber() *
Math.pow(10, liabToken.decimals - quoteDecimals); Math.pow(10, liabDecimals - quoteDecimals);
// TODO: confirm that this is correct
let assetTransfer = let assetTransfer =
new I80F48(eventData.assetTransfer).toNumber() / new I80F48(eventData.assetTransfer).toNumber() /
Math.pow(10, assetToken.decimals); Math.pow(10, assetDecimals);
let liabTransfer = let liabTransfer =
new I80F48(eventData.liabTransfer).toNumber() / new I80F48(eventData.liabTransfer).toNumber() /
Math.pow(10, liabToken.decimals); Math.pow(10, liabDecimals);
return { return {
liqor: liqor, liqor: liqor,
@ -1054,6 +1053,12 @@ function parseFillLog(
let tokens = ids["groups"].find((e) => e["publicKey"] === mangoGroupPk)[ let tokens = ids["groups"].find((e) => e["publicKey"] === mangoGroupPk)[
"tokens" "tokens"
]; ];
let quoteSymbol = ids['groups'].find((e) => e['publicKey'] === mangoGroupPk)[
'quoteSymbol'
];
let quoteDecimals = ids['groups']
.find((e) => e['publicKey'] === mangoGroupPk)
['tokens'].find((e) => e.symbol === quoteSymbol).decimals;
let mangoAccountPk = eventData.mangoAccount.toString(); let mangoAccountPk = eventData.mangoAccount.toString();
let tokenIndex = eventData.tokenIndex.toNumber(); let tokenIndex = eventData.tokenIndex.toNumber();
@ -1063,10 +1068,10 @@ function parseFillLog(
let symbol = token.symbol; let symbol = token.symbol;
let deposit = new I80F48(eventData.deposit) let deposit = new I80F48(eventData.deposit)
.div(I80F48.fromNumber(Math.pow(10, token.decimals))) .div(I80F48.fromNumber(Math.pow(10, token.decimals - quoteDecimals)))
.toNumber(); .toNumber();
let borrow = new I80F48(eventData.borrow) let borrow = new I80F48(eventData.borrow)
.div(I80F48.fromNumber(Math.pow(10, token.decimals))) .div(I80F48.fromNumber(Math.pow(10, token.decimals - quoteDecimals)))
.toNumber(); .toNumber();
return { return {

View File

@ -141,6 +141,8 @@ async function insertTransactions(
{ table: transactionsTable }, { table: transactionsTable },
); );
console.log('Starting transaction inserts')
let batchSize = 1000; let batchSize = 1000;
let client = await pool.connect(); let client = await pool.connect();
try { try {

View File

@ -77,6 +77,10 @@ export function parseTransactions(transactionsResult, mangoProgramId) {
), ),
); );
// Anchor logging was deployed at slot 100936906 - use different parsing code before and after this slot
const ancorDeploymentSlot = 100936906
if (slot < ancorDeploymentSlot) {
// Populate instruction num and name for each instruction // Populate instruction num and name for each instruction
let ixNum = 1; let ixNum = 1;
for (const ix of instructions) { for (const ix of instructions) {
@ -88,9 +92,6 @@ export function parseTransactions(transactionsResult, mangoProgramId) {
ixNum++; ixNum++;
} }
// Anchor logging was deployed at slot 100936906 - use different parsing code before and after this slot
const ancorDeploymentSlot = 100936906
if (slot < ancorDeploymentSlot) {
jsonParser(parsedTransactions, result, instructions, signature, blockTime, slot, blockDatetime) jsonParser(parsedTransactions, result, instructions, signature, blockTime, slot, blockDatetime)
} else { } else {
anchorParser(parsedTransactions, result, signature, blockTime, slot, blockDatetime) anchorParser(parsedTransactions, result, signature, blockTime, slot, blockDatetime)

View File

@ -44,7 +44,10 @@ async function processMangoTransactions(rawTransactionsPool, schema, limit) {
"3KzZ5jYfwp6LyPUt5LFbbPLEEsYNYtdAA5hs2KAdZxqarFiVVUKJ7WFxYXf8xeFnbWwypEWpNRCeE1d3y4e5Sxrk", // FillLog "3KzZ5jYfwp6LyPUt5LFbbPLEEsYNYtdAA5hs2KAdZxqarFiVVUKJ7WFxYXf8xeFnbWwypEWpNRCeE1d3y4e5Sxrk", // FillLog
"NGgdZu6YwNnFGoSMxc6ZgfUhSVy2rkB9BDY9yvYRLYZoteDSArWn5hDUGZuYCktC81jzGb6u9W6u7ab9mWutfQe", // SettlePnl "NGgdZu6YwNnFGoSMxc6ZgfUhSVy2rkB9BDY9yvYRLYZoteDSArWn5hDUGZuYCktC81jzGb6u9W6u7ab9mWutfQe", // SettlePnl
"67axUM8Q6tvCCNa6Cq8JfR9pLCAf5wyqc7gy1eafEtA4kcYE9Gte1LT8b9ziEWhtLfaGim5t5ChYU5uaQLfteGTJ", // SettlePnl - Multiple "67axUM8Q6tvCCNa6Cq8JfR9pLCAf5wyqc7gy1eafEtA4kcYE9Gte1LT8b9ziEWhtLfaGim5t5ChYU5uaQLfteGTJ", // SettlePnl - Multiple
"24hCHGXrf9nCnkioWf6HxtRqnQHGhhtTkARgA9tqkEmWb3uUzuE2oUU3so1JGNGZftCaBMjWek5rqAHRU3VAyQEJ" // Multiple net balances changes to the same (mangoAccount, token) pair "24hCHGXrf9nCnkioWf6HxtRqnQHGhhtTkARgA9tqkEmWb3uUzuE2oUU3so1JGNGZftCaBMjWek5rqAHRU3VAyQEJ", // Multiple net balances changes to the same (mangoAccount, token) pair
"eu5yMAACP41tvHAMmhuRAqu9tW4ZJeVY37TqbJLYVaqavKNh1rQEH97QGq6j3Zm721dgjMs94qmLm9PiSPDcwfX", // force_settle_quote_positions
"3twdGBA3Fz9Sbn4hS8AbHEcLomj8KyLVcB9P7ToiVP83cnHEHS7WFKgcsAa2TaDvYJ8emuhmBGWDybbtxVjgZXGt", // LiquidateTokenAndPerp
"3nQBUy8naBUj7US3PiVkcUt75jV4bszuQEV2vYMgrbYJGTJAbseuQJ7HvCQBhpWZqUUWPCeT72px1ijWdd4zC5ZG" // netbalances
]; ];
let signaturesSql = signatures.map((e) => "'" + e + "'").join(','); let signaturesSql = signatures.map((e) => "'" + e + "'").join(',');