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

[ECO-2671] Add new SDK types and bump processor submodule for the new base_ volume fields #513

Merged
merged 11 commits into from
Jan 22, 2025
2 changes: 2 additions & 0 deletions .github/workflows/sdk-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
with:
destination_directory: '/usr/local/bin'
- env:
EMOJICOIN_ARENA_MODULE_ADDRESS: >-
0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d
NEXT_PUBLIC_MODULE_ADDRESS: >-
0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d
PUBLISHER_PRIVATE_KEY: >-
Expand Down
3 changes: 3 additions & 0 deletions src/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ services:
GRPC_DATA_SERVICE_URL: '${GRPC_DATA_SERVICE_URL}'
MINIMUM_STARTING_VERSION: '${MINIMUM_STARTING_VERSION}'
EMOJICOIN_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}'
EMOJICOIN_ARENA_MODULE_ADDRESS: '${EMOJICOIN_ARENA_MODULE_ADDRESS}'
WS_PORT: '${PROCESSOR_WS_PORT}'
depends_on:
postgres:
Expand Down Expand Up @@ -110,6 +111,7 @@ services:
NEXT_PUBLIC_INTEGRATOR_FEE_RATE_BPS: '${FEE_RATE_BPS}'
NEXT_PUBLIC_IS_ALLOWLIST_ENABLED: 'false'
NEXT_PUBLIC_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}'
NEXT_PUBLIC_ARENA_MODULE_ADDRESS: '${EMOJICOIN_ARENA_MODULE_ADDRESS}'
NEXT_PUBLIC_BROKER_URL: 'ws://host.docker.internal:${BROKER_PORT}'
NEXT_PUBLIC_REWARDS_MODULE_ADDRESS: >-
${EMOJICOIN_REWARDS_MODULE_ADDRESS}
Expand All @@ -126,6 +128,7 @@ services:
NEXT_PUBLIC_INTEGRATOR_FEE_RATE_BPS: '${FEE_RATE_BPS}'
NEXT_PUBLIC_IS_ALLOWLIST_ENABLED: 'false'
NEXT_PUBLIC_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}'
NEXT_PUBLIC_ARENA_MODULE_ADDRESS: '${EMOJICOIN_ARENA_MODULE_ADDRESS}'
NEXT_PUBLIC_BROKER_URL: 'ws://host.docker.internal:${BROKER_PORT}'
NEXT_PUBLIC_REWARDS_MODULE_ADDRESS: '${EMOJICOIN_REWARDS_MODULE_ADDRESS}'
REVALIDATION_TIME: '${REVALIDATION_TIME}'
Expand Down
3 changes: 3 additions & 0 deletions src/docker/deployer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ COPY src/move/rewards/Move.toml move/rewards/Move.toml
COPY src/move/market_metadata/sources/* move/market_metadata/sources/
COPY src/move/market_metadata/Move.toml move/market_metadata/Move.toml

COPY src/move/emojicoin_arena/sources/* move/emojicoin_arena/sources/
COPY src/move/emojicoin_arena/Move.toml move/emojicoin_arena/Move.toml

RUN mkdir json

COPY src/docker/deployer/sh/* sh/
Expand Down
15 changes: 8 additions & 7 deletions src/docker/deployer/sh/build-publish-payloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ aptos move build-publish-payload \
--skip-fetch-latest-git-deps \
--move-2

aptos move build-publish-payload \
--assume-yes \
--named-addresses market_metadata=$profile,emojicoin_dot_fun=$profile \
--package-dir $move_dir/market_metadata/ \
--json-output-file $json_dir/market_metadata.json \
--skip-fetch-latest-git-deps \
--move-2
# aptos move build-publish-payload \
# --assume-yes \
# --named-addresses $arena_addresses \
# emojicoin_arena=$profile,integrator=$profile,emojicoin_dot_fun=$profile"
# --package-dir $move_dir/emojicoin_arena/ \
# --json-output-file $json_dir/emojicoin_arena.json \
# --skip-fetch-latest-git-deps \
# --move-2
7 changes: 7 additions & 0 deletions src/docker/deployer/sh/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ fund_and_publish() {
--max-gas 2000000 \
--gas-unit-price $gas_unit_price \
--profile $profile

# aptos move run \
# --assume-yes \
# --json-file /app/json/emojicoin_arena.json \
# --max-gas 2000000 \
# --gas-unit-price $gas_unit_price \
# --profile $profile
}

fund_test_accounts() {
Expand Down
3 changes: 3 additions & 0 deletions src/docker/example.local.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ EMOJICOIN_REWARDS_MODULE_ADDRESS="0xf000d910b99722d201c6cf88eb7d1112b43475b9765b
# used in all other contexts at runtime.
EMOJICOIN_INTEGRATOR_ADDRESS="0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d"

# This is the package address of the arena module.
EMOJICOIN_ARENA_MODULE_ADDRESS="0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d"

# The GRPC endpoint from which the indexer receives event data. Aptos Labs
# runs several public endpoints, listed below.
#
Expand Down
4 changes: 4 additions & 0 deletions src/docker/example.testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ EMOJICOIN_MODULE_ADDRESS="0x11113ddc70ea051ffd8a7cde7b96818326aabf56fdfd47807f77
# This is the package address of the rewards wrapper smart contract.
EMOJICOIN_REWARDS_MODULE_ADDRESS="0x22227920701e36651a6649be2067cd7eebf3fabb94717ff3b256e3ada58b2222"

# This is the package address of the arena module.
# NOTE: This is not the same as the REWARDS address.
EMOJICOIN_ARENA_MODULE_ADDRESS="0x2222e4c4788e34e21bacad364855f5e648c19f4643f20f22f507334d041c2222"

# This is the address that receives fees generated by any `emojicoin_dot_fun`
# smart contract. It is passed to the rewards contract at compile time, but
# used in all other contexts at runtime.
Expand Down
2 changes: 1 addition & 1 deletion src/docker/localnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cspell:word localnet

FROM econialabs/aptos-cli:4.1.0
FROM econialabs/aptos-cli:4.4.0

RUN apt-get update && apt-get install --no-install-recommends -y bc=1.07* \
&& rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion src/rust/processor
Submodule processor updated 21 files
+14 −0 rust/processor/src/db/common/models/emojicoin_models/constants.rs
+73 −3 rust/processor/src/db/common/models/emojicoin_models/enums.rs
+180 −0 rust/processor/src/db/common/models/emojicoin_models/json_types.rs
+60 −0 rust/processor/src/db/common/models/emojicoin_models/models/arena_enter_event.rs
+54 −0 rust/processor/src/db/common/models/emojicoin_models/models/arena_exit_event.rs
+50 −0 rust/processor/src/db/common/models/emojicoin_models/models/arena_melee_event.rs
+56 −0 rust/processor/src/db/common/models/emojicoin_models/models/arena_swap_event.rs
+39 −0 rust/processor/src/db/common/models/emojicoin_models/models/arena_vault_balance_update_event.rs
+3 −1 rust/processor/src/db/common/models/emojicoin_models/models/market_1m_periods_in_last_day.rs
+4 −2 rust/processor/src/db/common/models/emojicoin_models/models/market_24h_rolling_volume.rs
+2 −0 rust/processor/src/db/common/models/emojicoin_models/models/market_latest_state_event.rs
+5 −0 rust/processor/src/db/common/models/emojicoin_models/models/mod.rs
+84 −0 rust/processor/src/db/common/models/emojicoin_models/queries/insertion_queries.rs
+95 −0 rust/processor/src/db/postgres/migrations/2024-12-18-143643_add_daily_base_volume/down.sql
+116 −0 rust/processor/src/db/postgres/migrations/2024-12-18-143643_add_daily_base_volume/up.sql
+34 −0 rust/processor/src/db/postgres/migrations/2025-01-08-171729_emojicoin_arena/down.sql
+374 −0 rust/processor/src/db/postgres/migrations/2025-01-08-171729_emojicoin_arena/up.sql
+60 −0 rust/processor/src/db/postgres/migrations/2025-01-21-033858_add_daily_base_volume_to_user_pools/down.sql
+62 −0 rust/processor/src/db/postgres/migrations/2025-01-21-033858_add_daily_base_volume_to_user_pools/up.sql
+151 −0 rust/processor/src/db/postgres/schema.rs
+173 −31 rust/processor/src/processors/emojicoin_dot_fun/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export function getEventsAsProcessorModels(
dailyTvlPerLPCoinGrowth: "0",
inBondingCurve: true,
volumeIn1MStateTracker: 0n,
baseVolumeIn1MStateTracker: 0n,
};

// Convert the eventGroup data to the processor's `latest market state event` model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export const getMiscLatestStateEventFieldsFromWriteSet = (response: UserTransact
(p) => rawPeriodToEnum(p.period) === Period.Period1M
)?.volumeQuote;

const baseVolumeIn1MStateTracker = marketResource.periodicStateTrackers.find(
(p) => rawPeriodToEnum(p.period) === Period.Period1M
)?.volumeBase;

const periodicStateTracker1D = marketResource.periodicStateTrackers.find(
(p) => rawPeriodToEnum(p.period) === Period.Period1D
);

if (volumeIn1MStateTracker === undefined) {
if (volumeIn1MStateTracker === undefined || baseVolumeIn1MStateTracker === undefined) {
throw new Error("There should be a 1M periodic state tracker in the Market resource.");
}

Expand All @@ -45,6 +49,7 @@ export const getMiscLatestStateEventFieldsFromWriteSet = (response: UserTransact
dailyTvlPerLPCoinGrowth,
inBondingCurve,
volumeIn1MStateTracker,
baseVolumeIn1MStateTracker,
};
};

Expand Down
9 changes: 9 additions & 0 deletions src/typescript/sdk/src/indexer-v2/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,20 @@ export const toLiquidityEventModel = (data: DatabaseJsonType["liquidity_events"]
...GuidGetters.liquidityEvent(data),
});

/**
* Default to 0n while the processor is in need of a cold upgrade, otherwise the /stats
* page will fail to render and the build can't complete. This is temporary.
*/
const temporarilyDefaultToZero = (value: AnyNumberString) => BigInt(value ?? 0n);

// Note that daily TVL defaults to `0` since that's the initial value in the database.
export const toProcessedData = (
data: ProcessedFields & { daily_tvl_per_lp_coin_growth_q64?: string }
) => ({
dailyTvlPerLPCoinGrowth: Big(data.daily_tvl_per_lp_coin_growth ?? 0).toString(),
inBondingCurve: data.in_bonding_curve,
volumeIn1MStateTracker: BigInt(data.volume_in_1m_state_tracker),
baseVolumeIn1MStateTracker: temporarilyDefaultToZero(data.base_volume_in_1m_state_tracker),
});

export const toMarketLatestStateEventModel = (
Expand All @@ -533,6 +540,7 @@ export const toMarketLatestStateEventModel = (
export const toMarketStateModel = (data: DatabaseJsonType["market_state"]) => ({
...toMarketLatestStateEventModel(data),
dailyVolume: BigInt(data.daily_volume),
dailyBaseVolume: temporarilyDefaultToZero(data.daily_base_volume),
});

export const toTransactionMetadataForUserLiquidityPools = (
Expand Down Expand Up @@ -578,6 +586,7 @@ export const toMarket1MPeriodsInLastDay = (
insertedAt: data.inserted_at ? postgresTimestampToDate(data.inserted_at) : new Date(0),
nonce: BigInt(data.nonce),
volume: BigInt(data.volume),
baseVolume: BigInt(data.base_volume),
startTime: data.start_time,
});

Expand Down
3 changes: 3 additions & 0 deletions src/typescript/sdk/src/indexer-v2/types/json-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export type ProcessedFields = {
daily_tvl_per_lp_coin_growth: UnsizedDecimalString;
in_bonding_curve: boolean;
volume_in_1m_state_tracker: Uint128String;
base_volume_in_1m_state_tracker: Uint128String;
};

type UserLPCoinBalance = {
Expand Down Expand Up @@ -354,10 +355,12 @@ export type DatabaseJsonType = {
inserted_at?: PostgresTimestamp; // Omitted if the data is transmitted from the broker.
nonce: Uint64String;
volume: Uint128String;
base_volume: Uint128String;
start_time: PostgresTimestamp;
};
[TableName.MarketState]: DatabaseJsonType["market_latest_state_event"] & {
daily_volume: Uint128String;
daily_base_volume: Uint128String;
};
[TableName.ProcessorStatus]: {
processor: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const floatColumns: Set<AnyColumnName> = new Set([
"volume_in_1m_state_tracker",
"daily_volume",
"volume",
"base_volume",
"base_volume_in_1m_state_tracker",
"daily_base_volume",
]);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ describe("queries a market by market state with the emojicoin client", () => {
// Copy over the daily volume because we can't get that field from the mini processor.
(stateFromMiniProcessor as MarketStateModel).dailyVolume =
stateFromIndexerProcessor!.dailyVolume;
// Copy over the daily base volume because we can't get that field from the mini processor.
(stateFromMiniProcessor as MarketStateModel).dailyBaseVolume =
stateFromIndexerProcessor!.dailyBaseVolume;
// Copy over the `insertedAt` field because it's inserted at insertion time in postgres.
(stateFromMiniProcessor as MarketStateModel).transaction.insertedAt =
stateFromIndexerProcessor!.transaction.insertedAt;
Expand Down
6 changes: 6 additions & 0 deletions src/typescript/sdk/tests/e2e/queries/equality-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,16 @@ const MarketLatestState = (row: MarketLatestStateEventModel, response: UserTrans
(p) => rawPeriodToEnum(p.period) === Period.Period1M
)!.volumeQuote;

const baseVolumeInStateTrackerFromWriteSet = marketResource.periodicStateTrackers.find(
(p) => rawPeriodToEnum(p.period) === Period.Period1M
)!.volumeBase;

const periodicStateTracker1D = marketResource.periodicStateTrackers.find(
(p) => rawPeriodToEnum(p.period) === Period.Period1D
)!;

expect(volumeInStateTrackerFromWriteSet).toBeDefined();
expect(baseVolumeInStateTrackerFromWriteSet).toBeDefined();
expect(periodicStateTracker1D).toBeDefined();

compareMarketAndStateMetadata(row, stateEvent);
Expand All @@ -504,6 +509,7 @@ const MarketLatestState = (row: MarketLatestStateEventModel, response: UserTrans
expect(row.dailyTvlPerLPCoinGrowth).toEqual(calculateTvlGrowth(periodicStateTracker1D));
expect(row.inBondingCurve).toEqual(stateEvent.lpCoinSupply === BigInt(0));
expect(row.volumeIn1MStateTracker).toEqual(volumeInStateTrackerFromWriteSet);
expect(row.baseVolumeIn1MStateTracker).toEqual(baseVolumeInStateTrackerFromWriteSet);
};

const RowEqualityChecks = {
Expand Down
3 changes: 3 additions & 0 deletions src/typescript/sdk/tests/e2e/queries/market-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ describe("queries a market by market state", () => {
// Copy over the daily volume because we can't get that field from the mini processor.
(stateFromMiniProcessor as MarketStateModel).dailyVolume =
stateFromIndexerProcessor.dailyVolume;
// Copy over the daily base volume because we can't get that field from the mini processor.
(stateFromMiniProcessor as MarketStateModel).dailyBaseVolume =
stateFromIndexerProcessor!.dailyBaseVolume;
// Copy over the `insertedAt` field because it's inserted at insertion time in postgres.
(stateFromMiniProcessor as MarketStateModel).transaction.insertedAt =
stateFromIndexerProcessor.transaction.insertedAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const TestData = {
":false,"last_swap_avg_execution_price_q64":150958365430955,"last_swap_base_volume":120975585426
07,"last_swap_quote_volume":99000000,"last_swap_nonce":2,"last_swap_time":"2024-10-04T09:29:38.6
9085","daily_tvl_per_lp_coin_growth":0,"in_bonding_curve":true,"volume_in_1m_state_tracker":9900
0000,"daily_volume":99000000}]
0000,"daily_volume":99000000,"base_volume_in_1m_state_tracker":12097558542607,"daily_base_volume
":12097558542607}]
`.replaceAll(/\s/g, ""),
},
postBondingCurve: {
Expand All @@ -62,7 +63,8 @@ const TestData = {
4":7244903199401139,"last_swap_base_volume":756212034737,"last_swap_quote_volume":297000000,"las
t_swap_nonce":47667,"last_swap_time":"2024-10-03T15:55:08.649388","daily_tvl_per_lp_coin_growth"
:1.001499814363967876933091555675361179387333896289378370590041427871042284306953206420708127389
545305,"in_bonding_curve":false,"volume_in_1m_state_tracker":297000000,"daily_volume":0}]
545305,"in_bonding_curve":false,"volume_in_1m_state_tracker":297000000,"daily_volume":0,"base_vo
lume_in_1m_state_tracker":756212034737,"daily_base_volume":0}]
`.replaceAll(/\s/g, ""),
},
};
Expand Down
4 changes: 4 additions & 0 deletions src/typescript/sdk/tests/unit/event-parser/goldens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ const BondingCurveStates: {
dailyTvlPerLPCoinGrowth: "0",
inBondingCurve: true,
volumeIn1MStateTracker: 99000000n,
baseVolumeIn1MStateTracker: 12097558542607n,
dailyVolume: 99000000n,
dailyBaseVolume: 12097558542607n,
eventName: "State",
guid: "😉🙃::State::2",
},
Expand Down Expand Up @@ -311,7 +313,9 @@ const BondingCurveStates: {
042284306953206420708127389545305`.replaceAll(/\s/g, ""),
inBondingCurve: false,
volumeIn1MStateTracker: 297000000n,
baseVolumeIn1MStateTracker: 756212034737n,
dailyVolume: 0n,
dailyBaseVolume: 0n,
eventName: "State",
guid: "💻⚡::State::47668",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cumulative_stats_quote_volume": 198321507000,
"daily_tvl_per_lp_coin_growth": 1.001499814363967876933091555675361179387333896289378370590041427871042284306953206420708127389545305,
"daily_volume": 0,
"daily_base_volume": 0,
"entry_function": "0x11113ddc70ea051ffd8a7cde7b96818326aabf56fdfd47807f7700e2b46e1111::emojicoin_dot_fun::provide_liquidity",
"in_bonding_curve": false,
"inserted_at": "2024-10-03T01:09:52.037678",
Expand All @@ -41,7 +42,8 @@
"transaction_timestamp": "2024-10-03T15:55:32.080509",
"transaction_version": 6080639845,
"trigger": "provide_liquidity",
"volume_in_1m_state_tracker": 297000000
"volume_in_1m_state_tracker": 297000000,
"base_volume_in_1m_state_tracker": 756212034737
}
],
"pre_bonding_curve": [
Expand All @@ -60,6 +62,7 @@
"cumulative_stats_quote_volume": 99000000,
"daily_tvl_per_lp_coin_growth": 0,
"daily_volume": 99000000,
"daily_base_volume": 12097558542607,
"entry_function": "0x22227920701e36651a6649be2067cd7eebf3fabb94717ff3b256e3ada58b2222::emojicoin_dot_fun_rewards::swap_with_rewards",
"in_bonding_curve": true,
"inserted_at": "2024-10-04T09:29:14.65541",
Expand All @@ -86,7 +89,8 @@
"transaction_timestamp": "2024-10-04T09:29:38.69085",
"transaction_version": 6084169932,
"trigger": "swap_buy",
"volume_in_1m_state_tracker": 99000000
"volume_in_1m_state_tracker": 99000000,
"base_volume_in_1m_state_tracker": 12097558542607
}
]
}
Loading