Skip to content

Commit 1326ea8

Browse files
authored
Merge pull request #150 from onflow/nialexsan/scheduled-rebalance-resolve-merge
Nialexsan/scheduled rebalance resolve merge
2 parents d5da5a5 + 4040fa9 commit 1326ea8

File tree

44 files changed

+3287
-463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3287
-463
lines changed

cadence/contracts/FlowCreditMarket.cdc

Lines changed: 374 additions & 96 deletions
Large diffs are not rendered by default.

cadence/contracts/mocks/MockDexSwapper.cdc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ import "DeFiActionsUtils"
88
/// Do NOT use in production.
99
access(all) contract MockDexSwapper {
1010

11+
/// Holds the set of available swappers which will be provided to users of SwapperProvider.
12+
/// inType -> outType -> Swapper
13+
access(self) let swappers: {Type: {Type: Swapper}}
14+
15+
init() {
16+
self.swappers = {}
17+
}
18+
19+
access(all) fun getSwapper(inType: Type, outType: Type): Swapper? {
20+
if let swappersForInType = self.swappers[inType] {
21+
return swappersForInType[outType]
22+
}
23+
return nil
24+
}
25+
26+
/// Used by testing code to configure the DEX with swappers for a specific token pair.
27+
///
28+
/// IMPORTANT: This function will overwrite any existing swapper for the same token pair.
29+
/// This is intended to be used in cases where we want to change the price only, without
30+
/// needing to remove and re-add the swapper.
31+
///
32+
/// @param swapper: The swapper to set for the token pair
33+
access(all) fun setMockDEXSwapperForPair(swapper: Swapper) {
34+
let inType = swapper.inType()
35+
let outType = swapper.outType()
36+
let swappersRef = &self.swappers as auth(Mutate) &{Type: {Type: Swapper}}
37+
if swappersRef[inType] == nil {
38+
swappersRef[inType] = { outType: swapper }
39+
} else {
40+
let swappersForInTypeRef = &self.swappers[inType]! as auth(Mutate) &{Type: Swapper}
41+
swappersForInTypeRef[outType] = swapper
42+
}
43+
}
44+
45+
/// Used by testing code to remove a swapper for the given token pair.
46+
/// Panics if no swapper for the given pair exists.
47+
access(all) fun removeMockDEXSwapperForPair(inType: Type, outType: Type) {
48+
let swappersForInTypeRef = &self.swappers[inType]! as auth(Mutate) &{Type: Swapper}
49+
swappersForInTypeRef.remove(key: outType)
50+
}
51+
1152
access(all) struct BasicQuote : DeFiActions.Quote {
1253
access(all) let inType: Type
1354
access(all) let outType: Type
@@ -21,9 +62,11 @@ access(all) contract MockDexSwapper {
2162
}
2263
}
2364

65+
/// NOTE: reverse swaps are unsupported.
2466
access(all) struct Swapper : DeFiActions.Swapper {
2567
access(self) let inVault: Type
2668
access(self) let outVault: Type
69+
/// source for output tokens only (reverse swaps unsupported)
2770
access(self) let vaultSource: Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Vault}>
2871
access(self) let priceRatio: UFix64 // out per unit in
2972
access(contract) var uniqueID: DeFiActions.UniqueIdentifier?
@@ -86,4 +129,10 @@ access(all) contract MockDexSwapper {
86129
access(contract) view fun copyID(): DeFiActions.UniqueIdentifier? { return self.uniqueID }
87130
access(contract) fun setID(_ id: DeFiActions.UniqueIdentifier?) { self.uniqueID = id }
88131
}
132+
133+
access(all) struct SwapperProvider : DeFiActions.SwapperProvider {
134+
access(all) fun getSwapper(inType: Type, outType: Type): Swapper? {
135+
return MockDexSwapper.getSwapper(inType: inType, outType: outType)
136+
}
137+
}
89138
}

0 commit comments

Comments
 (0)