@@ -13,9 +13,9 @@ import { makeMakeRemoveLiquidityInvitation } from './removeLiquidity';
13
13
import '../../../exported' ;
14
14
15
15
/**
16
- * Autoswap is a rewrite of Uniswap. Please see the documentation for
17
- * more
18
- * https://agoric.com/documentation/zoe/guide/contracts/autoswap.html
16
+ * Multipool Autoswap is a rewrite of Uniswap that supports multiple liquidity
17
+ * pools, and direct exchanges across pools. Please see the documentation for
18
+ * more: https://agoric.com/documentation/zoe/guide/contracts/autoswap.html
19
19
*
20
20
* We expect that this contract will have tens to hundreds of issuers.
21
21
* Each liquidity pool is between the central token and a secondary
@@ -30,9 +30,25 @@ import '../../../exported';
30
30
*
31
31
* When the contract is instantiated, the central token is specified
32
32
* in the terms. Separate invitations are available by calling methods
33
- * on the publicFacet for adding and removing liquidity, and for
34
- * making trades. Other publicFacet operations support monitoring
35
- * prices and the sizes of pools.
33
+ * on the publicFacet for adding and removing liquidity and for
34
+ * making trades. Other publicFacet operations support querying
35
+ * prices and the sizes of pools. New Pools can be created with addPool().
36
+ *
37
+ * When making trades or requesting prices, the caller must specify that either
38
+ * the input price (swapIn, getInputPrice) or the output price (swapOut,
39
+ * getOutPutPrice) is fixed. For swaps, the required keywords are `In` for the
40
+ * trader's `give` amount, and `Out` for the trader's `want` amount.
41
+ * getInputPrice and getOutPrice each take an Amount for the direction that is
42
+ * being specified, and just a brand for the desired value, which is returned as
43
+ * the appropriate amount.
44
+ *
45
+ * When adding and removing liquidity, the keywords are Central, Secondary, and
46
+ * Liquidity. adding liquidity has Central and Secondary in the `give` section,
47
+ * while removing liquidity has `want` and `give` swapped.
48
+ *
49
+ * Transactions that don't require an invitation include addPool, and the
50
+ * queries: getInputPrice, getOutputPrice, getPoolAllocation,
51
+ * getLiquidityIssuer, and getLiquiditySupply.
36
52
*
37
53
* @type {ContractStartFn }
38
54
*/
@@ -51,20 +67,23 @@ const start = zcf => {
51
67
const isSecondary = secondaryBrandToPool . has ;
52
68
const isCentral = brand => brand === centralBrand ;
53
69
70
+ const getLiquiditySupply = brand => getPool ( brand ) . getLiquiditySupply ( ) ;
54
71
const getLiquidityIssuer = brand => getPool ( brand ) . getLiquidityIssuer ( ) ;
55
72
const addPool = makeAddPool ( zcf , isSecondary , initPool , centralBrand ) ;
56
73
const getPoolAllocation = brand => {
57
74
return getPool ( brand )
58
75
. getPoolSeat ( )
59
76
. getCurrentAllocation ( ) ;
60
77
} ;
61
- const getCurrentPrice = makeGetCurrentPrice ( isSecondary , isCentral , getPool ) ;
62
- const makeSwapInvitation = makeMakeSwapInvitation (
63
- zcf ,
64
- isSecondary ,
65
- isCentral ,
66
- getPool ,
67
- ) ;
78
+
79
+ const {
80
+ getOutputForGivenInput,
81
+ getInputForGivenOutput,
82
+ } = makeGetCurrentPrice ( isSecondary , isCentral , getPool ) ;
83
+ const {
84
+ makeSwapInInvitation,
85
+ makeSwapOutInvitation,
86
+ } = makeMakeSwapInvitation ( zcf , isSecondary , isCentral , getPool ) ;
68
87
const makeAddLiquidityInvitation = makeMakeAddLiquidityInvitation (
69
88
zcf ,
70
89
getPool ,
@@ -75,12 +94,17 @@ const start = zcf => {
75
94
getPool ,
76
95
) ;
77
96
97
+ /** @type {MultipoolAutoswapPublicFacet } */
78
98
const publicFacet = {
79
99
addPool,
80
100
getPoolAllocation,
81
101
getLiquidityIssuer,
82
- getCurrentPrice,
83
- makeSwapInvitation,
102
+ getLiquiditySupply,
103
+ getInputPrice : getOutputForGivenInput ,
104
+ getOutputPrice : getInputForGivenOutput ,
105
+ makeSwapInvitation : makeSwapInInvitation ,
106
+ makeSwapInInvitation,
107
+ makeSwapOutInvitation,
84
108
makeAddLiquidityInvitation,
85
109
makeRemoveLiquidityInvitation,
86
110
} ;
0 commit comments