Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions cadence/tests/rebalance_scenario2_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ access(all) let targetHealthFactor = 1.3

access(all) var snapshot: UInt64 = 0

// Helper function to get Flow collateral from position
access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() {
// Credit means it's a deposit (collateral)
if balance.direction.rawValue == 0 { // Credit = 0
return balance.balance
}
}
}
return 0.0
}



// Enhanced diagnostic precision tracking function with full call stack tracing
access(all) fun performDiagnosticPrecisionTrace(
yieldVaultID: UInt64,
Expand All @@ -48,16 +32,7 @@ access(all) fun performDiagnosticPrecisionTrace(
userAddress: Address
) {
// Get position ground truth
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
var flowAmount: UFix64 = 0.0

for balance in positionDetails.balances {
if balance.vaultType.identifier == flowTokenIdentifier {
if balance.direction.rawValue == 0 { // Credit
flowAmount = balance.balance
}
}
}
let flowAmount = getFlowCollateralFromPosition(pid: pid)

// Values at different layers
let positionValue = flowAmount * 1.0 // Flow price = 1.0 in Scenario 2
Expand Down Expand Up @@ -287,4 +262,3 @@ fun test_RebalanceYieldVaultScenario2() {
message: "Expected user's Flow balance after rebalance to be more than zero but got \(flowBalanceAfter)"
)
}

39 changes: 1 addition & 38 deletions cadence/tests/rebalance_scenario3a_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "FlowToken"
import "MOET"
import "YieldToken"
import "MockStrategies"
import "FlowALPv0"

access(all) let protocolAccount = Test.getAccount(0x0000000000000008)
access(all) let flowYieldVaultsAccount = Test.getAccount(0x0000000000000009)
Expand All @@ -23,34 +22,6 @@ access(all) let targetHealthFactor = 1.3

access(all) var snapshot: UInt64 = 0

// Helper function to get Flow collateral from position
access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() {
// Credit means it's a deposit (collateral)
if balance.direction == FlowALPv0.BalanceDirection.Credit {
return balance.balance
}
}
}
return 0.0
}

// Helper function to get MOET debt from position
access(all) fun getMOETDebtFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@MOET.Vault>() {
// Debit means it's borrowed (debt)
if balance.direction == FlowALPv0.BalanceDirection.Debit {
return balance.balance
}
}
}
return 0.0
}

access(all)
fun setup() {
deployContracts()
Expand Down Expand Up @@ -277,14 +248,7 @@ fun test_RebalanceYieldVaultScenario3A() {
let yieldVaultBalance = getYieldVaultBalance(address: user.address, yieldVaultID: yieldVaultIDs![0])!

// Get the actual available balance from the position
let positionDetails = getPositionDetails(pid: 1, beFailed: false)
var positionFlowBalance = 0.0
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() && balance.direction == FlowALPv0.BalanceDirection.Credit {
positionFlowBalance = balance.balance
break
}
}
let positionFlowBalance = getFlowCollateralFromPosition(pid: pid)

log("\n=== DIAGNOSTIC: YieldVault Balance vs Position Available ===")
log("getYieldVaultBalance() reports: \(yieldVaultBalance)")
Expand All @@ -298,4 +262,3 @@ fun test_RebalanceYieldVaultScenario3A() {
log("\n=== TEST COMPLETE - All precision checks passed ===")
}


44 changes: 2 additions & 42 deletions cadence/tests/rebalance_scenario3b_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "FlowToken"
import "MOET"
import "YieldToken"
import "MockStrategies"
import "FlowALPv0"

access(all) let protocolAccount = Test.getAccount(0x0000000000000008)
access(all) let flowYieldVaultsAccount = Test.getAccount(0x0000000000000009)
Expand All @@ -23,34 +22,6 @@ access(all) let targetHealthFactor = 1.3

access(all) var snapshot: UInt64 = 0

// Helper function to get Flow collateral from position
access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() {
// Credit means it's a deposit (collateral)
if balance.direction.rawValue == 0 { // Credit = 0
return balance.balance
}
}
}
return 0.0
}

// Helper function to get MOET debt from position
access(all) fun getMOETDebtFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@MOET.Vault>() {
// Debit means it's borrowed (debt)
if balance.direction.rawValue == 1 { // Debit = 1
return balance.balance
}
}
}
return 0.0
}

access(all)
fun setup() {
deployContracts()
Expand Down Expand Up @@ -266,21 +237,11 @@ fun test_RebalanceYieldVaultScenario3B() {
equalAmounts(a:debtAfterYieldIncrease, b:expectedDebtValues[2], tolerance:0.01),
message: "Expected MOET debt after yield price increase to be \(expectedDebtValues[2]) but got \(debtAfterYieldIncrease)"
)



// Check getYieldVaultBalance vs actual available balance before closing
// Check getYieldVaultBalance vs actual available balance before closing
let yieldVaultBalance = getYieldVaultBalance(address: user.address, yieldVaultID: yieldVaultIDs![0])!

// Get the actual available balance from the position
let positionDetails = getPositionDetails(pid: 1, beFailed: false)
var positionFlowBalance = 0.0
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() && balance.direction == FlowALPv0.BalanceDirection.Credit {
positionFlowBalance = balance.balance
break
}
}
let positionFlowBalance = getFlowCollateralFromPosition(pid: pid)

log("\n=== DIAGNOSTIC: YieldVault Balance vs Position Available ===")
log("getYieldVaultBalance() reports: \(yieldVaultBalance)")
Expand All @@ -294,4 +255,3 @@ fun test_RebalanceYieldVaultScenario3B() {
log("\n=== TEST COMPLETE ===")
}


30 changes: 0 additions & 30 deletions cadence/tests/rebalance_scenario3c_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "FlowToken"
import "MOET"
import "YieldToken"
import "MockStrategies"
import "FlowALPv0"

access(all) let protocolAccount = Test.getAccount(0x0000000000000008)
access(all) let flowYieldVaultsAccount = Test.getAccount(0x0000000000000009)
Expand All @@ -23,34 +22,6 @@ access(all) let targetHealthFactor = 1.3

access(all) var snapshot: UInt64 = 0

// Helper function to get Flow collateral from position
access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() {
// Credit means it's a deposit (collateral)
if balance.direction == FlowALPv0.BalanceDirection.Credit {
return balance.balance
}
}
}
return 0.0
}

// Helper function to get MOET debt from position
access(all) fun getMOETDebtFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@MOET.Vault>() {
// Debit means it's borrowed (debt)
if balance.direction == FlowALPv0.BalanceDirection.Debit {
return balance.balance
}
}
}
return 0.0
}

access(all)
fun setup() {
deployContracts()
Expand Down Expand Up @@ -275,4 +246,3 @@ fun test_RebalanceYieldVaultScenario3C() {
log("\n=== TEST COMPLETE ===")
}


30 changes: 0 additions & 30 deletions cadence/tests/rebalance_scenario3d_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "FlowToken"
import "MOET"
import "YieldToken"
import "MockStrategies"
import "FlowALPv0"

access(all) let protocolAccount = Test.getAccount(0x0000000000000008)
access(all) let flowYieldVaultsAccount = Test.getAccount(0x0000000000000009)
Expand All @@ -23,34 +22,6 @@ access(all) let targetHealthFactor = 1.3

access(all) var snapshot: UInt64 = 0

// Helper function to get Flow collateral from position
access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>() {
// Credit means it's a deposit (collateral)
if balance.direction == FlowALPv0.BalanceDirection.Credit {
return balance.balance
}
}
}
return 0.0
}

// Helper function to get MOET debt from position
access(all) fun getMOETDebtFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@MOET.Vault>() {
// Debit means it's borrowed (debt)
if balance.direction == FlowALPv0.BalanceDirection.Debit {
return balance.balance
}
}
}
return 0.0
}

access(all)
fun setup() {
deployContracts()
Expand Down Expand Up @@ -273,4 +244,3 @@ fun test_RebalanceYieldVaultScenario3D() {
log("\n=== TEST COMPLETE ===")
}


22 changes: 22 additions & 0 deletions cadence/tests/test_helpers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,28 @@ access(all) fun findBalance(
return nil
}

access(all) fun getFlowCollateralFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@FlowToken.Vault>()
&& balance.direction == FlowALPv0.BalanceDirection.Credit {
return balance.balance
}
}
return 0.0
}

access(all) fun getMOETDebtFromPosition(pid: UInt64): UFix64 {
let positionDetails = getPositionDetails(pid: pid, beFailed: false)
for balance in positionDetails.balances {
if balance.vaultType == Type<@MOET.Vault>()
&& balance.direction == FlowALPv0.BalanceDirection.Debit {
return balance.balance
}
}
return 0.0
}


access(all) let registryBytecode = "608060405234801561001057600080fd5b50338061003757604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b61004081610058565b50600080546001600160a01b031916331790556100aa565b600380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610bbd806100b96000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c8063862119ae11610071578063862119ae146101315780638da5cb5b14610144578063a6de610514610155578063b3d5dbdc14610168578063f2fde38b14610188578063faab9d391461019b57600080fd5b806301ffc9a7146100ae57806304433bbc146100d65780632b20e39714610101578063522791d114610114578063715018a614610129575b600080fd5b6100c16100bc366004610833565b6101ae565b60405190151581526020015b60405180910390f35b6100e96100e4366004610907565b6101e5565b6040516001600160a01b0390911681526020016100cd565b6000546100e9906001600160a01b031681565b610127610122366004610960565b610216565b005b6101276102b7565b6100c161013f366004610907565b6102cb565b6003546001600160a01b03166100e9565b6100c16101633660046109ae565b610308565b61017b6101763660046109ae565b610334565b6040516100cd91906109ed565b6101276101963660046109ae565b6103e0565b6101276101a93660046109ae565b61041e565b60006001600160e01b0319821663976998cb60e01b14806101df57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006001826040516101f79190610a20565b908152604051908190036020019020546001600160a01b031692915050565b6000546001600160a01b031633146102a95760405162461bcd60e51b815260206004820152604560248201527f466c6f774272696467654465706c6f796d656e7452656769737472793a204f6e60448201527f6c79207265676973747261722063616e207265676973746572206173736f636960648201526430ba34b7b760d91b608482015260a4015b60405180910390fd5b6102b3828261042f565b5050565b6102bf6106fd565b6102c9600061072a565b565b6000806001600160a01b03166001836040516102e79190610a20565b908152604051908190036020019020546001600160a01b0316141592915050565b6001600160a01b0381166000908152600260205260408120805461032b90610a3c565b15159392505050565b6001600160a01b038116600090815260026020526040902080546060919061035b90610a3c565b80601f016020809104026020016040519081016040528092919081815260200182805461038790610a3c565b80156103d45780601f106103a9576101008083540402835291602001916103d4565b820191906000526020600020905b8154815290600101906020018083116103b757829003601f168201915b50505050509050919050565b6103e86106fd565b6001600160a01b03811661041257604051631e4fbdf760e01b8152600060048201526024016102a0565b61041b8161072a565b50565b6104266106fd565b61041b8161077c565b6001600160a01b0381166104ab5760405162461bcd60e51b815260206004820152603760248201527f466c6f7745564d4465706c6f796d656e7452656769737472793a20436f6e747260448201527f61637420616464726573732063616e6e6f74206265203000000000000000000060648201526084016102a0565b81516000036105225760405162461bcd60e51b815260206004820152603d60248201527f466c6f7745564d4465706c6f796d656e7452656769737472793a20436164656e60448201527f6365206964656e7469666965722063616e6e6f7420626520656d70747900000060648201526084016102a0565b60006001600160a01b031660018360405161053d9190610a20565b908152604051908190036020019020546001600160a01b0316146105cb576040805162461bcd60e51b81526020600482015260248101919091527f466c6f7745564d4465706c6f796d656e7452656769737472793a20436164656e60448201527f6365206964656e74696669657220616c7265616479207265676973746572656460648201526084016102a0565b6001600160a01b038116600090815260026020526040902080546105ee90610a3c565b1590506106635760405162461bcd60e51b815260206004820152603e60248201527f466c6f7745564d4465706c6f796d656e7452656769737472793a20436f6e747260448201527f616374206164647265737320616c72656164792072656769737465726564000060648201526084016102a0565b806001836040516106749190610a20565b908152604080516020928190038301902080546001600160a01b0319166001600160a01b0394851617905591831660009081526002909152206106b78382610ac7565b50806001600160a01b03167f25d7ffc1de7be1c9b0762be63022756c4773f73211c044d668da6bbcba3e7f14836040516106f191906109ed565b60405180910390a25050565b6003546001600160a01b031633146102c95760405163118cdaa760e01b81523360048201526024016102a0565b600380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0381166107eb5760405162461bcd60e51b815260206004820152603060248201527f466c6f7745564d4465706c6f796d656e7452656769737472793a20526567697360448201526f0747261722063616e6e6f7420626520360841b60648201526084016102a0565b600080546001600160a01b0319166001600160a01b038316908117825560405190917ff90b3304151c89847ba28c08c86e9391dd12ef3a402cba7d3728776a36f29d1191a250565b60006020828403121561084557600080fd5b81356001600160e01b03198116811461085d57600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261088b57600080fd5b813567ffffffffffffffff808211156108a6576108a6610864565b604051601f8301601f19908116603f011681019082821181831017156108ce576108ce610864565b816040528381528660208588010111156108e757600080fd5b836020870160208301376000602085830101528094505050505092915050565b60006020828403121561091957600080fd5b813567ffffffffffffffff81111561093057600080fd5b61093c8482850161087a565b949350505050565b80356001600160a01b038116811461095b57600080fd5b919050565b6000806040838503121561097357600080fd5b823567ffffffffffffffff81111561098a57600080fd5b6109968582860161087a565b9250506109a560208401610944565b90509250929050565b6000602082840312156109c057600080fd5b61085d82610944565b60005b838110156109e45781810151838201526020016109cc565b50506000910152565b6020815260008251806020840152610a0c8160408501602087016109c9565b601f01601f19169190910160400192915050565b60008251610a328184602087016109c9565b9190910192915050565b600181811c90821680610a5057607f821691505b602082108103610a7057634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115610ac2576000816000526020600020601f850160051c81016020861015610a9f5750805b601f850160051c820191505b81811015610abe57828155600101610aab565b5050505b505050565b815167ffffffffffffffff811115610ae157610ae1610864565b610af581610aef8454610a3c565b84610a76565b602080601f831160018114610b2a5760008415610b125750858301515b600019600386901b1c1916600185901b178555610abe565b600085815260208120601f198616915b82811015610b5957888601518255948401946001909101908401610b3a565b5085821015610b775787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fea26469706673582212207bc4fe07fbc245f342675c43729c0cf0da0a7b16d24fef9f2aac1a401e334c8964736f6c63430008180033"

Expand Down