Skip to content

Commit

Permalink
feat(deployment): auto top up managed deployment with available amount
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Dec 5, 2024
1 parent 62aefe3 commit 699c6f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ describe(TopUpManagedDeploymentsService.name, () => {

const data = [
seedFor({}),
seedFor({ balance: "5000000", expectedDeploymentsTopUpCount: 1 }),
seedFor({ balance: "50000000", expectedDeploymentsTopUpCount: 2 }),
seedFor({ balance: "1408022", expectedDeploymentsTopUpCount: 1 }),
seedFor({ hasDeployments: false }),
seedFor({ balance: "0", expectedDeploymentsTopUpCount: 0 })
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class TopUpManagedDeploymentsService implements DeploymentsRefiller {
}

private async topUpForWallet(wallet: UserWalletOutput, options: TopUpDeploymentsOptions, summary: TopUpSummarizer) {
const depositor = await this.managedMasterWalletService.getFirstAddress();
summary.inc("walletsCount");
const owner = wallet.address;
const denom = this.billingConfig.DEPLOYMENT_GRANT_DENOM;
Expand All @@ -63,14 +64,15 @@ export class TopUpManagedDeploymentsService implements DeploymentsRefiller {
}

const signer = await this.txSignerService.getClientForAddressIndex(wallet.id);
const depositor = await this.managedMasterWalletService.getFirstAddress();

let balance = await this.balancesService.retrieveAndCalcDeploymentLimit(wallet);
let hasTopUp = false;

for (const deployment of drainingDeployments) {
const amount = await this.drainingDeploymentService.calculateTopUpAmount(deployment);
if (amount > balance) {
let amount = await this.drainingDeploymentService.calculateTopUpAmount(deployment);
amount = Math.min(amount, balance);

if (amount <= 0) {
this.logger.info({ event: "INSUFFICIENT_BALANCE", owner, balance, amount });
summary.inc("insufficientBalanceCount");
break;
Expand Down

0 comments on commit 699c6f1

Please sign in to comment.