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

fix(billing): use specific endpoint to check managed wallet grants #589

Merged
merged 1 commit into from
Dec 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion apps/api/mvm.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"@akashnetwork/database": "1.0.0",
"@akashnetwork/env-loader": "1.0.1",
"@akashnetwork/http-sdk": "1.1.1",
"@akashnetwork/http-sdk": "1.1.2",
"@akashnetwork/logging": "2.0.2"
}
}
22 changes: 10 additions & 12 deletions apps/api/test/functional/start-trial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { container } from "tsyringe";

import { app } from "@src/app";
import { BILLING_CONFIG, BillingConfig } from "@src/billing/providers";
import { resolveWallet } from "@src/billing/providers/wallet.provider";
import { ApiPgDatabase, POSTGRES_DB, resolveTable } from "@src/core";

import { DbTestingService } from "@test/services/db-testing.service";
Expand Down Expand Up @@ -41,8 +42,9 @@ describe("start trial", () => {
});
const getWalletsResponse = await app.request(`/v1/wallets?userId=${userId}`, { headers });
const userWallet = await userWalletsQuery.findFirst({ where: eq(userWalletsTable.userId, userId) });
const masterWalletAddress = await resolveWallet("MANAGED").getFirstAddress();
const allowances = await Promise.all([
authzHttpService.getDepositDeploymentGrantsForGrantee(userWallet.address),
authzHttpService.getDepositDeploymentGrantsForGranterAndGrantee(masterWalletAddress, userWallet.address),
authzHttpService.getFeeAllowancesForGrantee(userWallet.address)
]);

Expand Down Expand Up @@ -77,17 +79,13 @@ describe("start trial", () => {
isTrialing: true
});
expect(allowances).toMatchObject([
[
{
granter: expect.any(String),
grantee: userWallet.address,
authorization: {
"@type": "/akash.deployment.v1beta3.DepositDeploymentAuthorization",
spend_limit: { denom: config.DEPLOYMENT_GRANT_DENOM, amount: String(config.TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT) }
},
expiration: expect.any(String)
}
],
{
authorization: {
"@type": "/akash.deployment.v1beta3.DepositDeploymentAuthorization",
spend_limit: { denom: config.DEPLOYMENT_GRANT_DENOM, amount: String(config.TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT) }
},
expiration: expect.any(String)
},
[
{
granter: expect.any(String),
Expand Down
2 changes: 1 addition & 1 deletion packages/http-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashnetwork/http-sdk",
"version": "1.1.1",
"version": "1.1.2",
"description": "Package containing http layer for Akash Network",
"keywords": [],
"license": "Apache-2.0",
Expand Down
10 changes: 1 addition & 9 deletions packages/http-sdk/src/authz/authz-http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ export class AuthzHttpService extends HttpService {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getDepositDeploymentGrantsForGrantee(address: string): Promise<DepositDeploymentGrantResponse['grants']> {
// const response = this.extractData(await this.get<DepositDeploymentGrantResponse>(`cosmos/authz/v1beta1/grants/grantee/${address}`));
// return response.grants.filter(grant => this.isValidDepositDeploymentGrant(grant));
return []
}

async getDepositDeploymentGrantsForGranterAndGrantee(granter: string, grantee: string): Promise<ExactDepositDeploymentGrant | undefined> {
const response = this.extractData(
await this.get<DepositDeploymentGrantResponse<ExactDepositDeploymentGrant>>("cosmos/authz/v1beta1/grants", {
Expand All @@ -99,8 +92,7 @@ export class AuthzHttpService extends HttpService {
}

async hasValidDepositDeploymentGrant(granter: string, grantee: string) {
const depositDeploymentGrants = await this.getDepositDeploymentGrantsForGrantee(grantee);
return depositDeploymentGrants.some(allowance => allowance.granter === granter);
return !!(await this.getDepositDeploymentGrantsForGranterAndGrantee(granter, grantee))
}

async paginateDepositDeploymentGrants(
Expand Down
Loading