To create SDK instance you should provide config parameter, this is an object containing the rpc, wallets, http client settings, and your personal integrator wallet address.
RpcProviders is Rpc data to connect to blockchains you will use. You have to pass rpcProvider for each blockchain you will use with sdk, as presented in example below:
type RpcProviders = Partial<
Record<EvmBlockchainName, RpcProvider<string>> &
Record<TronBlockchainName, RpcProvider<TronWebProvider>> &
Record<SolanaBlockchainName, RpcProvider<string>>
>;
interface RpcProvider<T> {
/**
* Rpc links. Copy it from your rpc provider website
* (like Infura, Quicknode, Getblock, Moralis, etc).
*/
readonly rpcList: T[];
}
Providing wallet options
If at the time when you initiating SDK, users have already logged into your platform, you can provide walletProvider object, but it is no necessary, until you want to swap with SDK:
You can also pass your own http client as httpClient parameter (e.g. HttpClient in Angular) if you have it, to not duplicate http clients and decrease bundle size.
Your wallet address as integrator
This is one of the most important steps, please send to the Rubic team the providerAddress - the wallet address to which the fees will be credited. To make it work properly, you need to contact us so that we can whitelist you.
Update SDK configuration
When user finally connects the walet, you have to notify SDK about it.
You should do it on every address and network change events
SDK object
When SDK was initiated, you are able to refer it's fields and methods.
interface SDK {
/**
* On-chain manager object. Use it to calculate and create on-chain trades.
*/
public readonly onChainManager: OnChainManager;
/**
* Cross-chain trades manager object. Use it to calculate and create cross-chain trades.
*/
public readonly crossChainManager: CrossChainManager;
/**
* On-chain status manager object. Use it for special providers, which requires more than one trade.
*/
public readonly onChainStatusManager: OnChainStatusManager;
/**
* Cross-chain status manager object. Use it to get trade statuses on source and target network.
*/
public readonly crossChainStatusManager: CrossChainStatusManager;
/**
* Cross-chain symbiosis manager object. Use it to get pending trades in symbiosis and revert them.
*/
public readonly crossChainSymbiosisManager: CrossChainSymbiosisManager;
/**
* Deflation token manager object. Use it to check specific token for fees or deflation.
*/
public readonly deflationTokenManager: DeflationTokenManager;
/**
* Use it to create limit order.
*/
public readonly limitOrderManager: LimitOrderManager;
/**
* Can be used to get `Web3Public` instance by blockchain name to get public information from blockchain.
*/
public get web3PublicService(): Web3PublicService {
return Injector.web3PublicService;
}
/**
* Can be used to send transactions and execute smart contracts methods.
*/
public get web3PrivateService(): Web3PrivateService {
return Injector.web3PrivateService;
}
/**
* Use it to get gas price information.
*/
public get gasPriceApi(): GasPriceApi {
return Injector.gasPriceApi;
}
/**
* Use it to get coingecko price information.
*/
public get coingeckoApi(): CoingeckoApi {
return Injector.coingeckoApi;
}
/**
* Updates sdk configuration and sdk entities dependencies.
*/
public async updateConfiguration(configuration: Configuration): Promise<void> {
const [web3PublicService, web3PrivateService, httpClient] = await Promise.all([
SDK.createWeb3PublicService(configuration),
SDK.createWeb3PrivateService(configuration),
SDK.createHttpClient(configuration)
]);
Injector.createInjector(web3PublicService, web3PrivateService, httpClient);
}
public updateWalletProvider(walletProvider: WalletProvider): void {
Injector.web3PrivateService.updateWeb3PrivateStorage(walletProvider);
}
public updateWalletProviderCore(
chainType: keyof WalletProvider,
walletProviderCore: WalletProviderCore
): void {
Injector.web3PrivateService.updateWeb3Private(chainType, walletProviderCore);
}
public updateWalletAddress(chainType: keyof WalletProvider, address: string): void {
Injector.web3PrivateService.updateWeb3PrivateAddress(chainType, address);
}
}