use IDVM Vault
This commit is contained in:
@@ -16,7 +16,7 @@ import {DecimalMath} from "../../lib/DecimalMath.sol";
|
|||||||
import {IPermissionManager} from "../../lib/PermissionManager.sol";
|
import {IPermissionManager} from "../../lib/PermissionManager.sol";
|
||||||
import {IGasPriceSource} from "../../lib/GasPriceSource.sol";
|
import {IGasPriceSource} from "../../lib/GasPriceSource.sol";
|
||||||
import {IFeeRateModel} from "../../intf/IFeeRateModel.sol";
|
import {IFeeRateModel} from "../../intf/IFeeRateModel.sol";
|
||||||
import {DVMVault} from "./DVMVault.sol";
|
import {IDVMVault} from "../intf/IDVMVault.sol";
|
||||||
|
|
||||||
contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
@@ -46,7 +46,7 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
|||||||
uint256 public _K_;
|
uint256 public _K_;
|
||||||
uint256 public _I_;
|
uint256 public _I_;
|
||||||
|
|
||||||
DVMVault public _VAULT_;
|
IDVMVault public _VAULT_;
|
||||||
|
|
||||||
// ============ Modifiers ============
|
// ============ Modifiers ============
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,58 @@ interface IDVMVault {
|
|||||||
address _baseToken,
|
address _baseToken,
|
||||||
address _quoteToken
|
address _quoteToken
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function _BASE_TOKEN_() external returns (address);
|
||||||
|
|
||||||
|
function _QUOTE_TOKEN_() external returns (address);
|
||||||
|
|
||||||
|
function _BASE_RESERVE_() external returns (address);
|
||||||
|
|
||||||
|
function _QUOTE_RESERVE_() external returns (address);
|
||||||
|
|
||||||
|
function symbol() external returns (string memory);
|
||||||
|
|
||||||
|
function decimals() external returns (uint256);
|
||||||
|
|
||||||
|
function name() external returns (string memory);
|
||||||
|
|
||||||
|
function totalSupply() external returns (uint256);
|
||||||
|
|
||||||
|
function getVaultBalance() external view returns (uint256 baseBalance, uint256 quoteBalance);
|
||||||
|
|
||||||
|
function getVaultReserve() external view returns (uint256 baseReserve, uint256 quoteReserve);
|
||||||
|
|
||||||
|
function getBaseBalance() external view returns (uint256 baseBalance);
|
||||||
|
|
||||||
|
function getQuoteBalance() external view returns (uint256 quoteBalance);
|
||||||
|
|
||||||
|
function getBaseInput() external view returns (uint256 input);
|
||||||
|
|
||||||
|
function getQuoteInput() external view returns (uint256 input);
|
||||||
|
|
||||||
|
function sync() external;
|
||||||
|
|
||||||
|
function transferBaseOut(address to, uint256 amount) external;
|
||||||
|
|
||||||
|
function transferQuoteOut(address to, uint256 amount) external;
|
||||||
|
|
||||||
|
function transfer(address to, uint256 amount) external returns (bool);
|
||||||
|
|
||||||
|
function balanceOf(address owner) external view returns (uint256 balance);
|
||||||
|
|
||||||
|
function shareRatioOf(address owner) external view returns (uint256 shareRatio);
|
||||||
|
|
||||||
|
function transferFrom(
|
||||||
|
address from,
|
||||||
|
address to,
|
||||||
|
uint256 amount
|
||||||
|
) external returns (bool);
|
||||||
|
|
||||||
|
function approve(address spender, uint256 amount) external returns (bool);
|
||||||
|
|
||||||
|
function allowance(address owner, address spender) external view returns (uint256);
|
||||||
|
|
||||||
|
function mint(address user, uint256 value) external;
|
||||||
|
|
||||||
|
function burn(address user, uint256 value) external;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,6 @@ describe("Trader", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("trade", () => {
|
describe("trade", () => {
|
||||||
// it.only("gas cost", async () => {
|
|
||||||
// await logGas(ctx.DVM.methods.calculateBase0(decimalStr("200"), decimalStr("1")), ctx.sendParam(trader), "calculate base0")
|
|
||||||
// })
|
|
||||||
it("buy & sell", async () => {
|
it("buy & sell", async () => {
|
||||||
|
|
||||||
console.log("BASE0 before buy", await ctx.DVM.methods.getBase0().call())
|
console.log("BASE0 before buy", await ctx.DVM.methods.getBase0().call())
|
||||||
@@ -119,6 +116,37 @@ describe("Trader", () => {
|
|||||||
await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(),
|
await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(),
|
||||||
"103733009669408099"
|
"103733009669408099"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// buy when quoet is not 0
|
||||||
|
await logGas(ctx.Route.methods.sellQuoteOnDVM(ctx.DVM.options.address, trader, decimalStr("200"), decimalStr("1")), ctx.sendParam(trader), "buy base token")
|
||||||
|
console.log("BASE0 after second buy", await ctx.DVM.methods.getBase0().call())
|
||||||
|
// trader balances
|
||||||
|
console.log(
|
||||||
|
await ctx.BASE.methods.balanceOf(trader).call(),
|
||||||
|
"12837528824326616018"
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
await ctx.QUOTE.methods.balanceOf(trader).call(),
|
||||||
|
"703421810640399874603"
|
||||||
|
);
|
||||||
|
// vault balances
|
||||||
|
console.log(
|
||||||
|
await ctx.BASE.methods.balanceOf(ctx.Vault.options.address).call(),
|
||||||
|
"7158622099620899913"
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
await ctx.QUOTE.methods.balanceOf(ctx.Vault.options.address).call(),
|
||||||
|
"296474456349930717298"
|
||||||
|
);
|
||||||
|
// maintainer balances
|
||||||
|
console.log(
|
||||||
|
await ctx.BASE.methods.balanceOf(ctx.Maintainer).call(),
|
||||||
|
"3849076052484069"
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(),
|
||||||
|
"103733009669408099"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user