Skip to content
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
8 changes: 4 additions & 4 deletions apps/api/env/.env.functional.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
POSTGRES_URI=postgres://postgres:password@localhost:5432
UAKT_TOP_UP_MASTER_WALLET_MNEMONIC="since bread kind field rookie stairs elephant tent horror rice gain tongue collect goose rural garment cover client biology toe ability boat afford mind"
USDC_TOP_UP_MASTER_WALLET_MNEMONIC="leaf brush weapon puppy depart hockey walnut hospital orphan require unfair hunt ribbon toe cereal eagle hour door awesome dress mouse when phone return"
NETWORK=sandbox
RPC_NODE_ENDPOINT=https://rpc.sandbox-2.aksh.pw:443
NETWORK=testnet
RPC_NODE_ENDPOINT=https://testnetrpc.akashnet.net
TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT=20000000
DEPLOYMENT_ALLOWANCE_REFILL_AMOUNT=20000000
DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD=2000000
Expand All @@ -19,8 +19,8 @@ STRIPE_WEBHOOK_SECRET=STRIPE_WEBHOOK_SECRET
ALLOWED_CHECKOUT_REFERRERS=["http://localhost:3000"]
STRIPE_CHECKOUT_REDIRECT_URL=http://localhost:3000
DEPLOYMENT_ENV=test
FAUCET_URL=https://faucet.sandbox-2.aksh.pw/faucet
API_NODE_ENDPOINT=https://api.sandbox-2.aksh.pw:443
FAUCET_URL=https://faucet.dev.akash.pub/faucet
API_NODE_ENDPOINT=https://testnetapi.akashnet.net
PROVIDER_PROXY_URL=http://localhost:3040

AUTH0_ISSUER_HOST_WITH_DEFAULT=${AUTH0_ISSUER_HOST:-localhost}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@akashnetwork/akash-api": "^1.3.0",
"@akashnetwork/akashjs": "^0.11.1",
"@akashnetwork/chain-sdk": "1.0.0-alpha.7",
"@akashnetwork/chain-sdk": "^1.0.0-alpha.8",
"@akashnetwork/database": "*",
"@akashnetwork/env-loader": "*",
"@akashnetwork/http-sdk": "*",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/address/services/address/address.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Coin } from "@akashnetwork/chain-sdk/private-types/cosmos.v1beta1";
import { CosmosHttpService } from "@akashnetwork/http-sdk/src/cosmos/cosmos-http.service";
import { LoggerService } from "@akashnetwork/logging";
import { asset_lists } from "@chain-registry/assets";
import type { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { singleton } from "tsyringe";

import type { GetAddressResponse } from "@src/address/http-schemas/address.schema";
Expand Down
47 changes: 30 additions & 17 deletions apps/api/src/bid/http-schemas/bid.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ const DeploymentResource_V3 = z.object({

export const BidResponseSchema = z.object({
bid: z.object({
bid_id: z.object({
id: z.object({
owner: z.string(),
dseq: z.string(),
gseq: z.number(),
oseq: z.number(),
provider: z.string()
provider: z.string(),
bseq: z.number()
}),
state: z.string(),
price: z.object({
Expand All @@ -83,21 +84,33 @@ export const BidResponseSchema = z.object({
scope: z.string(),
xid: z.string()
}),
owner: z.string(),
state: z.string(),
balance: z.object({
denom: z.string(),
amount: z.string()
}),
transferred: z.object({
denom: z.string(),
amount: z.string()
}),
settled_at: z.string(),
depositor: z.string(),
funds: z.object({
denom: z.string(),
amount: z.string()
state: z.object({
owner: z.string(),
state: z.string(),
transferred: z.array(
z.object({
denom: z.string(),
amount: z.string()
})
),
settled_at: z.string(),
funds: z.array(
z.object({
denom: z.string(),
amount: z.string()
})
),
deposits: z.array(
z.object({
owner: z.string(),
height: z.string(),
source: z.string(),
balance: z.object({
denom: z.string(),
amount: z.string()
})
})
)
})
}),
isCertificateRequired: z.boolean()
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/bid/services/bid/bid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class BidService {
}

private async decorateWithCertRequirement<T extends Bid>(bid: T): Promise<T & { isCertificateRequired: boolean }> {
const provider = await this.providerService.getProvider(bid.bid.bid_id.provider);
const provider = await this.providerService.getProvider(bid.bid.id.provider);
return {
...bid,
isCertificateRequired: !provider || !semver.valid(provider.akashVersion) || semver.lt(provider.akashVersion, BidService.JWT_AUTH_SUPPORT_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/billing/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const envSchema = z.object({
TRIAL_FEES_ALLOWANCE_AMOUNT: z.number({ coerce: true }),
TRIAL_DEPLOYMENT_CLEANUP_HOURS: z.number({ coerce: true }).default(24),
DEPLOYMENT_GRANT_DENOM: z.string(),
GAS_SAFETY_MULTIPLIER: z.number({ coerce: true }).default(1.6),
GAS_SAFETY_MULTIPLIER: z.number({ coerce: true }).default(1.8),
AVERAGE_GAS_PRICE: z.number({ coerce: true }).default(0.0025),
FEE_ALLOWANCE_REFILL_THRESHOLD: z.number({ coerce: true }),
FEE_ALLOWANCE_REFILL_AMOUNT: z.number({ coerce: true }),
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/billing/http-schemas/tx.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const SignTxRequestInputSchema = z.object({
.array(
z.object({
typeUrl: z.enum([
"/akash.deployment.v1beta3.MsgCreateDeployment",
"/akash.cert.v1beta3.MsgCreateCertificate",
"/akash.market.v1beta4.MsgCreateLease",
"/akash.deployment.v1beta3.MsgUpdateDeployment",
"/akash.deployment.v1beta3.MsgCloseDeployment",
"/akash.deployment.v1beta3.MsgDepositDeployment"
"/akash.deployment.v1beta4.MsgCreateDeployment",
"/akash.cert.v1.MsgCreateCertificate",
"/akash.market.v1beta5.MsgCreateLease",
"/akash.deployment.v1beta4.MsgUpdateDeployment",
"/akash.deployment.v1beta4.MsgCloseDeployment",
"/akash.deployment.v1beta4.MsgDepositDeployment"
]),
value: z.string()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TxRaw } from "@akashnetwork/chain-sdk/private-types/cosmos.v1beta1";
import { sha256 } from "@cosmjs/crypto";
import { toHex } from "@cosmjs/encoding";
import { Registry } from "@cosmjs/proto-signing";
import type { Account } from "@cosmjs/stargate";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { mock } from "jest-mock-extended";

import type { ChainErrorService } from "@src/billing/services/chain-error/chain-error.service";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TxRaw } from "@akashnetwork/chain-sdk/private-types/cosmos.v1beta1";
import { LoggerService } from "@akashnetwork/logging";
import { sha256 } from "@cosmjs/crypto";
import { toHex } from "@cosmjs/encoding";
import type { EncodeObject, Registry } from "@cosmjs/proto-signing";
import { calculateFee, GasPrice } from "@cosmjs/stargate";
import type { IndexedTx } from "@cosmjs/stargate/build/stargateclient";
import { Sema } from "async-sema";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import DataLoader from "dataloader";
import { backOff } from "exponential-backoff";
import assert from "http-assert";
Expand Down Expand Up @@ -285,7 +285,7 @@ export class BatchSigningClientService {
}

const gasEstimation = await this.simulate(messages, "");
const estimatedGas = Math.round(gasEstimation * this.config.get("GAS_SAFETY_MULTIPLIER"));
const estimatedGas = Math.ceil(gasEstimation * this.config.get("GAS_SAFETY_MULTIPLIER"));

const fee = calculateFee(estimatedGas, GasPrice.fromString(`${this.config.get("AVERAGE_GAS_PRICE")}${denom}`));

Expand Down
27 changes: 23 additions & 4 deletions apps/api/src/billing/providers/type-registry.provider.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import "@src/utils/protobuf";

import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import * as v1 from "@akashnetwork/chain-sdk/private-types/akash.v1";
import * as v1beta4 from "@akashnetwork/chain-sdk/private-types/akash.v1beta4";
import * as v1beta5 from "@akashnetwork/chain-sdk/private-types/akash.v1beta5";
import * as cosmosv1 from "@akashnetwork/chain-sdk/private-types/cosmos.v1";
import * as cosmosv1alpha1 from "@akashnetwork/chain-sdk/private-types/cosmos.v1alpha1";
import * as cosmosv1beta1 from "@akashnetwork/chain-sdk/private-types/cosmos.v1beta1";
import * as cosmosv2alpha1 from "@akashnetwork/chain-sdk/private-types/cosmos.v2alpha1";
import type { GeneratedType } from "@cosmjs/proto-signing";
import { Registry } from "@cosmjs/proto-signing";
import { defaultRegistryTypes } from "@cosmjs/stargate";
import type { InjectionToken } from "tsyringe";
import { container, inject } from "tsyringe";

const registry = new Registry([...defaultRegistryTypes, ...getAkashTypeRegistry()]);
const newAkashTypes: ReadonlyArray<[string, GeneratedType]> = [
...Object.values(v1),
...Object.values(v1beta4),
...Object.values(v1beta5),
...Object.values(cosmosv1),
...Object.values(cosmosv1beta1),
...Object.values(cosmosv1alpha1),
...Object.values(cosmosv2alpha1)
]
.filter(x => "$type" in x)
.map(x => ["/" + x.$type, x as unknown as GeneratedType]);

export const TYPE_REGISTRY = "TYPE_REGISTRY";
const registry = new Registry(newAkashTypes);

export const TYPE_REGISTRY: InjectionToken<Registry> = "TYPE_REGISTRY";

container.register(TYPE_REGISTRY, { useValue: registry });
export const InjectTypeRegistry = () => inject(TYPE_REGISTRY);
11 changes: 1 addition & 10 deletions apps/api/src/billing/services/balances/balances.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,11 @@ export class BalancesService {
const escrowAccount = deployment.escrow_account;
if (!escrowAccount) return total;

if (escrowAccount.balance && escrowAccount.balance.amount) {
total += parseFloat(escrowAccount.balance.amount);
}

if (escrowAccount.funds && escrowAccount.funds.amount) {
total += parseFloat(escrowAccount.funds.amount);
}

return total;
return total + parseFloat(escrowAccount.state.funds.reduce((sum, { amount }) => sum + parseFloat(amount), 0).toFixed(18));
}, 0);

return deploymentEscrowBalance;
}

@Memoize({ ttlInSeconds: averageBlockTime })
async getFullBalance(address: string): Promise<GetBalancesResponseOutput> {
const [balanceData, deploymentEscrowBalance] = await Promise.all([this.getFreshLimits({ address }), this.calculateDeploymentEscrowBalance(address)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe(ChainErrorService.name, () => {
it("returns 400 for Invalid Owner Address error with message prefix", async () => {
const { service } = setup();
const err = new Error("Invalid Owner Address: invalid address message index: 0");
const messages: EncodeObject[] = [{ typeUrl: "/akash.cert.v1beta3.MsgCreateCertificate", value: {} }];
const messages: EncodeObject[] = [{ typeUrl: "/akash.cert.v1.MsgCreateCertificate", value: {} }];

const appErr = await service.toAppError(err, messages);
expect(appErr).toBeInstanceOf(BadRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export class ChainErrorService {
};

private MESSAGE_ERROR_TITLES: Record<string, string> = {
"/akash.deployment.v1beta3.MsgCreateDeployment": "Failed to create deployment",
"/akash.market.v1beta4.MsgCreateLease": "Failed to create lease",
"/akash.cert.v1beta3.MsgCreateCertificate": "Failed to create certificate"
"/akash.deployment.v1beta4.MsgCreateDeployment": "Failed to create deployment",
"/akash.market.v1beta5.MsgCreateLease": "Failed to create lease",
"/akash.cert.v1.MsgCreateCertificate": "Failed to create certificate"
};

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class FinancialStatsService {
SELECT DISTINCT m."relatedDeploymentId" AS "deployment_id"
FROM "transaction" t
INNER JOIN message m ON m."txId"=t.id
WHERE t."memo"='managed wallet tx' AND m.type='/akash.market.v1beta4.MsgCreateLease' AND t.height > 18515430 AND m.height > 18515430 -- 18515430 is height on trial launch (2024-10-17)
WHERE t."memo"='managed wallet tx' AND (m.type='/akash.market.v1beta4.MsgCreateLease' OR m.type='/akash.market.v1beta5.MsgCreateLease') AND t.height > 18515430 AND m.height > 18515430 -- 18515430 is height on trial launch (2024-10-17)
),
trial_leases AS (
SELECT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MsgCreateDeployment } from "@akashnetwork/akash-api/v1beta3";
import { MsgCreateLease } from "@akashnetwork/akash-api/v1beta4";
import { MsgCreateDeployment } from "@akashnetwork/chain-sdk/private-types/akash.v1beta4";
import { MsgCreateLease } from "@akashnetwork/chain-sdk/private-types/akash.v1beta5";
import type { LeaseHttpService } from "@akashnetwork/http-sdk";
import type { MongoAbility } from "@casl/ability";
import { createMongoAbility } from "@casl/ability";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MsgCreateLease } from "@akashnetwork/akash-api/v1beta4";
import { MsgCreateLease } from "@akashnetwork/chain-sdk/private-types/akash.v1beta5";
import { LeaseHttpService } from "@akashnetwork/http-sdk";
import { EncodeObject, Registry } from "@cosmjs/proto-signing";
import { IndexedTx } from "@cosmjs/stargate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class ManagedUserWalletService {
return await this.managedSignerService.executeRootTx(messages);
}

private async authorizeDeploymentSpending(options: any) {
private async authorizeDeploymentSpending(options: SpendingAuthorizationMsgOptions) {
const deploymentAllowanceMsg = this.rpcMessageService.getDepositDeploymentGrantMsg(options);
return await this.managedSignerService.executeRootTx([deploymentAllowanceMsg]);
}
Expand Down
Loading
Loading