Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@bancor/carbon-sdk
Advanced tools
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 fulfi
This SDK is in beta. We cannot be held responsible for any losses caused by use of the SDK.
The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around the Carbon matching algorithm and Carbon contracts, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades
Use npm or yarn to install carbon-sdk.
yarn add @bancor/carbon-sdk
import {
PayableOverrides,
TradeActionBNStr,
TokenPair,
MatchActionBNStr,
StrategyUpdate,
EncodedStrategyBNStr,
} from '@bancor/carbon-sdk';
import { Toolkit } from '@bancor/carbon-sdk/strategy-management';
import { ChainCache, initSyncedCache } from '@bancor/carbon-sdk/chain-cache';
import {
ContractsApi,
ContractsConfig,
} from '@bancor/carbon-sdk/contracts-api';
let api: ContractsApi;
let sdkCache: ChainCache;
let carbonSDK: Toolkit;
let isInitialized = false;
let isInitializing = false;
const MAX_BLOCK_AGE = 2000; // past this many blocks, the SDK won't attempt to catch up by processing events and instead call the contracts for strategy info.
const init = async (
rpcUrl: string,
config: ContractsConfig,
decimalsMap?: Map<string, number>,
cachedData?: string
) => {
if (isInitialized || isInitializing) return;
isInitializing = true;
const provider = new StaticJsonRpcProvider(
{ url: rpcUrl, skipFetchSetup: true },
1
);
api = new ContractsApi(provider, config);
const { cache, startDataSync } = initSyncedCache(api.reader, cachedData, MAX_BLOCK_AGE);
sdkCache = cache;
carbonSDK = new Toolkit(
api,
sdkCache,
decimalsMap
? (address) => decimalsMap.get(address.toLowerCase())
: undefined
);
sdkCache.on('onPairDataChanged', (affectedPairs) =>
onPairDataChanged(affectedPairs)
);
sdkCache.on('onPairAddedToCache', (affectedPairs) =>
onPairAddedToCache(affectedPairs)
);
await startDataSync();
isInitialized = true;
isInitializing = false;
};
0
(default) only prints errors and important logs.1
(debug) prints highly verbose logs.2
(debug readable) is same as 1
but also converts any BigNumber to an easy to read string (impacting performance).To use it in Node, set the environment variable CARBON_DEFI_SDK_VERBOSITY
to the desired level.
To use it from a browser app do, before importing the SDK:
window.CARBON_DEFI_SDK_VERBOSITY = 2;
window.LEGACY_TRADE_BY_SOURCE_RANGE = true;
Pull requests are welcome!
For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
FAQs
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 fulfi
The npm package @bancor/carbon-sdk receives a total of 198 weekly downloads. As such, @bancor/carbon-sdk popularity was classified as not popular.
We found that @bancor/carbon-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.