Skip to content

Commit

Permalink
feat(billing): skips trialing wallets refill
Browse files Browse the repository at this point in the history
and reduces the trial fees allowance
  • Loading branch information
ygrishajev committed Feb 10, 2025
1 parent 76beedf commit 671ea02
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/api/env/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WEBSITE_URL=https://console-beta.akash.network
TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT=10000000
DEPLOYMENT_ALLOWANCE_REFILL_AMOUNT=10000000
DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD=1000000
TRIAL_FEES_ALLOWANCE_AMOUNT=1000000
TRIAL_FEES_ALLOWANCE_AMOUNT=10000
FEE_ALLOWANCE_REFILL_AMOUNT=1000000
FEE_ALLOWANCE_REFILL_THRESHOLD=100000
LOG_LEVEL=debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class BatchSigningClientService {
async executeTx(messages: readonly EncodeObject[], options?: ExecuteTxOptions) {
const tx = await this.execTxLoader.load({ messages, options });

assert(tx.code === 0, 500, "Failed to sign and broadcast tx", { data: tx });
assert(tx?.code === 0, 500, "Failed to sign and broadcast tx", { data: tx });

return tx;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { count, eq, inArray, lte } from "drizzle-orm";
import { and, count, eq, inArray, lte } from "drizzle-orm";
import first from "lodash/first";
import omit from "lodash/omit";
import pick from "lodash/pick";
Expand Down Expand Up @@ -55,7 +55,7 @@ export class UserWalletRepository extends BaseRepository<ApiPgTables["UserWallet
}

async findDrainingWallets(thresholds = { fee: 0 }) {
const where = lte(this.table.feeAllowance, thresholds.fee.toString());
const where = and(lte(this.table.feeAllowance, thresholds.fee.toString()), eq(this.table.isTrialing, false));

return this.toOutputList(
await this.cursor.query.UserWallets.findMany({
Expand Down
16 changes: 11 additions & 5 deletions apps/api/test/functional/wallets-refill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe("Wallets Refill", () => {

describe("console refill-wallets", () => {
it("should refill wallets low on fee allowance", async () => {
const prepareRecords = Array.from({ length: 15 }).map(async () => {
const NUMBER_OF_WALLETS = 15;
const prepareRecords = Array.from({ length: NUMBER_OF_WALLETS }).map(async (_, index) => {
const records = await walletService.createUserAndWallet();
const { user, token } = records;
const { wallet } = records;
Expand All @@ -44,7 +45,8 @@ describe("Wallets Refill", () => {
walletRecord = await userWalletRepository.updateById(
wallet.id,
{
feeAllowance: limits.fees
feeAllowance: limits.fees,
isTrialing: index === NUMBER_OF_WALLETS - 1
},
{ returning: true }
);
Expand All @@ -57,14 +59,18 @@ describe("Wallets Refill", () => {

const records = await Promise.all(prepareRecords);
await walletController.refillWallets();
const trialingWallet = records.pop();

await Promise.all(
records.map(async ({ wallet }) => {
await Promise.all([
...records.map(async ({ wallet }) => {
const walletRecord = await userWalletRepository.findById(wallet.id);

expect(walletRecord.feeAllowance).toBe(config.FEE_ALLOWANCE_REFILL_AMOUNT);
}),
userWalletRepository.findById(trialingWallet.wallet.id).then(walletRecord => {
expect(walletRecord.feeAllowance).toBe(config.FEE_ALLOWANCE_REFILL_THRESHOLD);
})
);
]);
});
});
});
4 changes: 2 additions & 2 deletions packages/net/src/generated/netConfigData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const netConfigData = {
],
rpcUrls: [
"https://rpc.akashnet.net:443",
"https://rpc.akash.forbole.com:443",
"https://rpc-akash.ecostake.com:443",
"https://akash-rpc.polkachu.com:443",
"https://akash.c29r3.xyz:443/rpc"
"https://akash.c29r3.xyz:443/rpc",
"https://akash-rpc.europlots.com:443"
]
},
sandbox: {
Expand Down

0 comments on commit 671ea02

Please sign in to comment.