From 2b910e3328fb998c755dc909c258c594376776f2 Mon Sep 17 00:00:00 2001 From: Alex <12097569+nialexsan@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:00:38 -0400 Subject: [PATCH 1/2] remove non-upgradable change from position details --- cadence/contracts/FlowALPv0.cdc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cadence/contracts/FlowALPv0.cdc b/cadence/contracts/FlowALPv0.cdc index 4e427e20..3ef686cc 100644 --- a/cadence/contracts/FlowALPv0.cdc +++ b/cadence/contracts/FlowALPv0.cdc @@ -1927,7 +1927,6 @@ access(all) contract FlowALPv0 { ) return PositionDetails( - id: pid, balances: balances, poolDefaultToken: self.defaultToken, defaultTokenAvailableBalance: defaultTokenAvailable, @@ -4783,9 +4782,6 @@ access(all) contract FlowALPv0 { /// This structure is NOT used internally. access(all) struct PositionDetails { - /// The unique identifier of the position - access(all) let id: UInt64 - /// Balance details about each Vault Type deposited to the related Position access(all) let balances: [PositionBalance] @@ -4799,13 +4795,11 @@ access(all) contract FlowALPv0 { access(all) let health: UFix128 init( - id: UInt64, balances: [PositionBalance], poolDefaultToken: Type, defaultTokenAvailableBalance: UFix64, health: UFix128 ) { - self.id = id self.balances = balances self.poolDefaultToken = poolDefaultToken self.defaultTokenAvailableBalance = defaultTokenAvailableBalance From 8e1cbbe136633ed5f211933a369462e7c93f8cb0 Mon Sep 17 00:00:00 2001 From: Alex <12097569+nialexsan@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:28:41 -0400 Subject: [PATCH 2/2] tweak tests --- .../scripts/flow-alp/get_positions_by_ids.cdc | 6 +++-- cadence/tests/get_positions_by_ids_test.cdc | 23 +++++++++++-------- cadence/tests/test_helpers.cdc | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cadence/scripts/flow-alp/get_positions_by_ids.cdc b/cadence/scripts/flow-alp/get_positions_by_ids.cdc index 5a1651c5..2aca47af 100644 --- a/cadence/scripts/flow-alp/get_positions_by_ids.cdc +++ b/cadence/scripts/flow-alp/get_positions_by_ids.cdc @@ -3,16 +3,18 @@ // are silently skipped. import "FlowALPv0" -access(all) fun main(positionIDs: [UInt64]): [FlowALPv0.PositionDetails] { +access(all) fun main(positionIDs: [UInt64]): [FlowALPv0.PositionDetails?] { let protocolAddress = Type<@FlowALPv0.Pool>().address! let account = getAccount(protocolAddress) let pool = account.capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath) ?? panic("Could not find Pool at path \(FlowALPv0.PoolPublicPath)") - let details: [FlowALPv0.PositionDetails] = [] + let details: [FlowALPv0.PositionDetails?] = [] for id in positionIDs { if let detail = pool.tryGetPositionDetails(pid: id) { details.append(detail) + } else { + details.append(nil) } } return details diff --git a/cadence/tests/get_positions_by_ids_test.cdc b/cadence/tests/get_positions_by_ids_test.cdc index cb2b8ef5..70c75d42 100644 --- a/cadence/tests/get_positions_by_ids_test.cdc +++ b/cadence/tests/get_positions_by_ids_test.cdc @@ -51,11 +51,11 @@ fun test_getPositionsByIDs() { let details0 = getPositionDetails(pid: 0, beFailed: false) let details1 = getPositionDetails(pid: 1, beFailed: false) - Test.assertEqual(details0.health, details[0].health) - Test.assertEqual(details0.balances.length, details[0].balances.length) + Test.assertEqual(details0.health, details[0]!.health) + Test.assertEqual(details0.balances.length, details[0]!.balances.length) - Test.assertEqual(details1.health, details[1].health) - Test.assertEqual(details1.balances.length, details[1].balances.length) + Test.assertEqual(details1.health, details[1]!.health) + Test.assertEqual(details1.balances.length, details[1]!.balances.length) // --- Empty input returns empty array --- let emptyDetails = getPositionsByIDs(positionIDs: []) @@ -64,21 +64,26 @@ fun test_getPositionsByIDs() { // --- Single ID works --- let singleDetails = getPositionsByIDs(positionIDs: [UInt64(0)]) Test.assertEqual(1, singleDetails.length) - Test.assertEqual(details0.health, singleDetails[0].health) + Test.assertEqual(details0.health, singleDetails[0]!.health) // --- Closed positions are silently skipped --- // Close position 1, then request both IDs — should only return position 0 closePosition(user: user, positionID: 1) let afterClose = getPositionsByIDs(positionIDs: [UInt64(0), UInt64(1)]) - Test.assertEqual(1, afterClose.length) - Test.assertEqual(details0.health, afterClose[0].health) + Test.assertEqual(2, afterClose.length) + Test.assertEqual(details0.health, afterClose[0]!.health) + Test.assertEqual(afterClose[1], nil) // --- All IDs closed/invalid returns empty array --- closePosition(user: user, positionID: 0) let allClosed = getPositionsByIDs(positionIDs: [UInt64(0), UInt64(1)]) - Test.assertEqual(0, allClosed.length) + Test.assertEqual(2, allClosed.length) + Test.assertEqual(allClosed[0], nil) + Test.assertEqual(allClosed[1], nil) // --- Non-existent IDs are skipped --- let nonExistent = getPositionsByIDs(positionIDs: [UInt64(999), UInt64(1000)]) - Test.assertEqual(0, nonExistent.length) + Test.assertEqual(2, nonExistent.length) + Test.assertEqual(nonExistent[0], nil) + Test.assertEqual(nonExistent[1], nil) } diff --git a/cadence/tests/test_helpers.cdc b/cadence/tests/test_helpers.cdc index 3a2ac830..4b516d5e 100644 --- a/cadence/tests/test_helpers.cdc +++ b/cadence/tests/test_helpers.cdc @@ -801,13 +801,13 @@ fun getPositionIDs(): [UInt64] { } access(all) -fun getPositionsByIDs(positionIDs: [UInt64]): [FlowALPv0.PositionDetails] { +fun getPositionsByIDs(positionIDs: [UInt64]): [FlowALPv0.PositionDetails?] { let res = _executeScript( "../scripts/flow-alp/get_positions_by_ids.cdc", [positionIDs] ) Test.expect(res, Test.beSucceeded()) - return res.returnValue as! [FlowALPv0.PositionDetails] + return res.returnValue as! [FlowALPv0.PositionDetails?] } access(all)