A TypeScript library for interacting with the dYdX protocol.
Usage
Install
npm install --save @dydxprotocol/dydx.js
Initialize
import { DYDX } from '@dydxprotocol/dydx.js';
const dydx = new DYDX();
await dydx.initialize(provider, networkId);
Short & Leveraged Tokens
Mint
await dydx.shortToken.mint(
positionId,
trader,
tokensToMint,
payInHeldToken,
exchangeWrapper,
orderData,
options,
);
Or mint with ETH:
await dydx.shortToken.mintWithETH(
positionId,
trader,
tokensToMint,
ethToSend,
ethIsHeldToken,
exchangeWrapper,
orderData,
options,
);
Or mint directly (you will put up all held token [DAI for sETH] and will receive owed token [WETH for sETH]):
await dydx.token.setMaximumProxyAllowance(
heldTokenAddress,
traderAddress,
);
await dydx.shortToken.mintDirectly(
positionId,
trader,
tokensToMint,
);
Close
Close directly (you will pay all owed token owed to lenders [WETH for sETH] and will receive all held token collateral [DAI for sETH])
await dydx.token.setMaximumProxyAllowance(
owedTokenAddress,
traderAddress,
);
await dydx.shortToken.closeDirectly(
positionId,
closer,
tokensToClose,
);
Development
Install
npm install
Compile
npm run build