Overview
A javascript library for interacting with the JasperVault Protocol.
@jaspervault/jvault.jsInstall
npm install @jaspervault/jvault.jsyarn add @jaspervault/jvault.jsGetting Started
const { JVault } = require("@jaspervault/jvault.js");
const ADDRESSES = require("@jaspervault/jvault.js/dist/src/utils/coreAssets.json");
const config = require("@jaspervault/jvault.js/dist/src/api/config/arbitrum.json");
const { OptionType } = require("@jaspervault/jvault.js/dist/src/utils/types/index");
const ethers = require('ethers');
exports.demo = async ctx => {
ctx.status = 200;
let config_holder = {
ethersProvider: new ethers.providers.JsonRpcProvider("https://arb1.arbitrum.io/rpc"),
ethersSigner: new ethers.Wallet(process.env.PRIVATE_KEY_HOLDER,
new ethers.providers.JsonRpcProvider("https://arb1.arbitrum.io/rpc")),
network: 'arbitrum',
EOA: new ethers.Wallet(process.env.PRIVATE_KEY_HOLDER,
new ethers.providers.JsonRpcProvider("https://arb1.arbitrum.io/rpc")).address
};
let feeData = await config_holder.ethersProvider.getFeeData();
let jVault_holder = new JVault(config_holder);
let optionVault = await jVault_holder.VaultAPI.createNewVault(jVault_holder.EOA, {
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: ethers.utils.parseUnits('0.001', 'gwei')
});
console.log(`optionVault: ${optionVault}`);
let vaults_1 = await jVault_holder.VaultAPI.getAddress(jVault_holder.EOA, 1);
if (optionVault != ethers.constants.AddressZero) {
try {
let writer_config = await jVault_holder.OptionTradingAPI.getOptionWriterSettings();
let tx = await jVault_holder.OptionTradingAPI.createOrder({
amount: ethers.utils.parseEther('100'),
underlyingAsset: ADDRESSES.arbitrum.ARB,
optionType: OptionType.CALL,
premiumAsset: ADDRESSES.arbitrum.USDT,
optionVault: optionVault,
optionWriter: writer_config.arbitrum.CALL.ARB,
premiumVault: vaults_1,
chainId: config.chainId,
secondsToExpiry: 3600 * 2
}, {
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: ethers.utils.parseUnits('0.001', 'gwei')
});
if (tx) {
console.log(`order TX: ${tx.hash}`);
await tx.wait(1);
let order = await jVault_holder.OptionTradingAPI.getOrderByHash(tx.hash);
console.log(order);
}
}
catch (error) {
console.error(`call order failed: ${error}`);
}
}
ctx.body = db.users;
};Alternatively, you can run the demo code found in the script directory.
If everything is running correctly, you should see the following output:
Create a Vault
The Externally Owned Account (EOA) corresponding to the private key will serve as the owner of the Smart Account we create. You can get the private key from wallets like MetaMask, TrustWallet, Coinbase Wallet, etc. 🔑
Create an .evn file, copy the following code in it and replace the PRIVATE_KEY.
Be sure to never publicly expose your private key.
The code below demonstrates how to check if a vault exists and how to create a new one.
Move asset between your EOA and your vault
Execute Your First Transaction
Let's create your first transaction
This example shows how to create a call option order with a size of 100 ARB on Arbitrum.
Get Order Details
After executing a transaction, you may want to retrieve the details of the order. You can do this easily with the following code:
Last updated