diff --git a/cadence/contracts/FlowALPv0.cdc b/cadence/contracts/FlowALPv0.cdc index d6bb8022..ce220c3d 100644 --- a/cadence/contracts/FlowALPv0.cdc +++ b/cadence/contracts/FlowALPv0.cdc @@ -522,7 +522,7 @@ access(all) contract FlowALPv0 { /// - C means collateral: Ce is effective collateral, Ct is true collateral, measured in $ /// - D means debt: De is effective debt, Dt is true debt, measured in $ /// - Fc, Fd are collateral and debt factors - access(all) fun manualLiquidation( + access(FlowALPModels.EParticipant) fun manualLiquidation( pid: UInt64, debtType: Type, seizeType: Type, diff --git a/cadence/tests/cap_test.cdc b/cadence/tests/cap_test.cdc index d58c2a54..918f11af 100644 --- a/cadence/tests/cap_test.cdc +++ b/cadence/tests/cap_test.cdc @@ -220,7 +220,7 @@ fun testPublishClaimCap() { // ============================================================================= // // Actor: eParticipantUser — Capability -// Matrix rows: createPosition, depositToPosition +// Matrix rows: createPosition, depositToPosition, manualLiquidation /// EParticipant cap allows createPosition and depositToPosition. access(all) diff --git a/cadence/tests/fork_liquidation_edge_cases.cdc b/cadence/tests/fork_liquidation_edge_cases.cdc index 2c93cc68..106107d4 100644 --- a/cadence/tests/fork_liquidation_edge_cases.cdc +++ b/cadence/tests/fork_liquidation_edge_cases.cdc @@ -208,6 +208,7 @@ fun testPartialLiquidationSequences() { // Post effectiveCollateral = 990 * 0.855 * 0.8 = 677.16 // Post health = 677.16 / 700 = 0.967371428571428571428571 ≤ 1.05 let liq1Res = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator1, pid: pid1, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -224,6 +225,7 @@ fun testPartialLiquidationSequences() { // Post effectiveCollateral = 980 * 0.855 * 0.8 = 670.32 // Post health = 670.32 / 680 = 0.985764705882352941176470 ≤ 1.05 let liq2Res = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator1, pid: pid1, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -240,6 +242,7 @@ fun testPartialLiquidationSequences() { // Post effectiveCollateral = 970 * 0.855 * 0.8 = 663.48 // Post health = 663.48 / 660 = 1.005272727272727272727272 ≤ 1.05 let liq3Res = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator1, pid: pid1, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -259,6 +262,7 @@ fun testPartialLiquidationSequences() { // Liquidation call 4: fails because health = 1.00527 > 1.0 let liq4Res = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator1, pid: pid1, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -274,6 +278,7 @@ fun testPartialLiquidationSequences() { mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: liquidator2.address, amount: 500.0, beFailed: false) let liq5Res = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator2, pid: pid1, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -410,6 +415,7 @@ fun testLiquidateMultiCollateralChooseUSDC() { Test.expect(res, Test.beSucceeded()) let liqRes = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: MAINNET_USDF_TOKEN_ID, @@ -435,6 +441,7 @@ fun testLiquidateMultiCollateralChooseUSDC() { // A second liquidation attempt fails — position is now healthy let liqRes2 = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: MAINNET_USDF_TOKEN_ID, @@ -592,6 +599,7 @@ fun testStabilityAndInsuranceFees_notCollectedForLiquidatedFunds() { let liquidator = Test.createAccount() transferTokensWithSetup(tokenIdentifier: MAINNET_USDF_TOKEN_ID, from: MAINNET_USDF_HOLDER, to: liquidator, amount: 200.0) let liqRes = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: MAINNET_USDF_TOKEN_ID, diff --git a/cadence/tests/fork_multi_collateral_position_test.cdc b/cadence/tests/fork_multi_collateral_position_test.cdc index 4932c2af..cca7af86 100644 --- a/cadence/tests/fork_multi_collateral_position_test.cdc +++ b/cadence/tests/fork_multi_collateral_position_test.cdc @@ -835,6 +835,7 @@ fun test_multi_asset_liquidation_collateral_selection() { let seizeAmount: UFix64 = 140.0 let liqRes = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer:liquidator, pid: pid, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, diff --git a/cadence/tests/fork_multiple_positions_per_user_test.cdc b/cadence/tests/fork_multiple_positions_per_user_test.cdc index 971873e4..8e491a86 100644 --- a/cadence/tests/fork_multiple_positions_per_user_test.cdc +++ b/cadence/tests/fork_multiple_positions_per_user_test.cdc @@ -636,6 +636,7 @@ access(all) fun testBatchLiquidations() { let batchRepayAmounts = [usdfRepay, wethRepay, usdcRepay, wbtcRepay] batchManualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, pids: batchPids, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, seizeVaultIdentifiers: batchSeizeTypes, @@ -945,6 +946,7 @@ access(all) fun testMassUnhealthyLiquidations() { // DEX sources MOET from MAINNET_PROTOCOL_ACCOUNT's vault; liquidator receives seized collateral. log("Liquidating all 100 positions via DEX in chunks of 10...\n") batchLiquidateViaMockDex( + admin: MAINNET_PROTOCOL_ACCOUNT, pids: batchPids, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, seizeVaultIdentifiers: batchSeize, diff --git a/cadence/tests/fork_oracle_failure_test.cdc b/cadence/tests/fork_oracle_failure_test.cdc index 300a5d0a..643b1622 100644 --- a/cadence/tests/fork_oracle_failure_test.cdc +++ b/cadence/tests/fork_oracle_failure_test.cdc @@ -313,6 +313,7 @@ fun test_governance_tightens_dex_deviation_threshold() { mintMoet(signer: MAINNET_PROTOCOL_ACCOUNT, to: liquidator.address, amount: 500.0, beFailed: false) let liqRes = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, @@ -407,6 +408,7 @@ fun test_flash_crash_triggers_liquidation() { // DEX quote: 100 / 0.50 = 200 FLOW // Liquidator offers: 195 FLOW (better than DEX) let liqRes = manualLiquidation( + admin: MAINNET_PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: MAINNET_MOET_TOKEN_ID, diff --git a/cadence/tests/liquidation_phase1_test.cdc b/cadence/tests/liquidation_phase1_test.cdc index a17aa89a..ee9565fc 100644 --- a/cadence/tests/liquidation_phase1_test.cdc +++ b/cadence/tests/liquidation_phase1_test.cdc @@ -77,7 +77,8 @@ fun testManualLiquidation_healthyPosition() { let repayAmount = 2.0 let seizeAmount = 1.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -131,7 +132,8 @@ fun testManualLiquidation_liquidationExceedsTargetHealth() { let repayAmount = 500.0 let seizeAmount = 500.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -194,7 +196,8 @@ fun testManualLiquidation_repayExceedsDebt() { let repayAmount = debtBalance + 0.001 let seizeAmount = (repayAmount / newPrice) * 0.99 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -255,7 +258,8 @@ fun testManualLiquidation_seizeExceedsCollateral() { let seizeAmount = collateralBalance + 0.001 let repayAmount = seizeAmount * newPrice * 1.01 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -317,7 +321,8 @@ fun testManualLiquidation_reduceHealth() { let seizeAmount = collateralBalancePreLiq - 0.01 let repayAmount = seizeAmount * newPrice * 1.01 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -383,6 +388,7 @@ fun testBadDebt_seizeAllCollateral() { // Post-health = 0 / remainingDebt = 0.0 ≤ 1.05 ✓ let minRepay: UFix64 = initialCollateral * crashedPrice + 0.00000001 let liqRes = manualLiquidation( + admin: PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, @@ -433,6 +439,7 @@ fun testBadDebt_voluntaryRepayment_fullRepayReverts() { // First liquidation: seize all collateral, enter bad-debt state let minRepay: UFix64 = initialCollateral * crashedPrice + 0.00000001 Test.expect(manualLiquidation( + admin: PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, @@ -448,6 +455,7 @@ fun testBadDebt_voluntaryRepayment_fullRepayReverts() { // Post-health: 0 / 0.00000001 = 0.0 ≤ 1.05 ✓ let almostAll = remainingDebt - 0.00000001 Test.expect(manualLiquidation( + admin: PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, @@ -459,6 +467,7 @@ fun testBadDebt_voluntaryRepayment_fullRepayReverts() { // === Third liquidation: repaying the final tick reverts === // Repaying 0.00000001 MOET sets postDebt=0, so postHealth=UFix128.max > 1.05 → revert let liqRes3 = manualLiquidation( + admin: PROTOCOL_ACCOUNT, signer: liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, @@ -512,7 +521,8 @@ fun testManualLiquidation_increaseHealthBelowTarget() { let repayAmount = 100.0 let seizeAmount = 150.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -580,7 +590,8 @@ fun testManualLiquidation_liquidateToTarget() { let repayAmount = 100.0 let seizeAmount = 33.66 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -639,6 +650,7 @@ fun testManualLiquidation_repaymentVaultCollateralType() { // Purport to repay MOET to seize FLOW, but we will actually pass in a FLOW vault for repayment let repayAmount = debtBalance + 0.001 let seizeAmount = (repayAmount / newPrice) * 0.99 + grantBetaPoolParticipantAccess(PROTOCOL_ACCOUNT, liquidator) let liqRes = _executeTransaction( "../tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc", [pid, Type<@MOET.Vault>().identifier, FLOW_TOKEN_IDENTIFIER, FLOW_TOKEN_IDENTIFIER, seizeAmount, repayAmount], @@ -695,6 +707,7 @@ fun testManualLiquidation_repaymentVaultTypeMismatch() { // Purport to repay MOET to seize FLOW, but we will actually pass in a MockYieldToken vault for repayment let repayAmount = debtBalance + 0.001 let seizeAmount = (repayAmount / newPrice) * 0.99 + grantBetaPoolParticipantAccess(PROTOCOL_ACCOUNT, liquidator) let liqRes = _executeTransaction( "../tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc", [pid, Type<@MOET.Vault>().identifier, MOCK_YIELD_TOKEN_IDENTIFIER, FLOW_TOKEN_IDENTIFIER, seizeAmount, repayAmount], @@ -750,6 +763,7 @@ fun testManualLiquidation_unsupportedDebtType() { // Pass in MockYieldToken as repayment, an unsupported debt type let repayAmount = debtBalance + 0.001 let seizeAmount = (repayAmount / newPrice) * 0.99 + grantBetaPoolParticipantAccess(PROTOCOL_ACCOUNT, liquidator) let liqRes = _executeTransaction( "../tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc", [pid, MOCK_YIELD_TOKEN_IDENTIFIER, MOCK_YIELD_TOKEN_IDENTIFIER, FLOW_TOKEN_IDENTIFIER, seizeAmount, repayAmount], @@ -806,7 +820,8 @@ fun testManualLiquidation_unsupportedCollateralType() { let seizeAmount = collateralBalancePreLiq - 0.01 let repayAmount = seizeAmount * newPrice * 1.01 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: MOCK_YIELD_TOKEN_IDENTIFIER, @@ -893,7 +908,8 @@ fun testManualLiquidation_supportedDebtTypeNotInPosition() { let seizeAmount = 0.01 let repayAmount = 100.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid1, debtVaultIdentifier: MOCK_YIELD_TOKEN_IDENTIFIER, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -980,7 +996,8 @@ fun testManualLiquidation_supportedCollateralTypeNotInPosition() { let seizeAmount = 0.01 let repayAmount = 100.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid1, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: MOCK_YIELD_TOKEN_IDENTIFIER, @@ -1042,7 +1059,8 @@ fun testManualLiquidation_dexOraclePriceDivergence_withinThreshold() { let repayAmount = 50.0 let seizeAmount = 72.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -1080,7 +1098,8 @@ fun testManualLiquidation_dexOraclePriceDivergence_dexBelowOracle() { setupMoetVault(liquidator, beFailed: false) mintMoet(signer: Test.getAccount(0x0000000000000007), to: liquidator.address, amount: 1000.0, beFailed: false) let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -1119,7 +1138,8 @@ fun testManualLiquidation_dexOraclePriceDivergence_dexAboveOracle() { setupMoetVault(liquidator, beFailed: false) mintMoet(signer: Test.getAccount(0x0000000000000007), to: liquidator.address, amount: 1000.0, beFailed: false) let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -1173,7 +1193,8 @@ fun testManualLiquidation_liquidatorOfferWorseThanDex() { let repayAmount = 50.0 let seizeAmount = 75.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, @@ -1229,7 +1250,8 @@ fun testManualLiquidation_combinedEdgeCase() { let repayAmount = 50.0 let seizeAmount = 75.0 let liqRes = manualLiquidation( - signer:liquidator, + admin: PROTOCOL_ACCOUNT, + signer:liquidator, pid: pid, debtVaultIdentifier: Type<@MOET.Vault>().identifier, seizeVaultIdentifier: FLOW_TOKEN_IDENTIFIER, diff --git a/cadence/tests/test_helpers.cdc b/cadence/tests/test_helpers.cdc index 1d422c6c..597dfc1d 100644 --- a/cadence/tests/test_helpers.cdc +++ b/cadence/tests/test_helpers.cdc @@ -876,6 +876,7 @@ fun rebalancePosition(signer: Test.TestAccount, pid: UInt64, force: Bool, beFail access(all) fun manualLiquidation( + admin: Test.TestAccount, signer: Test.TestAccount, pid: UInt64, debtVaultIdentifier: String, @@ -883,6 +884,7 @@ fun manualLiquidation( seizeAmount: UFix64, repayAmount: UFix64, ): Test.TransactionResult { + grantBetaPoolParticipantAccess(admin, signer) return _executeTransaction( "../transactions/flow-alp/pool-management/manual_liquidation.cdc", [pid, debtVaultIdentifier, seizeVaultIdentifier, seizeAmount, repayAmount], @@ -892,6 +894,7 @@ fun manualLiquidation( access(all) fun liquidateViaMockDex( + admin: Test.TestAccount, signer: Test.TestAccount, pid: UInt64, debtVaultIdentifier: String, @@ -899,6 +902,7 @@ fun liquidateViaMockDex( seizeAmount: UFix64, repayAmount: UFix64, ): Test.TransactionResult { + grantBetaPoolParticipantAccess(admin, signer) return _executeTransaction( "./transactions/flow-alp/pool-management/batch_liquidate_via_mock_dex.cdc", [[pid], debtVaultIdentifier, [seizeVaultIdentifier], [seizeAmount], [repayAmount]], @@ -909,6 +913,7 @@ fun liquidateViaMockDex( /// Batch-liquidate positions using the liquidator's own tokens as repayment (no DEX). /// The liquidator must hold sufficient debt tokens upfront. access(all) fun batchManualLiquidation( + admin: Test.TestAccount, pids: [UInt64], debtVaultIdentifier: String, seizeVaultIdentifiers: [String], @@ -916,6 +921,7 @@ access(all) fun batchManualLiquidation( repayAmounts: [UFix64], signer: Test.TestAccount ) { + grantBetaPoolParticipantAccess(admin, signer) let res = _executeTransaction( "./transactions/flow-alp/pool-management/batch_manual_liquidation.cdc", [pids, debtVaultIdentifier, seizeVaultIdentifiers, seizeAmounts, repayAmounts], @@ -927,6 +933,7 @@ access(all) fun batchManualLiquidation( /// Batch-liquidate positions using MockDexSwapper as the repayment source in chunks of /// chunkSize to stay within the computation limit. access(all) fun batchLiquidateViaMockDex( + admin: Test.TestAccount, pids: [UInt64], debtVaultIdentifier: String, seizeVaultIdentifiers: [String], @@ -935,6 +942,7 @@ access(all) fun batchLiquidateViaMockDex( chunkSize: Int, signer: Test.TestAccount ) { + grantBetaPoolParticipantAccess(admin, signer) let total = pids.length let numChunks = (total + chunkSize - 1) / chunkSize for i in InclusiveRange(0, numChunks - 1) { diff --git a/cadence/tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc b/cadence/tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc index e2b5da65..2ae4fa01 100644 --- a/cadence/tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc +++ b/cadence/tests/transactions/flow-alp/helpers/manual_liquidation_chosen_vault.cdc @@ -3,6 +3,7 @@ import "FungibleTokenMetadataViews" import "MetadataViews" import "FlowALPv0" +import "FlowALPModels" /// Attempt to liquidate a position by repaying `repayAmount`. /// This TESTING-ONLY transaction allows specifying a different repayment vault type. @@ -10,7 +11,7 @@ import "FlowALPv0" /// debtVaultIdentifier: e.g., Type<@MOET.Vault>().identifier /// seizeVaultIdentifier: e.g., Type<@FlowToken.Vault>().identifier transaction(pid: UInt64, purportedDebtVaultIdentifier: String, actualDebtVaultIdentifier: String, seizeVaultIdentifier: String, seizeAmount: UFix64, repayAmount: UFix64) { - let pool: &FlowALPv0.Pool + let pool: auth(FlowALPModels.EParticipant) &FlowALPv0.Pool let receiver: &{FungibleToken.Receiver} let actualDebtType: Type let purportedDebtType: Type @@ -18,9 +19,10 @@ transaction(pid: UInt64, purportedDebtVaultIdentifier: String, actualDebtVaultId let repay: @{FungibleToken.Vault} prepare(signer: auth(BorrowValue, SaveValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) { - let protocolAddress = Type<@FlowALPv0.Pool>().address! - self.pool = getAccount(protocolAddress).capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath) - ?? panic("Could not borrow Pool at \(FlowALPv0.PoolPublicPath)") + let cap = signer.storage.borrow<&Capability>( + from: FlowALPv0.PoolCapStoragePath + ) ?? panic("Could not borrow Pool capability from storage - ensure the signer has been granted Pool access with EParticipant entitlement") + self.pool = cap.borrow() ?? panic("Could not borrow Pool from capability") // Resolve types self.actualDebtType = CompositeType(actualDebtVaultIdentifier) ?? panic("Invalid actualDebtVaultIdentifier: \(actualDebtVaultIdentifier)") diff --git a/cadence/tests/transactions/flow-alp/pool-management/batch_liquidate_via_mock_dex.cdc b/cadence/tests/transactions/flow-alp/pool-management/batch_liquidate_via_mock_dex.cdc index 34c61486..fb2e393f 100644 --- a/cadence/tests/transactions/flow-alp/pool-management/batch_liquidate_via_mock_dex.cdc +++ b/cadence/tests/transactions/flow-alp/pool-management/batch_liquidate_via_mock_dex.cdc @@ -3,6 +3,7 @@ import "FungibleTokenMetadataViews" import "MetadataViews" import "FlowALPv0" +import "FlowALPModels" import "MockDexSwapper" /// TEST-ONLY: Batch liquidate multiple positions using the stored MockDexSwapper as the debt @@ -23,14 +24,15 @@ transaction( seizeAmounts: [UFix64], repayAmounts: [UFix64] ) { - let pool: &FlowALPv0.Pool + let pool: auth(FlowALPModels.EParticipant) &FlowALPv0.Pool let debtType: Type let signerAccount: auth(BorrowValue) &Account prepare(signer: auth(BorrowValue) &Account) { - let protocolAddress = Type<@FlowALPv0.Pool>().address! - self.pool = getAccount(protocolAddress).capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath) - ?? panic("Could not borrow Pool at \(FlowALPv0.PoolPublicPath)") + let cap = signer.storage.borrow<&Capability>( + from: FlowALPv0.PoolCapStoragePath + ) ?? panic("Could not borrow Pool capability from storage - ensure the signer has been granted Pool access with EParticipant entitlement") + self.pool = cap.borrow() ?? panic("Could not borrow Pool from capability") self.debtType = CompositeType(repayVaultIdentifier) ?? panic("Invalid debtVaultIdentifier: \(repayVaultIdentifier)") diff --git a/cadence/tests/transactions/flow-alp/pool-management/batch_manual_liquidation.cdc b/cadence/tests/transactions/flow-alp/pool-management/batch_manual_liquidation.cdc index e57882bc..a2f5762e 100644 --- a/cadence/tests/transactions/flow-alp/pool-management/batch_manual_liquidation.cdc +++ b/cadence/tests/transactions/flow-alp/pool-management/batch_manual_liquidation.cdc @@ -3,6 +3,7 @@ import "FungibleTokenMetadataViews" import "MetadataViews" import "FlowALPv0" +import "FlowALPModels" /// Batch liquidate multiple positions in a single transaction /// @@ -18,7 +19,7 @@ transaction( seizeAmounts: [UFix64], repayAmounts: [UFix64] ) { - let pool: &FlowALPv0.Pool + let pool: auth(FlowALPModels.EParticipant) &FlowALPv0.Pool let repaymentType: Type let repaymentVaultRef: auth(FungibleToken.Withdraw) &{FungibleToken.Vault} let signerAccount: auth(BorrowValue) &Account @@ -26,9 +27,10 @@ transaction( prepare(signer: auth(BorrowValue, SaveValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) { self.signerAccount = signer - let protocolAddress = Type<@FlowALPv0.Pool>().address! - self.pool = getAccount(protocolAddress).capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath) - ?? panic("Could not borrow Pool at \(FlowALPv0.PoolPublicPath)") + let cap = signer.storage.borrow<&Capability>( + from: FlowALPv0.PoolCapStoragePath + ) ?? panic("Could not borrow Pool capability from storage - ensure the signer has been granted Pool access with EParticipant entitlement") + self.pool = cap.borrow() ?? panic("Could not borrow Pool from capability") self.repaymentType = CompositeType(repaymentVaultIdentifier) ?? panic("Invalid repaymentVaultIdentifier: \(repaymentVaultIdentifier)") diff --git a/cadence/transactions/flow-alp/pool-management/manual_liquidation.cdc b/cadence/transactions/flow-alp/pool-management/manual_liquidation.cdc index bb9afb78..10f4852c 100644 --- a/cadence/transactions/flow-alp/pool-management/manual_liquidation.cdc +++ b/cadence/transactions/flow-alp/pool-management/manual_liquidation.cdc @@ -3,22 +3,24 @@ import "FungibleTokenMetadataViews" import "MetadataViews" import "FlowALPv0" +import "FlowALPModels" /// Attempt to liquidation a position by repaying `repayAmount`. /// /// debtVaultIdentifier: e.g., Type<@MOET.Vault>().identifier /// seizeVaultIdentifier: e.g., Type<@FlowToken.Vault>().identifier transaction(pid: UInt64, debtVaultIdentifier: String, seizeVaultIdentifier: String, seizeAmount: UFix64, repayAmount: UFix64) { - let pool: &FlowALPv0.Pool + let pool: auth(FlowALPModels.EParticipant) &FlowALPv0.Pool let receiver: &{FungibleToken.Receiver} let debtType: Type let seizeType: Type let repay: @{FungibleToken.Vault} prepare(signer: auth(BorrowValue, SaveValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) { - let protocolAddress = Type<@FlowALPv0.Pool>().address! - self.pool = getAccount(protocolAddress).capabilities.borrow<&FlowALPv0.Pool>(FlowALPv0.PoolPublicPath) - ?? panic("Could not borrow Pool at \(FlowALPv0.PoolPublicPath)") + let cap = signer.storage.borrow<&Capability>( + from: FlowALPv0.PoolCapStoragePath + ) ?? panic("Could not borrow Pool capability from storage - ensure the signer has been granted Pool access with EParticipant entitlement") + self.pool = cap.borrow() ?? panic("Could not borrow Pool from capability") // Resolve types self.debtType = CompositeType(debtVaultIdentifier) ?? panic("Invalid debtVaultIdentifier: \(debtVaultIdentifier)")