Skip to content

Commit 44ed7dc

Browse files
committed
Fix SubQL ECS image manifests
1 parent 5442a01 commit 44ed7dc

28 files changed

Lines changed: 353 additions & 4790 deletions

.dockerignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ node_modules
44

55
# Build artifacts
66
dist
7+
**/dist
78
build
9+
**/build
810
*.tsbuildinfo
9-
!packages/*/dist
10-
!packages/*/dist/**
1111

1212
# Git
1313
.git

.github/workflows/docker.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ jobs:
7070
bun install
7171
bun run build
7272
73+
- name: Verify dex bundle
74+
working-directory: packages/dex-subql
75+
run: |
76+
bun run test
77+
if grep -R "rpc\\.oracle\\.getValue" dist; then
78+
echo "Built dex output still contains stale direct rpc.oracle.getValue"
79+
exit 1
80+
fi
81+
7382
- name: Set up Docker Buildx
7483
uses: docker/setup-buildx-action@v4
7584
with:
@@ -117,6 +126,14 @@ jobs:
117126
bun install
118127
bun run build
119128
129+
- name: Verify dex fixed bundle
130+
working-directory: packages/dex-subql-fixed
131+
run: |
132+
if grep -R "rpc\\.oracle\\.getValue" dist; then
133+
echo "Built dex-fixed output still contains stale direct rpc.oracle.getValue"
134+
exit 1
135+
fi
136+
120137
- name: Set up Docker Buildx
121138
uses: docker/setup-buildx-action@v4
122139
with:

packages/chain-stats-subql/acala-project.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
specVersion: 1.0.0
2-
name: acala-tokens
2+
name: acala-stats
33
version: 1.0.0
44
description: 'statistics tokens data'
55
repository: 'https://github.com/AcalaNetwork/acala-subql-services'
@@ -96,4 +96,4 @@ dataSources:
9696
kind: substrate/EventHandler
9797
filter:
9898
module: tokens
99-
method: Slashed
99+
method: Slashed

packages/chain-stats-subql/karura-project.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
specVersion: 1.0.0
2-
name: karura-tokens
2+
name: karura-stats
33
version: 1.0.0
44
description: 'statistics tokens data of karura network'
55
repository: 'https://github.com/AcalaNetwork/acala-subql-services'
@@ -96,4 +96,4 @@ dataSources:
9696
kind: substrate/EventHandler
9797
filter:
9898
module: tokens
99-
method: Slashed
99+
method: Slashed

packages/chain-stats-subql/project.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
specVersion: 1.0.0
2-
name: acala-tokens
2+
name: acala-stats
33
version: 1.0.0
44
description: 'statistics tokens data'
55
repository: 'https://github.com/AcalaNetwork/acala-tokens-subql'

packages/dex-subql-fixed/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ COPY packages/dex-subql-fixed/package.json packages/dex-subql-fixed/bun.lock ./
1616
RUN bun install
1717
COPY packages/dex-subql-fixed/ ./
1818
RUN set -e \
19-
&& if [ -d /app/dist ]; then \
20-
echo "Using prebuilt dist from build context"; \
21-
else \
22-
./node_modules/.bin/subql codegen; \
23-
./node_modules/.bin/subql build --output dist; \
24-
fi \
19+
&& rm -rf /app/dist \
20+
&& ./node_modules/.bin/subql codegen \
21+
&& ./node_modules/.bin/subql build --output dist \
2522
&& for i in 1 2 3 4 5; do [ -d /app/dist ] && break; sleep 1; done \
2623
&& if [ ! -d /app/dist ]; then \
2724
echo "SubQL build did not create /app/dist"; \
@@ -35,6 +32,10 @@ RUN set -e \
3532
&& if [ -f /app/src/chaintypes.ts ] && [ ! -f /app/dist/chaintypes.js ]; then \
3633
./node_modules/.bin/tsc /app/src/chaintypes.ts --module commonjs --target es2019 --esModuleInterop --skipLibCheck --outDir /app/dist; \
3734
fi \
35+
&& if grep -R "rpc\\.oracle\\.getValue" /app/dist; then \
36+
echo "Built dex-fixed output still contains stale direct rpc.oracle.getValue"; \
37+
exit 1; \
38+
fi \
3839
&& ls -la /app/dist \
3940
&& echo "Build completed successfully"
4041

packages/dex-subql-fixed/bun.lock

Lines changed: 18 additions & 2493 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dex-subql-fixed/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"dependencies": {
2525
"@acala-network/sdk-core": "^4.1.6-30",
2626
"@acala-network/sdk-wallet": "^4.1.6-30",
27-
"@acala-network/subql-utils": "^0.1.23",
2827
"@acala-network/type-definitions": "latest",
2928
"@open-web3/util": "^1.1.4",
3029
"dayjs": "^1.10.7"

packages/dex-subql-fixed/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dotenv.config({ path: dotenvPath });
1717
const project: SubstrateProject = {
1818
specVersion: "1.0.0",
1919
version: "0.0.1",
20-
name: "acala-starter",
20+
name: "acala-dex",
2121
description:
2222
"This project can be used as a starting point for developing your SubQuery project. It indexes all transfers on Acala network",
2323
runner: {

packages/dex-subql-fixed/src/utils/queryPrice.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
import { AnyApi, FixedPointNumber as FN, MaybeCurrency, Token, forceToCurrencyId } from "@acala-network/sdk-core";
22
import { SubstrateBlock } from '@subql/types/dist/interfaces';
3-
import { getPool, getToken } from ".";
3+
import { getBlock, getPool, getToken } from "./record";
44
import { getTokenName } from './getTokenName';
55
import { PriceBundle } from "../types";
6-
import { queryPriceFromOracle } from "@acala-network/subql-utils";
6+
7+
const getOracleValue = async (api: AnyApi, token: MaybeCurrency) => {
8+
const currencyId = forceToCurrencyId(api as any, token);
9+
const query = (api as any)?.query?.acalaOracle?.values || (api as any)?.query?.oracle?.values;
10+
11+
if (query) {
12+
return query(currencyId);
13+
}
14+
15+
const getValue = (api as any)?.rpc?.oracle?.getValue;
16+
17+
if (typeof getValue === 'function') {
18+
return getValue('Aggregated', currencyId);
19+
}
20+
21+
throw new Error(`Oracle price source is unavailable for ${getTokenName(token)}`);
22+
}
23+
24+
const queryPriceFromOracle = async (api: AnyApi, _block: SubstrateBlock, token: MaybeCurrency) => {
25+
const result = await getOracleValue(api, token);
26+
const value = result?.unwrapOrDefault?.() || result;
27+
28+
return FN.fromInner(value?.value?.value?.toString() || value?.value?.toString() || 0, 18);
29+
}
30+
31+
export const ensurePriceBundleBlock = async (block: SubstrateBlock) => {
32+
const blockId = block.block.header.number.toString();
33+
const blockRecord = await getBlock(blockId);
34+
35+
blockRecord.hash = block.block.hash.toString();
36+
blockRecord.number = BigInt(blockId);
37+
blockRecord.timestamp = block.timestamp;
38+
39+
await blockRecord.save();
40+
41+
return blockRecord;
42+
}
743

844
const getOtherPrice = async (api: AnyApi, block: SubstrateBlock, token: string, stakingCurrency: string, StableCurrency: string) => {
945
const { rate: rateA, amount: _amountA } = await getPriceFromDexPool(token, stakingCurrency);
@@ -154,11 +190,12 @@ export const getStablePriceBundle = async (api: AnyApi, block: SubstrateBlock, t
154190

155191
if (!record) {
156192
const price = token === 'KUSD' ? await getKusdMarketPrice(api, block) : await getAusdMarketPrice(api, block);
193+
const blockRecord = await ensurePriceBundleBlock(block);
157194

158195
record = new PriceBundle(id);
159196

160197
record.tokenId = token
161-
record.blockId = block.block.header.number.toString();
198+
record.blockId = blockRecord.id;
162199
record.price = BigInt((price || FN.ZERO).toChainData())
163200

164201
await record.save();

0 commit comments

Comments
 (0)