diff --git a/docs/schemas/delegatedStaking.yml b/docs/schemas/delegatedStaking.yml index 8f42902..37088ad 100644 --- a/docs/schemas/delegatedStaking.yml +++ b/docs/schemas/delegatedStaking.yml @@ -7,9 +7,9 @@ components: ordinal: { type: integer } source: { type: string } nodeId: { type: string } - amount: { type: string, description: "BigInt represented as a string" } + amount: { type: string, description: "Effective stake amount (current amount if increased, otherwise original). BigInt represented as a string" } fee: { type: string, description: "BigInt represented as a string" } - tokenLockHash: { type: string } + tokenLockHash: { type: string, description: "Effective token lock hash (current if stake increased, otherwise original)" } parentHash: { type: string, nullable: true } type: { type: string, enum: [create, transfer] } status: { type: string, enum: [active, transferred, pendingWithdrawal, withdrawalComplete] } @@ -33,7 +33,7 @@ components: nodeId: { type: string } status: { type: string, enum: [active, transferred, pendingWithdrawal, withdrawalComplete] } stakeHash: { type: string } - lockAmount: { type: string, description: "BigInt represented as a string" } + lockAmount: { type: string, description: "Effective locked stake amount (current amount if increased, otherwise original). BigInt represented as a string" } rewardsAccrued: { type: string, description: "BigInt represented as a string" } withdrawnAmount: { type: string, description: "BigInt represented as a string" } transferredFromHash: { type: string, nullable: true } diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6aca504..d96161f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -601,8 +601,10 @@ model delegate_stake_create_events { parent_hash String @db.VarChar global_snapshot_hash String @db.VarChar transfer_from_hash String? @unique @db.VarChar - created_at DateTime @default(now()) @db.Timestamp(6) - updated_at DateTime @default(now()) @db.Timestamp(6) + created_at DateTime @default(now()) @db.Timestamp(6) + updated_at DateTime @default(now()) @db.Timestamp(6) + current_token_lock_hash String? @db.VarChar + current_amount BigInt? global_snapshot global_snapshots @relation(fields: [global_snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: Restrict) addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: Restrict) @@ -617,6 +619,7 @@ model delegate_stake_create_events { @@index([global_snapshot_hash]) @@index([source_addr]) @@index([lock_reference_hash]) + @@index([current_token_lock_hash]) } model delegate_stake_withdraw_events { diff --git a/prisma/seed.ts b/prisma/seed.ts index 4a3b080..bbf0fdb 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -185,6 +185,16 @@ export const data_dag_token_locks = [ round_id: randomUUID(), snapshot_hash: data_global_snapshots[1].hash, }, + { + hash: `token-lock-hash-004`, + currency_id: "currency-2", + source_addr: data_addresses[1].address, + amount: 5000000000000n, + ordinal: 4n, + unlock_epoch: 10n, + round_id: randomUUID(), + snapshot_hash: data_global_snapshots[2].hash, + }, ]; // Test data for DAG token unlocks @@ -555,6 +565,8 @@ export const data_delegate_stake_create_events = [ lock_reference_hash: data_dag_token_locks[1].hash, parent_hash: "stake-event-hash-001", global_snapshot_hash: data_global_snapshots[1].hash, + current_token_lock_hash: data_dag_token_locks[3].hash, + current_amount: 5000000000000n, }, { hash: "stake-event-hash-003", diff --git a/src/handlers/delegatedStakingHandler.ts b/src/handlers/delegatedStakingHandler.ts index 363ca86..6e8d71b 100644 --- a/src/handlers/delegatedStakingHandler.ts +++ b/src/handlers/delegatedStakingHandler.ts @@ -47,9 +47,9 @@ const delegateStakeCreateResponse = (event) => ({ ordinal: event.ordinal, source: event.source_addr, nodeId: event.node_id, - amount: event.amount, + amount: event.current_amount ?? event.amount, fee: event.fee, - tokenLockHash: event.lock_reference_hash, + tokenLockHash: event.current_token_lock_hash ?? event.lock_reference_hash, parentHash: event.parent_hash, type: event.transfer_from_hash ? "transfer" : "create", status: stakeStatus(event), @@ -92,7 +92,7 @@ const delegateStakePositionResponse = (change) => { nodeId: change.node_id, status: stakeStatus(change), stakeHash: change.hash, - lockAmount: change.amount, + lockAmount: change.current_amount ?? change.amount, rewardsAccrued: change.delegate_stake_total_rewards?.delegate_stake_total_rewards ?? 0, withdrawnAmount: completedAmount(change), diff --git a/tests/handlers/actionsHandler.test.ts b/tests/handlers/actionsHandler.test.ts index bb34b56..7f58705 100644 --- a/tests/handlers/actionsHandler.test.ts +++ b/tests/handlers/actionsHandler.test.ts @@ -84,7 +84,7 @@ describe("actionsHandler", () => { expect(result.statusCode).toBe(200); const body = validatePaginatedResponse(result); - expect(body.data.length).toBe(19); + expect(body.data.length).toBe(20); body.data.forEach(validateAction); }); diff --git a/tests/handlers/delegatedStakingHandler.test.ts b/tests/handlers/delegatedStakingHandler.test.ts index 6b64c8d..0aebffc 100644 --- a/tests/handlers/delegatedStakingHandler.test.ts +++ b/tests/handlers/delegatedStakingHandler.test.ts @@ -41,7 +41,9 @@ const validateCreateStake = (tx) => { ); expect(tx.source).toBe(match.source_addr); expect(tx.nodeId).toBe(match.node_id); - expect(tx.amount).toBeBigInt(match.amount); + // Use effective amount (current_amount if set, otherwise original amount) + const effectiveAmount = match.current_amount ?? match.amount; + expect(tx.amount).toBeBigInt(effectiveAmount); expect(tx.fee).toBeBigInt(match.fee); expect(tx.timestamp).toBeDefined(); expect(tx.type).toBe(match.transfer_from_hash ? "transfer" : "create"); @@ -70,7 +72,9 @@ const validateStakingPosition = (tx) => { ); expect(tx.address).toBe(match.source_addr); expect(tx.nodeId).toBe(match.node_id); - expect(tx.lockAmount).toBeBigInt(match.amount); + // Use effective amount (current_amount if set, otherwise original amount) + const effectiveLockAmount = match.current_amount ?? match.amount; + expect(tx.lockAmount).toBeBigInt(effectiveLockAmount); //rewards for this staking event expect(tx.rewardsAccrued).toBeBigInt( data_delegate_stake_rewards diff --git a/tests/handlers/tokenLocksHandler.test.ts b/tests/handlers/tokenLocksHandler.test.ts index 5a8bd42..a414437 100644 --- a/tests/handlers/tokenLocksHandler.test.ts +++ b/tests/handlers/tokenLocksHandler.test.ts @@ -134,10 +134,11 @@ describe("Token Locks Handler Integration Tests", () => { expect(response.statusCode).toBe(200); const body = validatePaginatedResponse(response); - // Only the second and third token lock should be active (not unlocked) - expect(body.data.length).toBe(2); - expect(body.data[1].hash).toBe(data_dag_token_locks[1].hash); - expect(body.data[0].hash).toBe(data_dag_token_locks[2].hash); + // Token locks 2, 3, and 4 should be active (not unlocked) + expect(body.data.length).toBe(3); + expect(body.data[2].hash).toBe(data_dag_token_locks[1].hash); + expect(body.data[1].hash).toBe(data_dag_token_locks[2].hash); + expect(body.data[0].hash).toBe(data_dag_token_locks[3].hash); }); }); @@ -212,7 +213,8 @@ describe("Token Locks Handler Integration Tests", () => { expect(response.statusCode).toBe(200); const body = validatePaginatedResponse(response); - expect(body.data.length).toBe(data_dag_token_locks.length); + // Token locks 1, 2, and 3 belong to address[0]; token lock 4 belongs to address[1] + expect(body.data.length).toBe(3); body.data.forEach(validateDagTokenLock); });