Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@cennznet/crml-cennzx-spot
Advanced tools
the javascript sdk for cennznet runtime module: CennzxSpot. also a plugin of @cennznet/api
cennznet-js/crml-cennzx-spot
A sdk providing additional features for cennzx spot runtime module
It is installed along with @cennznet/api
$> npm i --save @cennznet/api
@cennznet/api
will create a instance of cennzxSpot after it finishes initialization.
// node --experimental-repl-await
// initialize Api and connect to dev network
const {Api} = require('@cennznet/api')
const api = await Api.create({provider: 'wss://rimu.unfrastructure.io/public/ws'});
const cennzxSpot = api.cennzxSpot;
// for Rxjs
const {ApiRx} = require('@cennznet/api')
const apiRx = await ApiRx.create({provider: 'wss://rimu.unfrastructure.io/public/ws'});
const cennzxSpotRx = apiRx.cennzxSpot;
All derives related to crml-cennzx-spot are defined in this library, which can be access from both CennzxSpot instance and api.derives.cennzxSpot.*
check API Docs for more information
const coreAssetId = 16001;
const tradeAssetA = 16000;
const tradeAssetB = 16002;
const investAmount: number = 1000;
const maxAssetAmount = '1000';
await cennzxSpot
.addLiquidity(tradeAssetA, 0, maxAssetAmount, investAmount)
.signAndSend(investor.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let isCreated = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'AddLiquidity') {
// Liquidity added
}
}
}
});
#liquidity -> amount to remove
await cennzxSpot.removeLiquidity(tradeAssetA, liquidity, 1, 1)
.signAndSend(investor.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let isRemoved = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'RemoveLiquidity') {
}
}
}
});
Given a certain amountBought
, assetBought
and assetSold
Paying no more than maxPayingAmount
of assetSold
in order to trade for amountBought
of assetBought
//1) query current exchange rate
const expectCost = await cennzxSpot.getOutputPrice(assetSold, assetBought, amountBought);
//2) add a buffer in case price goes up, let's say 2%
const maxPayingAmount = expectCost.muln(1.02);
//3) commit the exchange tx
await cennzxSpot
.assetSwapOutput(assetSold, assetBought, amountBought, maxPayingAmount)
.signAndSend(trader.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let trade = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'TradeAssetPurchase') { // check if ExtrinsicFailed or successful
}
}
}
});
await cennzxSpot
.assetTransferOutput(recipient, assetSold, assetBought, amountBought, maxPayingAmount)
.signAndSend(trader.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let trade = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'TradeAssetPurchase') { // check if ExtrinsicFailed or successful
}
}
}
});
Given a certain amountSell
, assetSold
and assetBought
Sell amountSell
of assetSold
to gain no less than minReceive
amount of AssetBought
//1) query current exchange rate
const expectReceive = await cennzxSpot.getInputPrice(assetSold, assetBought, amountSell);
//2) add a buffer in case price goes down, let's say 2%
const minReceive = expectReceive.muln(0.98);
//3) commit the exchange tx
await cennzxSpot
.assetSwapInput(assetSold, assetBought, amountSell, minReceive)
.signAndSend(trader.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let trade = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'TradeAssetPurchase') { // check if ExtrinsicFailed or successful
}
}
}
});
await cennzxSpot
.assetTransferInput(recipient, assetSold, assetBought, amountSell, minReceive)
.signAndSend(trader.address, ({events, status}: SubmittableResult) => {
if (status.isFinalized && events !== undefined) {
let trade = false;
for (let i = 0; i < status.events.length; i += 1) {
const event = events[i];
if (event.event.method === 'TradeAssetPurchase') { // check if ExtrinsicFailed or successful
}
}
}
});
FAQs
the javascript sdk for cennznet runtime module: CennzxSpot. also a plugin of @cennznet/api
The npm package @cennznet/crml-cennzx-spot receives a total of 11 weekly downloads. As such, @cennznet/crml-cennzx-spot popularity was classified as not popular.
We found that @cennznet/crml-cennzx-spot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.