@dolomite-exchange/dolomite-margin
Version:
Ethereum Smart Contracts and TypeScript library used for the DolomiteMargin trading protocol
143 lines (138 loc) • 8.02 kB
JavaScript
"use strict";
/*
Copyright 2019 dYdX Trading Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DolomiteMargin = void 0;
var web3_1 = __importDefault(require("web3"));
var Contracts_1 = require("./lib/Contracts");
var Interest_1 = require("./lib/Interest");
var Admin_1 = require("./modules/Admin");
var ArbitrumGasInfo_1 = require("./modules/ArbitrumGasInfo");
var BorrowPositionProxyV1_1 = require("./modules/BorrowPositionProxyV1");
var BorrowPositionProxyV2_1 = require("./modules/BorrowPositionProxyV2");
var DepositProxy_1 = require("./modules/DepositProxy");
var Expiry_1 = require("./modules/Expiry");
var GenericTraderProxyV1_1 = require("./modules/GenericTraderProxyV1");
var Getters_1 = require("./modules/Getters");
var LiquidatorAssetRegistry_1 = require("./modules/LiquidatorAssetRegistry");
var LiquidatorProxyV1_1 = require("./modules/LiquidatorProxyV1");
var LiquidatorProxyV4WithGenericTrader_1 = require("./modules/LiquidatorProxyV4WithGenericTrader");
var IsolationModeUnwrapper_1 = require("./modules/IsolationModeUnwrapper");
var Logs_1 = require("./modules/Logs");
var MultiCall_1 = require("./modules/MultiCall");
var Operation_1 = require("./modules/operate/Operation");
var ChainlinkPriceOracleV1_1 = require("./modules/oracles/ChainlinkPriceOracleV1");
var OrderMapper_1 = require("./modules/OrderMapper");
var Permissions_1 = require("./modules/Permissions");
var SignedOperations_1 = require("./modules/SignedOperations");
var StandardActions_1 = require("./modules/StandardActions");
var Token_1 = require("./modules/Token");
var TransferProxy_1 = require("./modules/TransferProxy");
var WalletLogin_1 = require("./modules/WalletLogin");
var PayableToken_1 = require("./modules/PayableToken");
var types_1 = require("./types");
var IsolationModeWrapper_1 = require("./modules/IsolationModeWrapper");
var ExpiryProxy_1 = require("./modules/ExpiryProxy");
var MantleGasInfo_1 = require("./modules/MantleGasInfo");
var DolomiteMargin = /** @class */ (function () {
function DolomiteMargin(provider, networkId, options) {
var _this = this;
if (networkId === void 0) { networkId = types_1.Networks.ARBITRUM_ONE; }
if (options === void 0) { options = {}; }
var realProvider;
if (typeof provider === 'string') {
realProvider = new web3_1.default.providers.HttpProvider(provider, options.ethereumNodeTimeout || 10000);
}
else {
realProvider = provider;
}
this.web3 = new web3_1.default(realProvider);
if (options.defaultAccount) {
this.web3.eth.defaultAccount = options.defaultAccount;
}
this.contracts = this.createContractsModule(realProvider, networkId, this.web3, options);
this.admin = new Admin_1.Admin(this.contracts);
this.arbitrumGasInfo = networkId === types_1.Networks.ARBITRUM_ONE ? new ArbitrumGasInfo_1.ArbitrumGasInfo(this.contracts) : undefined;
this.borrowPositionProxyV1 = new BorrowPositionProxyV1_1.BorrowPositionProxyV1(this.contracts);
this.borrowPositionProxyV2 = new BorrowPositionProxyV2_1.BorrowPositionProxyV2(this.contracts);
this.chainlinkPriceOracle = new ChainlinkPriceOracleV1_1.ChainlinkPriceOracleV1(this.contracts);
this.depositWithdrawalProxy = new DepositProxy_1.DepositProxy(this.contracts);
this.expiry = new Expiry_1.Expiry(this.contracts);
this.expiryProxy = new ExpiryProxy_1.ExpiryProxy(this.contracts);
this.genericTraderProxyV1 = new GenericTraderProxyV1_1.GenericTraderProxyV1(this.contracts);
this.getters = new Getters_1.Getters(this.contracts);
this.interest = new Interest_1.Interest(networkId);
this.liquidatorAssetRegistry = new LiquidatorAssetRegistry_1.LiquidatorAssetRegistry(this.contracts);
this.liquidatorProxyV1 = new LiquidatorProxyV1_1.LiquidatorProxyV1(this.contracts);
this.liquidatorProxyV4WithGenericTrader = new LiquidatorProxyV4WithGenericTrader_1.LiquidatorProxyV4WithGenericTrader(this.contracts);
this.logs = new Logs_1.Logs(this.contracts, this.web3);
this.mantleGasInfo = networkId === types_1.Networks.MANTLE ? new MantleGasInfo_1.MantleGasInfo(this.contracts) : undefined;
this.multiCall = new MultiCall_1.MultiCall(this.contracts);
this.networkId = networkId;
this.operation = new Operation_1.Operation(this.contracts, new OrderMapper_1.OrderMapper(this.contracts), networkId);
this.permissions = new Permissions_1.Permissions(this.contracts);
this.signedOperations = new SignedOperations_1.SignedOperations(this.contracts, this.web3, networkId);
this.standardActions = new StandardActions_1.StandardActions(this.operation, this.contracts);
this.token = new Token_1.Token(this.contracts);
this.transferProxy = new TransferProxy_1.TransferProxy(this.contracts);
this.walletLogin = new WalletLogin_1.WalletLogin(this.web3, networkId);
this.payableToken = new PayableToken_1.PayableToken(this.contracts, this.token);
if (options.accounts) {
options.accounts.forEach(function (a) { return _this.loadAccount(a); });
}
}
Object.defineProperty(DolomiteMargin.prototype, "address", {
/**
* @return The address of the main DolomiteMargin smart contract
*/
get: function () {
return this.contracts.dolomiteMargin.options.address;
},
enumerable: false,
configurable: true
});
DolomiteMargin.prototype.setProvider = function (provider, networkId) {
this.web3.setProvider(provider);
this.contracts.setProvider(provider, networkId);
this.interest.setNetworkId(networkId);
};
DolomiteMargin.prototype.setDefaultAccount = function (account) {
this.web3.eth.defaultAccount = account;
this.contracts.setDefaultAccount(account);
};
DolomiteMargin.prototype.getDefaultAccount = function () {
return this.web3.eth.defaultAccount;
};
// ============ Helper Functions ============
DolomiteMargin.prototype.loadAccount = function (account) {
var newAccount = this.web3.eth.accounts.wallet.add(account.privateKey);
if (!newAccount || (account.address && account.address.toLowerCase() !== newAccount.address.toLowerCase())) {
throw new Error("Loaded account address mismatch.\n Expected " + account.address + ", got " + (newAccount ? newAccount.address : null));
}
};
DolomiteMargin.prototype.getIsolationModeUnwrapper = function (unwrapperAddress) {
return new IsolationModeUnwrapper_1.IsolationModeUnwrapper(this.contracts, this.contracts.getIsolationModeUnwrapper(unwrapperAddress));
};
DolomiteMargin.prototype.getIsolationModeWrapper = function (unwrapperAddress) {
return new IsolationModeWrapper_1.IsolationModeWrapper(this.contracts, this.contracts.getIsolationModeWrapper(unwrapperAddress));
};
DolomiteMargin.prototype.createContractsModule = function (provider, networkId, web3, options) {
return new Contracts_1.Contracts(provider, networkId, web3, options);
};
return DolomiteMargin;
}());
exports.DolomiteMargin = DolomiteMargin;
//# sourceMappingURL=DolomiteMargin.js.map