rubic-sdk
Version:
Simplify dApp creation
58 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoffeeSwapApiService = void 0;
const injector_1 = require("../../../../../../../core/injector/injector");
class CoffeeSwapApiService {
static async fetchQuote(params) {
try {
const input_token = this.getCoffeeToken(params.srcToken);
const output_token = this.getCoffeeToken(params.dstToken);
const res = await injector_1.Injector.httpClient.post(`${this.apiUrl}/v1/route`, {
input_token,
output_token,
input_amount: params.srcToken.tokenAmount.toNumber(),
max_splits: 3,
max_length: 3,
pool_selector: {
blockchains: ['ton'],
dexes: ['stonfi', 'dedust'],
// restricts that liquidity wasn't changed more than 30%(with max_volatility 0.3) in last 15 minutes
max_volatility: 0.3
},
additional_data: {
sender_address: params.walletAddress,
referral_name: 'rubic'
}
});
return res;
}
catch (err) {
throw err;
}
}
static async fetchTonEncodedConfigs(walletAddress, slippage, paths) {
try {
const res = await injector_1.Injector.httpClient.post(`${this.apiUrl}/v2/route/transactions`, {
sender_address: walletAddress,
slippage,
referral_name: 'rubic',
paths
});
const tonConfigs = res.transactions.map(tx => ({
address: tx.address,
amount: tx.value,
payload: tx.cell
}));
return tonConfigs;
}
catch (err) {
throw err;
}
}
static getCoffeeToken(token) {
return { blockchain: 'ton', address: token.isNative ? 'native' : token.address };
}
}
exports.CoffeeSwapApiService = CoffeeSwapApiService;
CoffeeSwapApiService.apiUrl = 'https://backend.swap.coffee';
//# sourceMappingURL=coffee-swap-api-service.js.map