Skip to content

Commit dd82157

Browse files
authored
Features/support multi denom payments (akash-network#5)
* Move dataFolder path into env variable * Add usdc payment in indexer * Add usdc support in api * Sandbox fixes * Fixes * Add DataFolder doc
1 parent aaf0781 commit dd82157

22 files changed

+197
-55
lines changed

Diff for: api/src/db/dbConnection.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { chainDefinitions } from "@shared/chainDefinitions";
88

99
const csMap = {
1010
mainnet: env.AkashDatabaseCS,
11-
testnet: env.AkashTestnetDatabaseCS
11+
testnet: env.AkashTestnetDatabaseCS,
12+
sandbox: env.AkashSandboxDatabaseCS
1213
};
1314

1415
if (!(env.Network in csMap)) {

Diff for: api/src/db/networkRevenueProvider.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Day } from "@shared/dbSchemas/base";
33
import { AkashBlock as Block } from "@shared/dbSchemas/akash";
44
import { add } from "date-fns";
55
import { getTodayUTC } from "@src/shared/utils/date";
6-
import { round, uaktToAKT } from "@src/shared/utils/math";
6+
import { round, uaktToAKT, udenomToDenom } from "@src/shared/utils/math";
77

88
export const getWeb3IndexRevenue = async (debug?: boolean) => {
99
const dailyNetworkRevenues = await getDailyRevenue();
@@ -12,6 +12,7 @@ export const getWeb3IndexRevenue = async (debug?: boolean) => {
1212
date: r.date.getTime() / 1000,
1313
revenue: round(r.usd, 2),
1414
revenueUAkt: r.uakt,
15+
revenueUUsdc: r.uusdc,
1516
aktPrice: r.aktPrice,
1617
dateStr: r.date
1718
}));
@@ -40,13 +41,22 @@ export const getWeb3IndexRevenue = async (debug?: boolean) => {
4041
thirtyDaysAgoRevenueUAkt: number = 0,
4142
sixtyDaysAgoRevenueUAkt: number = 0,
4243
ninetyDaysAgoRevenueUAkt: number = 0;
44+
let totalRevenueUUsdc: number = 0,
45+
oneDayAgoRevenueUUsdc: number = 0,
46+
twoDaysAgoRevenueUUsdc: number = 0,
47+
oneWeekAgoRevenueUUsdc: number = 0,
48+
twoWeeksAgoRevenueUUsdc: number = 0,
49+
thirtyDaysAgoRevenueUUsdc: number = 0,
50+
sixtyDaysAgoRevenueUUsdc: number = 0,
51+
ninetyDaysAgoRevenueUUsdc: number = 0;
4352

4453
days.forEach((b) => {
4554
const date = new Date(b.date * 1000);
4655

4756
if (date <= ninetyDaysAgo) {
4857
ninetyDaysAgoRevenue += b.revenue;
4958
ninetyDaysAgoRevenueUAkt += b.revenueUAkt;
59+
ninetyDaysAgoRevenueUUsdc += b.revenueUUsdc;
5060
}
5161
if (date <= sixtyDaysAgo) {
5262
sixtyDaysAgoRevenue += b.revenue;
@@ -121,7 +131,7 @@ async function getDailyRevenue() {
121131
{
122132
model: Block,
123133
as: "lastBlockYet",
124-
attributes: ["totalUAktSpent"],
134+
attributes: ["totalUAktSpent", "totalUUsdcSpent"],
125135
required: true
126136
}
127137
],
@@ -134,13 +144,15 @@ async function getDailyRevenue() {
134144
let stats = result.map((day) => ({
135145
date: day.date,
136146
totalUAktSpent: (day.lastBlockYet as Block).totalUAktSpent,
147+
totalUUsdcSpent: (day.lastBlockYet as Block).totalUUsdcSpent,
137148
aktPrice: day.aktPrice // TODO handle no price
138149
}));
139150

140-
let relativeStats = stats.reduce((arr, dataPoint, index) => {
151+
let relativeStats: { date: Date; uakt: number; uusdc: number; aktPrice: number }[] = stats.reduce((arr, dataPoint, index) => {
141152
arr[index] = {
142153
date: dataPoint.date,
143154
uakt: dataPoint.totalUAktSpent - (index > 0 ? stats[index - 1].totalUAktSpent : 0),
155+
uusdc: dataPoint.totalUUsdcSpent - (index > 0 ? stats[index - 1].totalUUsdcSpent : 0),
144156
aktPrice: dataPoint.aktPrice
145157
};
146158

@@ -151,7 +163,9 @@ async function getDailyRevenue() {
151163
date: x.date,
152164
uakt: x.uakt,
153165
akt: uaktToAKT(x.uakt, 6),
154-
usd: uaktToAKT(x.uakt, 6) * x.aktPrice,
166+
uusdc: x.uusdc,
167+
usdc: udenomToDenom(x.uusdc),
168+
usd: uaktToAKT(x.uakt, 6) * x.aktPrice + udenomToDenom(x.uusdc),
155169
aktPrice: x.aktPrice
156170
}));
157171
}

Diff for: api/src/db/statsProvider.ts

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const getDashboardData = async () => {
3939
dailyLeaseCount: latestBlockStats.totalLeaseCount - compareBlockStats.totalLeaseCount,
4040
totalUAktSpent: latestBlockStats.totalUAktSpent,
4141
dailyUAktSpent: latestBlockStats.totalUAktSpent - compareBlockStats.totalUAktSpent,
42+
totalUUsdcSpent: latestBlockStats.totalUUsdcSpent,
43+
dailyUUsdcSpent: latestBlockStats.totalUUsdcSpent - compareBlockStats.totalUUsdcSpent,
4244
activeCPU: latestBlockStats.activeCPU,
4345
activeGPU: latestBlockStats.activeGPU,
4446
activeMemory: latestBlockStats.activeMemory,
@@ -52,6 +54,8 @@ export const getDashboardData = async () => {
5254
dailyLeaseCount: compareBlockStats.totalLeaseCount - secondCompareBlockStats.totalLeaseCount,
5355
totalUAktSpent: compareBlockStats.totalUAktSpent,
5456
dailyUAktSpent: compareBlockStats.totalUAktSpent - secondCompareBlockStats.totalUAktSpent,
57+
totalUUsdcSpent: compareBlockStats.totalUUsdcSpent,
58+
dailyUUsdcSpent: compareBlockStats.totalUUsdcSpent - secondCompareBlockStats.totalUUsdcSpent,
5559
activeCPU: compareBlockStats.activeCPU,
5660
activeGPU: compareBlockStats.activeGPU,
5761
activeMemory: compareBlockStats.activeMemory,
@@ -152,6 +156,14 @@ export const getProviderGraphData = async (dataName: ProviderStatsKey) => {
152156
true
153157
);
154158

159+
if (result.length < 2) {
160+
return {
161+
currentValue: 0,
162+
compareValue: 0,
163+
snapshots: []
164+
};
165+
}
166+
155167
const currentValue = result[result.length - 1] as ProviderStats;
156168
const compareValue = result[result.length - 2] as ProviderStats;
157169

Diff for: api/src/shared/utils/env.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const env = {
99
HealthchecksEnabled: process.env.HealthchecksEnabled,
1010
AkashDatabaseCS: process.env.AkashDatabaseCS,
1111
AkashTestnetDatabaseCS: process.env.AkashTestnetDatabaseCS,
12+
AkashSandboxDatabaseCS: process.env.AkashSandboxDatabaseCS,
1213
UserDatabaseCS: process.env.UserDatabaseCS,
1314
Network: process.env.Network ?? "mainnet",
1415
RestApiNodeUrl: process.env.RestApiNodeUrl,

Diff for: api/src/shared/utils/math.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ export function round(amount: number, precision: number = 2) {
88

99
export function uaktToAKT(amount: number, precision = 2) {
1010
return round(amount / 1_000_000, precision);
11+
}
12+
13+
export function udenomToDenom(amount: number, precision = 2) {
14+
return round(amount / 1_000_000, precision);
1115
}

Diff for: deploy-web/src/components/deployment/DeploymentListRow.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ export const DeploymentListRow: React.FunctionComponent<Props> = ({ deployment,
231231
title={
232232
<>
233233
<strong>
234-
{udenomToDenom(isActive && hasActiveLeases ? realTimeLeft?.escrow : escrowBalance, 6)}&nbsp;{denomData.label}
234+
{udenomToDenom(isActive && hasActiveLeases ? realTimeLeft?.escrow : escrowBalance, 6)}&nbsp;{denomData?.label}
235235
</strong>
236236
<Box display="flex">
237-
{udenomToDenom(amountSpent, 2)} {denomData.label} spent
237+
{udenomToDenom(amountSpent, 2)} {denomData?.label} spent
238238
</Box>
239239
<br />
240240
The escrow account balance will be fully returned to your wallet balance when the deployment is closed.{" "}
@@ -266,7 +266,7 @@ export const DeploymentListRow: React.FunctionComponent<Props> = ({ deployment,
266266
arrow
267267
title={
268268
<span>
269-
{avgCost} {denomData.label} / month
269+
{avgCost} {denomData?.label} / month
270270
</span>
271271
}
272272
>

Diff for: deploy-web/src/types/deployment.ts

+65-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export interface RpcDeployment {
5858
escrow_account: EscrowAccount;
5959
}
6060

61-
interface DeploymentGroup {
61+
// TODO Change after mainnet6 upgrade
62+
type DeploymentGroup = DeploymentGroup_v2 | DeploymentGroup_v3;
63+
64+
interface DeploymentGroup_v2 {
6265
group_id: {
6366
owner: string;
6467
dseq: string;
@@ -119,6 +122,67 @@ interface DeploymentGroup {
119122
created_at: string;
120123
}
121124

125+
interface DeploymentGroup_v3 {
126+
group_id: {
127+
owner: string;
128+
dseq: string;
129+
gseq: number;
130+
};
131+
state: string;
132+
group_spec: {
133+
name: string;
134+
requirements: {
135+
signed_by: {
136+
all_of: string[];
137+
any_of: string[];
138+
};
139+
attributes: Array<{
140+
key: string;
141+
value: string;
142+
}>;
143+
};
144+
resources: Array<{
145+
resource: {
146+
cpu: {
147+
units: {
148+
val: string;
149+
};
150+
attributes: any[];
151+
};
152+
gpu: {
153+
units: {
154+
val: string;
155+
};
156+
attributes: any[];
157+
};
158+
memory: {
159+
quantity: {
160+
val: string;
161+
};
162+
attributes: any[];
163+
};
164+
storage: Array<{
165+
name: string;
166+
quantity: {
167+
val: string;
168+
};
169+
attributes: any[];
170+
}>;
171+
endpoints: Array<{
172+
kind: string;
173+
sequence_number: number;
174+
}>;
175+
};
176+
count: number;
177+
price: {
178+
denom: string;
179+
amount: string;
180+
};
181+
}>;
182+
};
183+
created_at: string;
184+
}
185+
122186
interface EscrowAccount {
123187
id: {
124188
scope: string;

Diff for: deploy-web/src/utils/deploymentData/v1beta3.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ function validate(yamlJson) {
194194
}
195195
}
196196

197-
export function getManifest(yamlJson) {
198-
const manifest = Manifest(yamlJson, "beta3");
197+
export function getManifest(yamlJson, asString: boolean) {
198+
const manifest = Manifest(yamlJson, "beta3", asString);
199199

200200
return manifest;
201201
}
202202

203203
export async function getManifestVersion(yamlJson, asString = false) {
204-
const version = await ManifestVersion(yamlJson, "beta2");
204+
const version = await ManifestVersion(yamlJson, "beta3");
205205

206206
if (asString) {
207207
return Buffer.from(version).toString("base64");

Diff for: deploy-web/src/utils/deploymentDetailUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { DeploymentDto, LeaseDto, RpcDeployment, RpcLease } from "@src/types/dep
22
import { coinToUAkt } from "./priceUtils";
33

44
export function deploymentResourceSum(deployment: RpcDeployment, resourceSelector) {
5-
return deployment.groups.map(g => g.group_spec.resources.map(r => r.count * resourceSelector(r.resources)).reduce((a, b) => a + b)).reduce((a, b) => a + b);
5+
return deployment.groups.map(g => g.group_spec.resources.map(r => r.count * resourceSelector(r.resources ?? r.resource)).reduce((a, b) => a + b)).reduce((a, b) => a + b);
66
}
77

88
export function deploymentGroupResourceSum(group, resourceSelector) {
99
if (!group || !group.group_spec || !group.group_spec) return 0;
1010

11-
return group.group_spec.resources.map(r => r.count * resourceSelector(r.resources)).reduce((a, b) => a + b);
11+
return group.group_spec.resources.map(r => r.count * resourceSelector(r.resources ?? r.resource)).reduce((a, b) => a + b);
1212
}
1313

1414
export function deploymentToDto(d: RpcDeployment): DeploymentDto {

Diff for: deploy-web/src/utils/networks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ export let networks = [
124124
title: "Sandbox",
125125
description: "Sandbox of the mainnet version.",
126126
nodesUrl: sandboxNodes,
127-
chainId: "sandbox",
127+
chainId: "sandbox-01",
128128
versionUrl: ApiUrlService.sandboxVersion(),
129129
version: null, // Set asynchronously
130130
enabled: true,
131131
suggestKeplrChain: async () => {
132132
await window.keplr.experimentalSuggestChain({
133133
// Chain-id of the Craft chain.
134-
chainId: "sandbox",
134+
chainId: "sandbox-01",
135135
// The name of the chain to be displayed to the user.
136136
chainName: "Akash-Sandbox",
137137
// RPC endpoint of the chain. In this case we are using blockapsis, as it's accepts connections from any host currently. No Cors limitations.

Diff for: deploy-web/src/utils/proto/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function initProtoTypes() {
1515
protoTypes = v1beta3;
1616
break;
1717
case sandboxId:
18-
protoTypes = v1beta2;
18+
protoTypes = v1beta3;
1919
break;
2020

2121
default:

Diff for: indexer/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ AkashDatabaseCS|ex: `postgres://user:password@localhost:5432/cloudmos-akash`|Aka
3131
ActiveChain|ex: `akash`|Chain code from [chainDefinitions.ts](../shared/chainDefinitions.ts)
3232
KeepCache|`true` or `false`|Specify if the [block & block response cache](#block-cache-structure) should be kept on drive. Takes a lot of space, but allow rebuilding the database without redownloading every blocks.
3333
Standby|`true` or `false`|If `true`, indexer will not start. Useful for stopping an indexer deployed on akash without needing to close the lease.
34+
DataFolder|ex: `./data/`|Directory where block cache and node statuses should be saved. Defaults to `./data/`.
3435

3536
## Scheduled Tasks
3637

Diff for: indexer/package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: indexer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"homepage": "https://github.com/akash-network/cloudmos",
2121
"dependencies": {
22-
"@akashnetwork/akashjs": "0.4.5",
22+
"@akashnetwork/akashjs": "0.4.11",
2323
"@cosmjs/crypto": "^0.28.11",
2424
"@cosmjs/encoding": "^0.28.11",
2525
"@cosmjs/math": "^0.28.11",

Diff for: indexer/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { bytesToHumanReadableSize } from "./shared/utils/files";
1313
import { getCacheSize } from "./chain/dataStore";
1414
import { env } from "./shared/utils/env";
1515
import { nodeAccessor } from "./chain/nodeAccessor";
16-
import { activeChain } from "@shared/chainDefinitions";
16+
import { activeChain, chainDefinitions } from "@shared/chainDefinitions";
1717
import { addressBalanceMonitor, deploymentBalanceMonitor } from "./monitors";
1818
import { updateProvidersLocation } from "./providers/ipLocationProvider";
1919
import { sleep } from "./shared/utils/delay";
@@ -124,6 +124,10 @@ async function initApp() {
124124
}
125125
}
126126

127+
if (!(process.env.ActiveChain in chainDefinitions)) {
128+
throw new Error(`Unknown chain with code: ${process.env.ActiveChain}`);
129+
}
130+
127131
await initDatabase();
128132
await nodeAccessor.loadNodeStatus();
129133

0 commit comments

Comments
 (0)