Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mars debug util #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crawler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,37 @@ kycCli
}
});

const debugCli = program.command('debug').description('Debug commands');
debugCli
.command('mars')
.command('crawl')
.argument('<batch_id>', 'Batch ID')
.argument('<account>', 'Account ID')
.action(async (batchId, account) => {
logger.level = 'trace';
const task = db
.query<
{ height: number },
[string, string]
>('SELECT height FROM tasks WHERE batch_id = ? AND protocol_id = ?')
.get(batchId, 'neutron-mars');
if (!task) {
logger.error('Task not found');
return;
}
logger.debug('Task height: %d', task.height);
const multipliers = getAssetMulsByProtocolAndBatchId(
'neutron-mars',
batchId,
);
logger.debug('Multipliers: %o', multipliers);
const source = new sources['mars'](
config.protocols['neutron-mars'].rpc,
logger,
config.protocols['neutron-mars'],
);
const out = await source.debugOneAccount(task.height, multipliers, account);
logger.debug('Account %s: %o', account, out);
});

program.parse(process.argv);
24 changes: 24 additions & 0 deletions lib/sources/mars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export default class MarsSource implements SourceInterface {
);
const assetAmount = Number(foundAsset?.amount || '0');
if (assetAmount) {
this.logger.trace(
'assetAmount * this.lpToDATOMRate[assetId] = %s * %s = %s',
assetAmount,
this.lpToDATOMRate[assetId],
(assetAmount * this.lpToDATOMRate[assetId]) | 0,
);
return {
balance: BigInt((assetAmount * this.lpToDATOMRate[assetId]) | 0),
debted: positions.debts.length > 0,
Expand Down Expand Up @@ -310,6 +316,24 @@ export default class MarsSource implements SourceInterface {
return Number(datomAmount) / 1000000000;
};

debugOneAccount = async (
height: number,
multipliers: Record<string, number>,
account: string,
) => {
for (const [assetId, asset] of Object.entries(this.assets)) {
if (asset.lp) {
const lpRate = await this.getAtroLpExchangeRate(
height,
asset.denom.split('/')[1],
);
this.lpToDATOMRate[assetId] = lpRate;
}
}
this.logger.debug('lpToDATOMRate %o', this.lpToDATOMRate);
return this.getAddressAndBalances(height, multipliers, account);
};

getUsersBalances = async (
height: number,
multipliers: Record<string, number>,
Expand Down