@mak201010/bluefin-v2-client
Version:
The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.
80 lines • 4.51 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIErrorMessages = exports.VerificationStatus = exports.SuccessMessages = exports.TransformToResponseSchema = exports.handleResponse = exports.LOCKED_ERROR_MESSAGE = void 0;
const library_sui_1 = require("@mak201010/library-sui/");
const eth_rpc_errors_1 = require("eth-rpc-errors");
const lockErrorRetryDelayMS = 2000;
const lockErrorMaxRetries = 5;
exports.LOCKED_ERROR_MESSAGE = "Failed to sign transaction by a quorum of validators because of locked objects";
const handleResponse = (response, ok) => {
const mutatedResponse = {
ok,
data: (0, library_sui_1.getValue)(response.data, "originalError.transaction", response.data),
message: (0, library_sui_1.getValue)(response.data, "originalError.reason", response.message),
code: (0, library_sui_1.getValue)(response.data, "originalError.code", response.code),
stack: response.message,
};
return mutatedResponse;
};
exports.handleResponse = handleResponse;
const TransformToResponseSchema = (contactCall, successMessage) => __awaiter(void 0, void 0, void 0, function* () {
for (let retryNo = 0; retryNo < lockErrorMaxRetries; retryNo++) {
try {
const tx = yield contactCall();
if (library_sui_1.Transaction.getStatus(tx) === "success") {
return (0, exports.handleResponse)({
data: tx,
message: successMessage,
code: 200,
}, true);
}
return (0, exports.handleResponse)({
data: tx,
message: library_sui_1.Transaction.getError(tx),
code: 400,
}, false);
}
catch (error) {
if (error.toString().indexOf(exports.LOCKED_ERROR_MESSAGE) >= 0) {
console.log("Retrying on sui lock error %o", error);
yield new Promise((resolve) => setTimeout(resolve, lockErrorRetryDelayMS));
}
else {
return (0, exports.handleResponse)(Object.assign({}, (0, eth_rpc_errors_1.serializeError)(error)), false);
}
}
}
});
exports.TransformToResponseSchema = TransformToResponseSchema;
var SuccessMessages;
(function (SuccessMessages) {
SuccessMessages["adjustLeverage"] = "Leverage Adjusted to {leverage}x.";
SuccessMessages["adjustMarginAdd"] = "{amount} USDC margin Added to position.";
SuccessMessages["adjustMarginRemove"] = "{amount} USDC margin Removed from position.";
SuccessMessages["withdrawMargin"] = "{amount} USDC withdrawn.";
SuccessMessages["approveUSDC"] = "{amount} USDC approved.";
SuccessMessages["depositToBank"] = "{amount} USDC deposited to Margin Bank.";
SuccessMessages["setSubAccounts"] = "This {address} is successfully {status} as a subaccount";
SuccessMessages["transferCoins"] = "{balance} {coin} transferred to {walletAddress}";
})(SuccessMessages || (exports.SuccessMessages = SuccessMessages = {}));
var VerificationStatus;
(function (VerificationStatus) {
VerificationStatus["Success"] = "success";
VerificationStatus["Restricted"] = "restricted";
VerificationStatus["Blocked"] = "blocked";
})(VerificationStatus || (exports.VerificationStatus = VerificationStatus = {}));
var APIErrorMessages;
(function (APIErrorMessages) {
// eslint-disable-next-line max-len
APIErrorMessages["restrictedUser"] = "This wallet address has been identified as high-risk. You will not be able to open any new positions or deposit funds on the exchange. You may, however, close out any open positions and withdraw free collateral";
})(APIErrorMessages || (exports.APIErrorMessages = APIErrorMessages = {}));
//# sourceMappingURL=contractErrorHandling.service.js.map