UNPKG

@firefly-exchange/library-sui

Version:

Sui library housing helper methods, classes to interact with Bluefin protocol(s) deployed on Sui

156 lines (155 loc) 9.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdminCalls = void 0; const __1 = require("../../"); const on_chain_calls_1 = require("./on-chain-calls"); const helpers_1 = require("../../helpers"); const defaults_1 = require("../../defaults"); const bcs_1 = require("../utils/bcs"); class AdminCalls extends on_chain_calls_1.OnChainCalls { /** * Create and executes support asset transaction. Allows admin to add a new supportable asset on * the protocol * @param supportedCoin supported coin address. should be of format 0xax....bs::coin::COIN * @param supportedCoinSymbol Name of the supported coin * @param coinDecimals The number of decimals in supported coin * @param weight The discounted price percentage to be used for asset * @param price The initial/starting price of the asset * @param collateral True if the asset can be used to collateralize a position * @param minDeposit The minimum amount of acceptable deposit * @param maxDeposit The maximum amount of acceptable deposit * @param options Optional tx execution params * @returns OnChainCallResponse */ async supportAsset(supportedCoin, supportedCoinSymbol, supportedCoinDecimals, weight, price, collateral, minDeposit, maxDeposit, options) { const txb = this.txBuilder.supportAsset(supportedCoin, supportedCoinSymbol, supportedCoinDecimals, weight, price, collateral, minDeposit, maxDeposit, options); return this.execCall(txb, options); } /** * Create and executes data store creation transaction * @param sequencer address of the sequencer that will own the data store * @param options Optional tx execution params * @returns OnChainCallResponse */ async createInternalDataStore(sequencer, options) { const txb = this.txBuilder.createInternalDataStore(sequencer || this.walletAddress, options); return this.execCall(txb, options); } /** * Allows the holder of the Treasury cap to mint test usdc coins (Will only work on Dev/Test net) * @param args optional {amountE6: defaults to 10K, should be in 6 decimal places, to: defaults to the signer} * @param options Optional tx execution params * @returns OnChainCallResponse */ async mintUSDC(args, options) { const txb = this.txBuilder.mintUSDC(args?.amountE6 || (0, __1.toBigNumberStr)(10000, __1.USDC_BASE_DECIMALS), args?.to || this.walletAddress, options); return this.execCall(txb, options); } /** * Create and executes perpetual creation transaction * @param perpetualConfig perpetual configs * @param options Optional tx execution params * @returns OnChainCallResponse and IPerpetualConfig */ async createPerpetual(perpetualConfig, options) { perpetualConfig = { baseAssetSymbol: perpetualConfig.baseAssetSymbol || "ETH", baseAssetName: perpetualConfig.baseAssetName || "Ethereum", baseAssetDecimals: perpetualConfig.baseAssetDecimals || "600000", defaultLeverage: perpetualConfig.defaultLeverage || "3000000000", symbol: perpetualConfig.symbol || "ETH-PERP", imr: perpetualConfig.imr || (0, __1.toBigNumberStr)(0.1, __1.SUI_NATIVE_BASE), mmr: perpetualConfig.mmr || (0, __1.toBigNumberStr)(0.05, __1.SUI_NATIVE_BASE), stepSize: perpetualConfig.stepSize || (0, __1.toBigNumberStr)(0.1, __1.SUI_NATIVE_BASE), tickSize: perpetualConfig.tickSize || (0, __1.toBigNumberStr)(0.001, __1.SUI_NATIVE_BASE), minTradeQty: perpetualConfig.minTradeQty || (0, __1.toBigNumberStr)(0.1, __1.SUI_NATIVE_BASE), maxTradeQty: perpetualConfig.maxTradeQty || (0, __1.toBigNumberStr)(1000, __1.SUI_NATIVE_BASE), minTradePrice: perpetualConfig.minTradePrice || (0, __1.toBigNumberStr)(0.1, __1.SUI_NATIVE_BASE), maxTradePrice: perpetualConfig.maxTradePrice || (0, __1.toBigNumberStr)(100000, __1.SUI_NATIVE_BASE), maxNotionalAtOpen: perpetualConfig.maxNotionalAtOpen || [ (0, __1.toBigNumberStr)(1000000, __1.SUI_NATIVE_BASE), //1x (0, __1.toBigNumberStr)(1000000, __1.SUI_NATIVE_BASE), //2x (0, __1.toBigNumberStr)(500000, __1.SUI_NATIVE_BASE), //3x (0, __1.toBigNumberStr)(500000, __1.SUI_NATIVE_BASE), //4x (0, __1.toBigNumberStr)(250000, __1.SUI_NATIVE_BASE), //5x (0, __1.toBigNumberStr)(250000, __1.SUI_NATIVE_BASE), //6x (0, __1.toBigNumberStr)(250000, __1.SUI_NATIVE_BASE), //7x (0, __1.toBigNumberStr)(250000, __1.SUI_NATIVE_BASE), //8x (0, __1.toBigNumberStr)(100000, __1.SUI_NATIVE_BASE), //9x (0, __1.toBigNumberStr)(100000, __1.SUI_NATIVE_BASE) //10x ], mtbLong: perpetualConfig.mtbLong || (0, __1.toBigNumberStr)(0.2, __1.SUI_NATIVE_BASE), mtbShort: perpetualConfig.mtbShort || (0, __1.toBigNumberStr)(0.2, __1.SUI_NATIVE_BASE), makerFee: perpetualConfig.makerFee != undefined ? perpetualConfig.makerFee : (0, __1.toBigNumberStr)(0.001, __1.SUI_NATIVE_BASE), takerFee: perpetualConfig.takerFee != undefined ? perpetualConfig.takerFee : (0, __1.toBigNumberStr)(0.0045, __1.SUI_NATIVE_BASE), maxFundingRate: perpetualConfig.maxFundingRate != undefined ? perpetualConfig.maxFundingRate : (0, __1.toBigNumberStr)(0.001, __1.SUI_NATIVE_BASE), insurancePoolRatio: perpetualConfig.insurancePoolRatio != undefined ? perpetualConfig.insurancePoolRatio : (0, __1.toBigNumberStr)(0.3, __1.SUI_NATIVE_BASE), tradingStartTime: (0, helpers_1.processTradingStartTime)(perpetualConfig.tradingStartTime || 0, this.network == "mainnet" ? "PROD" : "DEV"), insurancePool: perpetualConfig.insurancePool || defaults_1.DEFAULT.INSURANCE_POOL_ADDRESS, feePool: perpetualConfig.feePool || defaults_1.DEFAULT.FEE_POOL_ADDRESS, tradingStatus: true, delist: false, delistingPrice: 0, isolatedOnly: perpetualConfig.isolatedOnly || false, maxLimitOrderQuantity: perpetualConfig.maxLimitOrderQuantity || (0, __1.toBigNumberStr)(10000, __1.SUI_NATIVE_BASE), maxMarketOrderQuantity: perpetualConfig.maxMarketOrderQuantity || (0, __1.toBigNumberStr)(1000, __1.SUI_NATIVE_BASE) }; perpetualConfig.minTradeQty = perpetualConfig.stepSize; const txb = this.txBuilder.createPerpetual(perpetualConfig.symbol, perpetualConfig.imr, perpetualConfig.mmr, perpetualConfig.stepSize, perpetualConfig.tickSize, perpetualConfig.minTradeQty, perpetualConfig.maxTradeQty, perpetualConfig.minTradePrice, perpetualConfig.maxTradePrice, perpetualConfig.maxNotionalAtOpen, perpetualConfig.mtbLong, perpetualConfig.mtbShort, perpetualConfig.makerFee, perpetualConfig.takerFee, perpetualConfig.maxFundingRate, perpetualConfig.insurancePoolRatio, perpetualConfig.tradingStartTime, perpetualConfig.insurancePool, perpetualConfig.feePool, perpetualConfig.isolatedOnly, perpetualConfig.baseAssetSymbol, perpetualConfig.baseAssetName, perpetualConfig.baseAssetDecimals, perpetualConfig.maxLimitOrderQuantity, perpetualConfig.maxMarketOrderQuantity, perpetualConfig.defaultLeverage, options); return { txResponse: await this.execCall(txb, options), perpetualConfig }; } /** * Create and executes transaction to update perpetual config * @param perpetual the symbol of the perpetual/market to be updated * @param field the name of the field/config being updated * @param value the new value * @param options Optional tx execution params * @returns OnChainCallResponse */ async updatePerpetual(perpetual, field, value, options) { let serialized_value; if (typeof value === "string") { // address serialized_value = bcs_1.bcs.Address.serialize(value).toBytes(); } else if (typeof value == "boolean") { // status serialized_value = bcs_1.bcs.Bool.serialize(value).toBytes(); } else if (typeof value == "number") { // a u64 value serialized_value = bcs_1.bcs.U64.serialize(value).toBytes(); } else if (Array.isArray(value)) { // a vector<u64> value serialized_value = bcs_1.bcs.vector(bcs_1.bcs.u64()).serialize(value).toBytes(); } else { throw `The value can only be a string(Address), number(u64) or a boolean`; } const txb = this.txBuilder.updatePerpetual(perpetual, field, serialized_value, options); return this.execCall(txb, options); } /** * Create and executes transaction to set an operator on EDS * @param type The type of the operator be updated * @param newOperator The address of the new operator to be set * @param options Optional tx execution params * @returns OnChainCallResponse */ async setOperatorEDS(type, newOperator, options) { const txb = this.txBuilder.setOperatorEDS(type, newOperator, options); return this.execCall(txb, options); } } exports.AdminCalls = AdminCalls;