Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bancor/carbon-sdk

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bancor/carbon-sdk - npm Package Compare versions

Comparing version 0.0.12-DEV to 0.0.13-DEV

lib/cjs/chain/utils.js

17

lib/cjs/chain/Composer.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const numerics_1 = require("../numerics");
const utils_1 = require("./utils");
class Composer {

@@ -8,6 +10,17 @@ constructor(contracts) {

trade(sourceToken, targetToken, tradeActions, tradeByTargetAmount, overrides) {
return this._contracts.poolCollection.populateTransaction.trade(sourceToken, targetToken, tradeActions, tradeByTargetAmount, overrides);
const customOverrides = Object.assign({}, overrides);
if ((0, utils_1.isETHAddress)(sourceToken)) {
customOverrides.value = tradeActions.reduce((acc, cur) => acc.add(cur.amount), numerics_1.BigNumber.from(0));
}
return this._contracts.poolCollection.populateTransaction.trade(sourceToken, targetToken, tradeActions, tradeByTargetAmount, customOverrides);
}
createStrategy(token0, token1, y0, z0, A0, B0, y1, z1, A1, B1, overrides) {
return this._contracts.poolCollection.populateTransaction.createStrategy(token0, token1, y0, z0, A0, B0, y1, z1, A1, B1, overrides);
const customOverrides = Object.assign({}, overrides);
if ((0, utils_1.isETHAddress)(token0)) {
customOverrides.value = y0;
}
else if ((0, utils_1.isETHAddress)(token1)) {
customOverrides.value = y1;
}
return this._contracts.poolCollection.populateTransaction.createStrategy(token0, token1, y0, z0, A0, B0, y1, z1, A1, B1, customOverrides);
}

@@ -14,0 +27,0 @@ transferVoucherOwnership(newOwner, overrides) {

7

lib/cjs/chain/Reader.js

@@ -13,2 +13,3 @@ "use strict";

const multicall_1 = require("./multicall");
const utils_1 = require("./utils");
const toStrategy = (res) => {

@@ -47,4 +48,6 @@ const id = res[0];

this.getDecimalsByAddress = (address) => __awaiter(this, void 0, void 0, function* () {
const decimals = yield this._contracts.token(address).decimals();
return decimals;
if ((0, utils_1.isETHAddress)(address)) {
return 18;
}
return this._contracts.token(address).decimals();
});

@@ -51,0 +54,0 @@ this._contracts = contracts;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchByTargetAmount = exports.matchBySourceAmount = exports.match = exports.getRateByTargetAmount = exports.getRateBySourceAmount = exports.getTradeSourceAmount = exports.getTradeTargetAmount = void 0;
exports.matchByTargetAmount = exports.matchBySourceAmount = exports.match = exports.getRateByTargetAmount = exports.getRateBySourceAmount = void 0;
const utils_1 = require("./utils");
const numerics_1 = require("../numerics");
const MIN = numerics_1.BigNumber.from(0);
const MAX = numerics_1.BigNumber.from(2).pow(128).sub(1);
const getTradeTargetAmount = (x, order) => {
const temp1 = order.y.mul(order.A).add(order.z.mul(order.B));
const temp2 = temp1.mul(x).div(numerics_1.ONE);
const temp3 = temp2.mul(order.A).add(order.z.mul(order.z).mul(numerics_1.ONE));
const res = (0, utils_1.mulDivF)(temp1, temp2, temp3);
return res.gt(MAX) ? MIN : res;
};
exports.getTradeTargetAmount = getTradeTargetAmount;
const getTradeSourceAmount = (x, order) => {
const temp1 = order.z.mul(numerics_1.ONE);
const temp2 = order.y.mul(order.A).add(order.z.mul(order.B));
const temp3 = temp2.sub(x.mul(order.A));
const res = (0, utils_1.mulDivC)(x.mul(temp1), temp1, temp2.mul(temp3));
return res.lt(MIN) ? MAX : res;
};
exports.getTradeSourceAmount = getTradeSourceAmount;
const trade_1 = require("../trade");
const getRateBySourceAmount = (sourceAmount, order) => {
const targetAmount = (0, exports.getTradeTargetAmount)(sourceAmount, order);
const targetAmount = (0, trade_1.getEncodedTradeTargetAmount)(sourceAmount, order);
const output = targetAmount.lt(order.y) ? targetAmount : order.y;
const input = (0, exports.getTradeSourceAmount)(output, order);
const input = (0, trade_1.getEncodedTradeSourceAmount)(output, order);
return { input, output };

@@ -33,7 +16,7 @@ };

const input = targetAmount.lt(order.y) ? targetAmount : order.y;
const output = (0, exports.getTradeSourceAmount)(input, order);
const output = (0, trade_1.getEncodedTradeSourceAmount)(input, order);
return { input, output };
};
exports.getRateByTargetAmount = getRateByTargetAmount;
const match = (amount, orders, trade, cmp, filter) => {
const match = (amount, orders, filter, trade, cmp) => {
const actions = [];

@@ -44,3 +27,3 @@ for (const { id, rate } of Object.keys(orders)

if (amount.gt(rate.input)) {
if (!filter || filter(rate)) {
if (filter(rate)) {
actions.push({

@@ -55,3 +38,3 @@ id: numerics_1.BigNumber.from(id),

else if (amount.eq(rate.input)) {
if (!filter || filter(rate)) {
if (filter(rate)) {
actions.push({

@@ -65,4 +48,3 @@ id: numerics_1.BigNumber.from(id),

}
else {
// if (amount.lt(rate.input))
else /* if (amount.lt(rate.input)) */ {
const adjustedRate = {

@@ -72,3 +54,3 @@ input: amount,

};
if (!filter || filter(adjustedRate)) {
if (filter(adjustedRate)) {
actions.push({

@@ -86,9 +68,9 @@ id: numerics_1.BigNumber.from(id),

exports.match = match;
const matchBySourceAmount = (amount, orders, filter) => {
return (0, exports.match)(amount, orders, exports.getRateBySourceAmount, utils_1.cmpMin, filter);
const matchBySourceAmount = (amount, orders, filter = (_) => true) => {
return (0, exports.match)(amount, orders, filter, exports.getRateBySourceAmount, utils_1.cmpMin);
};
exports.matchBySourceAmount = matchBySourceAmount;
const matchByTargetAmount = (amount, orders, filter) => {
return (0, exports.match)(amount, orders, exports.getRateByTargetAmount, utils_1.cmpMax, filter);
const matchByTargetAmount = (amount, orders, filter = (_) => true) => {
return (0, exports.match)(amount, orders, filter, exports.getRateByTargetAmount, utils_1.cmpMax);
};
exports.matchByTargetAmount = matchByTargetAmount;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cmpMax = exports.cmpMin = exports.mulDivC = exports.mulDivF = void 0;
const mulDivF = (x, y, z) => x.mul(y).div(z);
exports.mulDivF = mulDivF;
const mulDivC = (x, y, z) => x.mul(y).add(z).sub(1).div(z);
exports.mulDivC = mulDivC;
exports.cmpMax = exports.cmpMin = void 0;
const cmpMin = (x, y) => {

@@ -9,0 +5,0 @@ const lhs = x.output.mul(y.input);

import { BigNumber } from '../numerics';
import { TradeActionStruct } from '../abis/types/PoolCollection';
import Contracts from './Contracts';
import { Overrides } from 'ethers';
import { Overrides, PayableOverrides } from 'ethers';
export default class Composer {
private _contracts;
constructor(contracts: Contracts);
trade(sourceToken: string, targetToken: string, tradeActions: TradeActionStruct[], tradeByTargetAmount: boolean, overrides?: Overrides): Promise<import("ethers").PopulatedTransaction>;
createStrategy(token0: string, token1: string, y0: BigNumber, z0: BigNumber, A0: BigNumber, B0: BigNumber, y1: BigNumber, z1: BigNumber, A1: BigNumber, B1: BigNumber, overrides?: Overrides): Promise<import("ethers").PopulatedTransaction>;
trade(sourceToken: string, targetToken: string, tradeActions: TradeActionStruct[], tradeByTargetAmount: boolean, overrides?: PayableOverrides): Promise<import("ethers").PopulatedTransaction>;
createStrategy(token0: string, token1: string, y0: BigNumber, z0: BigNumber, A0: BigNumber, B0: BigNumber, y1: BigNumber, z1: BigNumber, A1: BigNumber, B1: BigNumber, overrides?: PayableOverrides): Promise<import("ethers").PopulatedTransaction>;
transferVoucherOwnership(newOwner: string, overrides?: Overrides): Promise<import("ethers").PopulatedTransaction>;
}
//# sourceMappingURL=Composer.d.ts.map

@@ -1,5 +0,6 @@

import { Overrides, PopulatedTransaction } from '@ethersproject/contracts';
import { PopulatedTransaction } from '@ethersproject/contracts';
import { FriendlyAction, FriendlyStrategy, Rate, TokenPair } from './types';
import { BigNumber } from './numerics';
import { TradeActionStruct } from './abis/types/PoolCollection';
import { PayableOverrides } from 'ethers';
/**

@@ -134,3 +135,3 @@ * The Sdk class is the main entry point for interacting with the Carbon SDK. It provides methods for

*/
composeTradeTransaction(sourceToken: string, targetToken: string, tradeByTargetAmount: boolean, tradeActions: TradeActionStruct[], overrides?: Overrides): Promise<PopulatedTransaction>;
composeTradeTransaction(sourceToken: string, targetToken: string, tradeByTargetAmount: boolean, tradeActions: TradeActionStruct[], overrides?: PayableOverrides): Promise<PopulatedTransaction>;
/**

@@ -187,4 +188,4 @@ * Creates an unsigned transaction to create a strategy for buying and selling tokens of `baseToken` for price in `quoteToken` per 1 `baseToken`.

decimals: number;
}, buyPriceLow: string, buyPriceHigh: string, buyBudget: string, sellPriceLow: string, sellPriceHigh: string, sellBudget: string, overrides?: Overrides): Promise<PopulatedTransaction>;
}, buyPriceLow: string, buyPriceHigh: string, buyBudget: string, sellPriceLow: string, sellPriceHigh: string, sellBudget: string, overrides?: PayableOverrides): Promise<PopulatedTransaction>;
}
//# sourceMappingURL=index.d.ts.map

@@ -6,9 +6,7 @@ import { EncodedOrder, Rate, Action, Filter } from '../types';

};
export declare const getTradeTargetAmount: (x: BigNumber, order: EncodedOrder) => BigNumber;
export declare const getTradeSourceAmount: (x: BigNumber, order: EncodedOrder) => BigNumber;
export declare const getRateBySourceAmount: (sourceAmount: BigNumber, order: EncodedOrder) => Rate;
export declare const getRateByTargetAmount: (targetAmount: BigNumber, order: EncodedOrder) => Rate;
export declare const match: (amount: BigNumber, orders: OrdersMap, trade: (amount: BigNumber, order: EncodedOrder) => Rate, cmp: (x: Rate, y: Rate) => number, filter?: Filter) => Action[];
export declare const match: (amount: BigNumber, orders: OrdersMap, filter: Filter, trade: (amount: BigNumber, order: EncodedOrder) => Rate, cmp: (x: Rate, y: Rate) => number) => Action[];
export declare const matchBySourceAmount: (amount: BigNumber, orders: OrdersMap, filter?: Filter) => Action[];
export declare const matchByTargetAmount: (amount: BigNumber, orders: OrdersMap, filter?: Filter) => Action[];
//# sourceMappingURL=match.d.ts.map

@@ -1,7 +0,4 @@

import { BigNumber } from '../numerics';
import { Rate } from '../types';
export declare const mulDivF: (x: BigNumber, y: BigNumber, z: BigNumber) => BigNumber;
export declare const mulDivC: (x: BigNumber, y: BigNumber, z: BigNumber) => BigNumber;
export declare const cmpMin: (x: Rate, y: Rate) => number;
export declare const cmpMax: (x: Rate, y: Rate) => number;
//# sourceMappingURL=utils.d.ts.map
{
"name": "@bancor/carbon-sdk",
"version": "0.0.12-DEV",
"version": "0.0.13-DEV",
"description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades",

@@ -5,0 +5,0 @@ "types": "./lib/cjs/types/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc