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 liabSymbol;
let assetType = eventData.assetType;
let liabType = eventData.liabType;
let assetType = eventData.assetType === 0 ? 'Token': 'Perp';
let liabType = eventData.liabType === 0 ? 'Token': 'Perp';
let assetDecimals;
let liabDecimals;
@ -867,18 +867,17 @@ function parseFillLog(
let assetPrice =
new I80F48(eventData.assetPrice).toNumber() *
Math.pow(10, assetToken.decimals - quoteDecimals);
Math.pow(10, assetDecimals - quoteDecimals);
let liabPrice =
new I80F48(eventData.liabPrice).toNumber() *
Math.pow(10, liabToken.decimals - quoteDecimals);
Math.pow(10, liabDecimals - quoteDecimals);
// TODO: confirm that this is correct
let assetTransfer =
new I80F48(eventData.assetTransfer).toNumber() /
Math.pow(10, assetToken.decimals);
Math.pow(10, assetDecimals);
let liabTransfer =
new I80F48(eventData.liabTransfer).toNumber() /
Math.pow(10, liabToken.decimals);
Math.pow(10, liabDecimals);
return {
liqor: liqor,
@ -1054,6 +1053,12 @@ function parseFillLog(
let tokens = ids["groups"].find((e) => e["publicKey"] === mangoGroupPk)[
"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 tokenIndex = eventData.tokenIndex.toNumber();
@ -1061,12 +1066,12 @@ function parseFillLog(
let tokenPk = tokenIndexesMap[mangoGroupPk][tokenIndex];
let token = tokens.find((e) => e["mintKey"] === tokenPk);
let symbol = token.symbol;
let deposit = new I80F48(eventData.deposit)
.div(I80F48.fromNumber(Math.pow(10, token.decimals)))
.div(I80F48.fromNumber(Math.pow(10, token.decimals - quoteDecimals)))
.toNumber();
let borrow = new I80F48(eventData.borrow)
.div(I80F48.fromNumber(Math.pow(10, token.decimals)))
.div(I80F48.fromNumber(Math.pow(10, token.decimals - quoteDecimals)))
.toNumber();
return {

View File

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

View File

@ -76,21 +76,22 @@ export function parseTransactions(transactionsResult, mangoProgramId) {
)
),
);
// Populate instruction num and name for each instruction
let ixNum = 1;
for (const ix of instructions) {
let decodeData = bs58.decode(ix.data);
let decodedInstruction = MangoInstructionLayout.decode(decodeData, 0);
let instructionName = Object.keys(decodedInstruction)[0];
ix.instructionNum = ixNum;
ix.instructionName = instructionName;
ixNum++;
}
// 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
let ixNum = 1;
for (const ix of instructions) {
let decodeData = bs58.decode(ix.data);
let decodedInstruction = MangoInstructionLayout.decode(decodeData, 0);
let instructionName = Object.keys(decodedInstruction)[0];
ix.instructionNum = ixNum;
ix.instructionName = instructionName;
ixNum++;
}
jsonParser(parsedTransactions, result, instructions, signature, blockTime, slot, blockDatetime)
} else {
anchorParser(parsedTransactions, result, signature, blockTime, slot, blockDatetime)

View File

@ -44,7 +44,10 @@ async function processMangoTransactions(rawTransactionsPool, schema, limit) {
"3KzZ5jYfwp6LyPUt5LFbbPLEEsYNYtdAA5hs2KAdZxqarFiVVUKJ7WFxYXf8xeFnbWwypEWpNRCeE1d3y4e5Sxrk", // FillLog
"NGgdZu6YwNnFGoSMxc6ZgfUhSVy2rkB9BDY9yvYRLYZoteDSArWn5hDUGZuYCktC81jzGb6u9W6u7ab9mWutfQe", // SettlePnl
"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(',');