@dbricks/dbricks-ts
Version:
## Introduction
76 lines (75 loc) • 2.44 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const winston_1 = __importDefault(require("winston"));
const src_1 = require("../src");
const util_1 = require("./util");
const ownerKp = (0, util_1.loadKeypairSync)(process.env.KEYPAIR_PATH);
async function play() {
const builder = new src_1.Builder({
ownerPubkey: ownerKp.publicKey,
connectionUrl: 'https://solana-api.projectserum.com',
committment: 'processed',
});
// buy 1 MNGO for 0.3 USDC
builder.addBrick({
protocol: src_1.Protocol.Serum,
action: src_1.Action.Serum.PlaceOrder,
args: {
marketPubkey: '3d4rzwpy9iGdCZvgxcu7B1YocYffVLsQXPXkBZKt2zLc',
side: 'buy',
price: '0.3',
size: '1',
orderType: 'limit',
},
});
// settle Serum market (see docs if unclear why)
builder.addBrick({
protocol: src_1.Protocol.Serum,
action: src_1.Action.Serum.SettleMarket,
args: {
marketPubkey: '3d4rzwpy9iGdCZvgxcu7B1YocYffVLsQXPXkBZKt2zLc',
},
});
// deposit the just acquired 1 MNGO token into Mango
builder.addBrick({
protocol: src_1.Protocol.Mango,
action: src_1.Action.Mango.Deposit,
args: {
mintPubkey: 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac',
quantity: '1',
mangoAccountNumber: '0',
},
});
// sell 1 MNGO back for USDC
builder.addBrick({
protocol: src_1.Protocol.Mango,
action: src_1.Action.Mango.PlaceSpotOrder,
args: {
marketPubkey: '3d4rzwpy9iGdCZvgxcu7B1YocYffVLsQXPXkBZKt2zLc',
side: 'sell',
price: '0.2',
size: '1',
orderType: 'limit',
mangoAccountNumber: '0',
},
});
// withdraw from MNGO
builder.addBrick({
protocol: src_1.Protocol.Mango,
action: src_1.Action.Mango.Withdraw,
args: {
mintPubkey: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
quantity: '0.2',
isBorrow: false,
mangoAccountNumber: '0',
},
});
await builder.build({
keypair: ownerKp,
});
winston_1.default.info('All done (using keypair).');
}
play();