Skip to content
Merged
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
24 changes: 11 additions & 13 deletions cadence/contracts/FlowYieldVaultsStrategies.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ access(all) contract FlowYieldVaultsStrategies {
/// Canonical StoragePath where the StrategyComposerIssuer should be stored
access(all) let IssuerStoragePath: StoragePath

/// This is the first Strategy implementation, wrapping a FlowCreditMarket Position along with its related Sink &
/// This is the first Strategy implementation, wrapping a @FlowCreditMarket.Position along with its related Sink &
/// Source. While this object is a simple wrapper for the top-level collateralized position, the true magic of the
/// DeFiActions is in the stacking of the related connectors. This stacking logic can be found in the
/// TracerStrategyComposer construct.
access(all) resource TracerStrategy : FlowYieldVaults.Strategy, DeFiActions.IdentifiableResource {
/// An optional identifier allowing protocols to identify stacked connector operations by defining a protocol-
/// specific Identifier to associated connectors on construction
access(contract) var uniqueID: DeFiActions.UniqueIdentifier?
access(self) let position: FlowCreditMarket.Position
access(self) let position: @FlowCreditMarket.Position
access(self) var sink: {DeFiActions.Sink}
access(self) var source: {DeFiActions.Source}

init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: FlowCreditMarket.Position) {
init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: @FlowCreditMarket.Position) {
self.uniqueID = id
self.position = position
self.sink = position.createSink(type: collateralType)
self.source = position.createSourceWithOptions(type: collateralType, pullFromTopUpSource: true)
self.position <-position
}

// Inherited from FlowYieldVaults.Strategy default implementation
Expand Down Expand Up @@ -200,13 +200,12 @@ access(all) contract FlowYieldVaultsStrategies {

let poolRef = poolCap.borrow() ?? panic("Invalid Pool Cap")

let pid = poolRef.createPosition(
let position <- poolRef.createPosition(
funds: <-withFunds,
issuanceSink: abaSwapSink,
repaymentSource: abaSwapSource,
pushToDrawDownSink: true
)
let position = FlowCreditMarket.Position(id: pid, pool: poolCap)
FlowYieldVaultsStrategies.account.storage.save(poolCap, to: FlowCreditMarket.PoolCapStoragePath)

// get Sink & Source connectors relating to the new Position
Expand All @@ -231,7 +230,7 @@ access(all) contract FlowYieldVaultsStrategies {
return <-create TracerStrategy(
id: uniqueID,
collateralType: collateralType,
position: position
position: <- position
)
}
}
Expand All @@ -241,15 +240,15 @@ access(all) contract FlowYieldVaultsStrategies {
/// An optional identifier allowing protocols to identify stacked connector operations by defining a protocol-
/// specific Identifier to associated connectors on construction
access(contract) var uniqueID: DeFiActions.UniqueIdentifier?
access(self) let position: FlowCreditMarket.Position
access(self) let position: @FlowCreditMarket.Position
access(self) var sink: {DeFiActions.Sink}
access(self) var source: {DeFiActions.Source}

init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: FlowCreditMarket.Position) {
init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: @FlowCreditMarket.Position) {
self.uniqueID = id
self.position = position
self.sink = position.createSink(type: collateralType)
self.source = position.createSourceWithOptions(type: collateralType, pullFromTopUpSource: true)
self.position <-position
}

// Inherited from FlowYieldVaults.Strategy default implementation
Expand Down Expand Up @@ -476,13 +475,12 @@ access(all) contract FlowYieldVaultsStrategies {
) ?? panic("Missing or invalid pool capability")
let poolRef = poolCap.borrow() ?? panic("Invalid Pool Cap")

let pid = poolRef.createPosition(
let position <- poolRef.createPosition(
funds: <-withFunds,
issuanceSink: abaSwapSink,
repaymentSource: abaSwapSource,
pushToDrawDownSink: true
)
let position = FlowCreditMarket.Position(id: pid, pool: poolCap)

// get Sink & Source connectors relating to the new Position
let positionSink = position.createSinkWithOptions(type: collateralType, pushToDrawDownSink: true)
Expand Down Expand Up @@ -527,7 +525,7 @@ access(all) contract FlowYieldVaultsStrategies {
return <-create mUSDCStrategy(
id: uniqueID,
collateralType: collateralType,
position: position
position: <-position
)
}
}
Expand Down
16 changes: 8 additions & 8 deletions cadence/contracts/FlowYieldVaultsStrategiesV1_1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ access(all) contract FlowYieldVaultsStrategiesV1_1 {
/// An optional identifier allowing protocols to identify stacked connector operations by defining a protocol-
/// specific Identifier to associated connectors on construction
access(contract) var uniqueID: DeFiActions.UniqueIdentifier?
access(self) let position: FlowCreditMarket.Position
access(self) let position: @FlowCreditMarket.Position
access(self) var sink: {DeFiActions.Sink}
access(self) var source: {DeFiActions.Source}

init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: FlowCreditMarket.Position) {
init(id: DeFiActions.UniqueIdentifier, collateralType: Type, position: @FlowCreditMarket.Position) {
self.uniqueID = id
self.position = position
self.sink = position.createSink(type: collateralType)
self.source = position.createSourceWithOptions(type: collateralType, pullFromTopUpSource: true)
self.position <-position
}

// Inherited from FlowYieldVaults.Strategy default implementation
Expand Down Expand Up @@ -279,7 +279,7 @@ access(all) contract FlowYieldVaultsStrategiesV1_1 {
)

// Open FlowCreditMarket position
let position = self._openCreditPosition(
let position <- self._openCreditPosition(
funds: <-withFunds,
issuanceSink: abaSwapSink,
repaymentSource: abaSwapSource
Expand Down Expand Up @@ -309,7 +309,7 @@ access(all) contract FlowYieldVaultsStrategiesV1_1 {
return <-create FlowYieldVaultsStrategiesV1_1.mUSDFStrategy(
id: uniqueID,
collateralType: collateralType,
position: position
position: <-position
)
}

Expand Down Expand Up @@ -478,22 +478,22 @@ access(all) contract FlowYieldVaultsStrategiesV1_1 {
funds: @{FungibleToken.Vault},
issuanceSink: {DeFiActions.Sink},
repaymentSource: {DeFiActions.Source}
): FlowCreditMarket.Position {
): @FlowCreditMarket.Position {
let poolCap = FlowYieldVaultsStrategiesV1_1.account.storage.copy<
Capability<auth(FlowCreditMarket.EParticipant, FlowCreditMarket.EPosition) &FlowCreditMarket.Pool>
>(from: FlowCreditMarket.PoolCapStoragePath)
?? panic("Missing or invalid pool capability")

let poolRef = poolCap.borrow() ?? panic("Invalid Pool Cap")

let pid = poolRef.createPosition(
let position <- poolRef.createPosition(
funds: <-funds,
issuanceSink: issuanceSink,
repaymentSource: repaymentSource,
pushToDrawDownSink: true
)

return FlowCreditMarket.Position(id: pid, pool: poolCap)
return <-position
}

access(self) fun _createYieldToCollateralSwapper(
Expand Down
10 changes: 5 additions & 5 deletions cadence/contracts/mocks/MockSwapper.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ access(all) contract MockSwapper {
let inTokenPrice = self.oracle.price(ofToken: self.inType())
?? panic("Price for token \(self.inType().identifier) is currently unavailable")

let uintOutTokenPrice = FlowCreditMarketMath.toUFix128(outTokenPrice)
let uintInTokenPrice = FlowCreditMarketMath.toUFix128(inTokenPrice)
let uintOutTokenPrice = UFix128(outTokenPrice)
let uintInTokenPrice = UFix128(inTokenPrice)

// the original formula is correct, but lacks precision
// let price = reverse ? outTokenPrice / inTokenPrice : inTokenPrice / outTokenPrice
let uintPrice = reverse ? FlowCreditMarketMath.div(uintOutTokenPrice, uintInTokenPrice) : FlowCreditMarketMath.div(uintInTokenPrice, uintOutTokenPrice)
let uintPrice = reverse ? (uintOutTokenPrice / uintInTokenPrice) : (uintInTokenPrice / uintOutTokenPrice)

if amount == UFix64.max {
return SwapConnectors.BasicQuote(
Expand All @@ -110,8 +110,8 @@ access(all) contract MockSwapper {
)
}

let uintAmount = FlowCreditMarketMath.toUFix128(amount)
let uintInAmount = out ? uintAmount : FlowCreditMarketMath.div(uintAmount, uintPrice)
let uintAmount = UFix128(amount)
let uintInAmount = out ? uintAmount : (uintAmount / uintPrice)
let uintOutAmount = out ? uintAmount * uintPrice : uintAmount

let inAmount = FlowCreditMarketMath.toUFix64Round(uintInAmount)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/atomic_registration_gc_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ access(all) fun setup() {

// Setup FlowCreditMarket with a pool & add FLOW as a supported token.
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: collateralFactor,
borrowFactor: borrowFactor,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// Open a wrapped FlowCreditMarket position so strategies have an underlying position to work with.
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario1_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario2_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario3a_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario3b_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario3c_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_scenario3d_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/rebalance_yield_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ fun setup() {

// setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.0),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)

// open wrapped position (pushToDrawDownSink)
// the equivalent of depositing reserves
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
5 changes: 3 additions & 2 deletions cadence/tests/scheduled_rebalance_integration_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ fun setup() {

// Setup FlowCreditMarket with a Pool & add FLOW as supported token
createAndStorePool(signer: protocolAccount, defaultTokenIdentifier: moetTokenIdentifier, beFailed: false)
addSupportedTokenSimpleInterestCurve(
addSupportedTokenFixedRateInterestCurve(
signer: protocolAccount,
tokenTypeIdentifier: flowTokenIdentifier,
collateralFactor: 0.8,
borrowFactor: 1.0,
yearlyRate: UFix128(0.1),
depositRate: 1_000_000.0,
depositCapacityCap: 1_000_000.0
)
log("FlowCreditMarket pool configured")

// Open wrapped position
let openRes = executeTransaction(
"../../lib/FlowCreditMarket/cadence/tests/transactions/mock-flow-credit-market-consumer/create_wrapped_position.cdc",
"../../lib/FlowCreditMarket/cadence/transactions/flow-credit-market/position/create_position.cdc",
[reserveAmount/2.0, /storage/flowTokenVault, true],
protocolAccount
)
Expand Down
Loading