Skip to content

Commit 953f8f3

Browse files
Merge branch 'tracer-bullet' into gio/refactor-pool-creation-updated
2 parents 87d7d21 + 8ce8e16 commit 953f8f3

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

cadence/contracts/TidalProtocol.cdc

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,6 @@ access(all) contract TidalProtocol {
538538
return self.globalLedger[tokenType] != nil
539539
}
540540

541-
// RESTORED: Public deposit function from Dieter's implementation
542-
// Allows anyone to deposit funds into any position
543-
access(all) fun depositToPosition(pid: UInt64, from: @{FungibleToken.Vault}) {
544-
self.depositAndPush(pid: pid, from: <-from, pushToDrawDownSink: false)
545-
}
546-
547541
// RESTORED: Enhanced deposit with queue processing and rebalancing from Dieter's implementation
548542
access(EPosition) fun depositAndPush(pid: UInt64, from: @{FungibleToken.Vault}, pushToDrawDownSink: Bool) {
549543
pre {
@@ -605,6 +599,12 @@ access(all) contract TidalProtocol {
605599
self.queuePositionForUpdateIfNecessary(pid: pid)
606600
}
607601

602+
// RESTORED: Public deposit function from Dieter's implementation
603+
// Allows anyone to deposit funds into any position
604+
access(all) fun depositToPosition(pid: UInt64, from: @{FungibleToken.Vault}) {
605+
self.depositAndPush(pid: pid, from: <-from, pushToDrawDownSink: false)
606+
}
607+
608608
access(EPosition) fun withdraw(pid: UInt64, amount: UFix64, type: Type): @{FungibleToken.Vault} {
609609
// RESTORED: Call the enhanced function with pullFromTopUpSource = false for backward compatibility
610610
return <- self.withdrawAndPull(pid: pid, type: type, amount: amount, pullFromTopUpSource: false)
@@ -804,7 +804,6 @@ access(all) contract TidalProtocol {
804804
let position = (&self.positions[pid] as auth(EImplementation) &InternalPosition?)!
805805
position.setDrawDownSink(sink)
806806
}
807-
808807
access(EPosition) fun provideTopUpSource(pid: UInt64, source: {DFB.Source}?) {
809808
let position = (&self.positions[pid] as auth(EImplementation) &InternalPosition?)!
810809
position.setTopUpSource(source)
@@ -959,7 +958,6 @@ access(all) contract TidalProtocol {
959958
for type in position.balances.keys {
960959
let balance = position.balances[type]!
961960
let tokenState = self.tokenState(type: type)
962-
963961
let trueBalance = balance.direction == BalanceDirection.Credit
964962
? TidalProtocol.scaledBalanceToTrueBalance(scaledBalance: balance.scaledBalance, interestIndex: tokenState.creditInterestIndex)
965963
: TidalProtocol.scaledBalanceToTrueBalance(scaledBalance: balance.scaledBalance, interestIndex: tokenState.debitInterestIndex)
@@ -983,7 +981,6 @@ access(all) contract TidalProtocol {
983981
}
984982

985983
// RESTORED: Advanced position health management functions from Dieter's implementation
986-
987984
// The quantity of funds of a specified token which would need to be deposited to bring the
988985
// position to the target health. This function will return 0.0 if the position is already at or over
989986
// that health value.
@@ -1020,7 +1017,6 @@ access(all) contract TidalProtocol {
10201017
var effectiveCollateralAfterWithdrawal = balanceSheet.effectiveCollateral
10211018
var effectiveDebtAfterWithdrawal = balanceSheet.effectiveDebt
10221019

1023-
10241020
if withdrawAmount != 0.0 {
10251021
if position.balances[withdrawType] == nil || position.balances[withdrawType]!.direction == BalanceDirection.Debit {
10261022
// If the position doesn't have any collateral for the withdrawn token, we can just compute how much
@@ -1079,7 +1075,6 @@ access(all) contract TidalProtocol {
10791075
let depositTokenState = self.tokenState(type: depositType)
10801076
// REMOVED: This is now handled by tokenState() helper function
10811077
// depositTokenState.updateForTimeChange()
1082-
10831078
let debtBalance = position.balances[depositType]!.scaledBalance
10841079
let trueDebt = TidalProtocol.scaledBalanceToTrueBalance(
10851080
scaledBalance: debtBalance,
@@ -1225,7 +1220,6 @@ access(all) contract TidalProtocol {
12251220
let withdrawTokenState = self.tokenState(type: withdrawType)
12261221
// REMOVED: This is now handled by tokenState() helper function
12271222
// withdrawTokenState.updateForTimeChange()
1228-
12291223
let creditBalance = position.balances[withdrawType]!.scaledBalance
12301224
let trueCredit = TidalProtocol.scaledBalanceToTrueBalance(
12311225
scaledBalance: creditBalance,
@@ -1376,7 +1370,6 @@ access(all) contract TidalProtocol {
13761370
let queuedVault <- position.queuedDeposits.remove(key: depositType)!
13771371
let queuedAmount = queuedVault.balance
13781372
let depositTokenState = self.tokenState(type: depositType)
1379-
13801373
let maxDeposit = depositTokenState.depositLimit()
13811374

13821375
if maxDeposit >= queuedAmount {
@@ -1648,6 +1641,29 @@ access(all) contract TidalProtocol {
16481641
access(all) case Debit
16491642
}
16501643

1644+
// RESTORED: DummyPriceOracle for testing from Dieter's design pattern
1645+
access(all) struct DummyPriceOracle: DFB.PriceOracle {
1646+
access(self) var prices: {Type: UFix64}
1647+
access(self) let defaultToken: Type
1648+
1649+
access(all) view fun unitOfAccount(): Type {
1650+
return self.defaultToken
1651+
}
1652+
1653+
access(all) fun price(ofToken: Type): UFix64 {
1654+
return self.prices[ofToken] ?? 1.0
1655+
}
1656+
1657+
access(all) fun setPrice(ofToken: Type, price: UFix64) {
1658+
self.prices[ofToken] = price
1659+
}
1660+
1661+
init(defaultToken: Type) {
1662+
self.defaultToken = defaultToken
1663+
self.prices = {defaultToken: 1.0}
1664+
}
1665+
}
1666+
16511667
// A structure returned externally to report a position's balance for a particular token.
16521668
// This structure is NOT used internally.
16531669
access(all) struct PositionBalance {

0 commit comments

Comments
 (0)