Beispiel #1
0
        /// <summary>
        /// 移除流动性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="tokenA"></param>
        /// <param name="tokenB"></param>
        /// <param name="liquidity">移除的liquidity Token量</param>
        /// <param name="amountAMin">tokenA 期望最小提取量,Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.</param>
        /// <param name="amountBMin">tokenB 期望最小提取量</param>
        /// <param name="deadLine"></param>
        /// <returns></returns>
        public static BigInteger[] RemoveLiquidity(UInt160 sender, UInt160 tokenA, UInt160 tokenB, BigInteger liquidity, BigInteger amountAMin, BigInteger amountBMin, BigInteger deadLine)
        {
            //验证权限
            Assert(Runtime.CheckWitness(sender), "Forbidden");
            //看看有没有超过最后期限
            Assert((BigInteger)Runtime.Time <= deadLine, "Exceeded the deadline");


            var pairContract = GetExchangePairWithAssert(tokenA, tokenB);

            SafeTransfer(pairContract, sender, pairContract, liquidity);

            var amounts = pairContract.DynamicBurn(sender);
            //var amounts = (byte[])Contract.Call(pairContract, "burn", CallFlags.All, sender);
            var tokenAIsToken0 = tokenA.ToUInteger() < tokenB.ToUInteger();
            var amountA        = tokenAIsToken0 ? amounts[0] : amounts[1];
            var amountB        = tokenAIsToken0 ? amounts[1] : amounts[0];

            Assert(amountA >= amountAMin, "Insufficient A Amount");
            Assert(amountB >= amountBMin, "Insufficient B Amount");

            return(new BigInteger[] { amountA, amountB });
        }
Beispiel #2
0
        /// <summary>
        /// 查询TokenA,TokenB交易对合约的里的持有量并按A、B顺序返回
        /// </summary>
        /// <param name="tokenA"></param>
        /// <param name="tokenB"></param>
        /// <returns></returns>
        public static BigInteger[] GetReserves(UInt160 tokenA, UInt160 tokenB)
        {
            var reserveData = (ReservesData)Contract.Call(GetExchangePairWithAssert(tokenA, tokenB), "getReserves", CallFlags.ReadOnly, new object[] { });

            return(tokenA.ToUInteger() < tokenB.ToUInteger() ? new BigInteger[] { reserveData.Reserve0, reserveData.Reserve1 } : new BigInteger[] { reserveData.Reserve1, reserveData.Reserve0 });
        }
Beispiel #3
0
 /// <summary>
 /// 获取pair
 /// </summary>
 /// <param name="tokenA"></param>
 /// <param name="tokenB"></param>
 /// <returns></returns>
 private static byte[] GetPairKey(UInt160 tokenA, UInt160 tokenB)
 {
     return(tokenA.ToUInteger() < tokenB.ToUInteger()
         ? ExchangeMapKey.Concat(tokenA).Concat(tokenB)
         : ExchangeMapKey.Concat(tokenB).Concat(tokenA));
 }