Skip to content

Commit

Permalink
2615, add stonfi refferal, add multistep alert for dedust
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoElement committed Oct 1, 2024
1 parent 0b49c83 commit 5c2fcef
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "6.0.0-alpha.ton.103",
"version": "6.0.0-alpha.ton.105",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ export class DedustOnChainProvider extends AggregatorOnChainProvider {
weiAmount: new BigNumber(toStringWeiAmount)
});

const slippage = this.dedustSwapService.isMultistepSwap()
? 0.1
: options.slippageTolerance;

return new DedustOnChainTrade(
{
from,
to,
gasFeeInfo: await this.getGasFeeInfo(),
slippageTolerance: options.slippageTolerance,
slippageTolerance: slippage,
useProxy: false,
withDeflation: options.withDeflation,
path: this.getRoutePath(from, toToken),
usedForCrossChain: false
usedForCrossChain: false,
isMultistepSwap: this.dedustSwapService.isMultistepSwap()
},
options.providerAddress
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import { DedustOnChainTradeStruct } from './models/dedust-trade-types';
import { DedustSwapService } from './services/dedust-swap-service';

export class DedustOnChainTrade extends TonOnChainTrade<undefined> {
public type: OnChainTradeType = ON_CHAIN_TRADE_TYPE.DEDUST;
public readonly type: OnChainTradeType = ON_CHAIN_TRADE_TYPE.DEDUST;

public readonly isTonMultistepTrade: boolean;

private readonly dedustSwapService = new DedustSwapService();

constructor(tradeStruct: DedustOnChainTradeStruct, providerAddress: string) {
super(tradeStruct, providerAddress);
this.isTonMultistepTrade = tradeStruct.isMultistepSwap;
}

public async swap(options: SwapTransactionOptions = {}): Promise<string | never> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TonOnChainTradeStruct } from '../../../common/on-chain-trade/ton-on-chain-trade/models/ton-on-chian-trade-types';

export interface DedustOnChainTradeStruct extends TonOnChainTradeStruct {}
export interface DedustOnChainTradeStruct extends TonOnChainTradeStruct {
isMultistepSwap: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class DedustSwapService {
* @returns string wei amount
*/
public async calcOutputAmount(from: PriceTokenAmount, to: PriceToken): Promise<string> {
if (this.maybeMultihopSwap(from, to)) {
if (this.maybeMultistepSwap(from, to)) {
const pools = await DedustApiService.findBestPools(from, to);
if (!pools.length) {
throw new RubicSdkError(
Expand Down Expand Up @@ -113,6 +113,10 @@ export class DedustSwapService {
}
}

public isMultistepSwap(): boolean {
return this.txSteps.length > 1;
}

/**
* Stores found pools in calcOutputAmount method and reuses its in sendTransaction methods
*/
Expand All @@ -123,7 +127,7 @@ export class DedustSwapService {
/**
* maybe uses more than 1 pool
*/
private maybeMultihopSwap(from: Token, to: Token): boolean {
private maybeMultistepSwap(from: Token, to: Token): boolean {
return !from.isNative && !to.isNative;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { StonfiQuoteInfo, StonfiQuoteResponse } from '../models/stonfi-api-types
export class StonfiApiService {
private static readonly apiUrl = 'https://api.ston.fi/v1';

private static readonly rubicRefferalAddress =
'UQDCgZa4vgbHOIEYrbWTaD5pEmDN0opSfs3gQZ_dYOVzEsx1';

public static async makeQuoteRequest(
from: PriceTokenAmount,
to: PriceToken,
Expand All @@ -16,7 +19,13 @@ export class StonfiApiService {
const srcTokenAddress = from.isNative ? BOUNCEABLE_TON_NATIVE_ADDRESS : from.address;
const dstTokenAddress = to.isNative ? BOUNCEABLE_TON_NATIVE_ADDRESS : to.address;

const queryParams = `offer_address=${srcTokenAddress}&ask_address=${dstTokenAddress}&units=${from.stringWeiAmount}&slippage_tolerance=${slippage}`;
const queryParams = `offer_address=${srcTokenAddress}
&ask_address=${dstTokenAddress}
&units=${from.stringWeiAmount}
&slippage_tolerance=${slippage}
&referral_fee_bps=100
&referral_address=${this.rubicRefferalAddress}`;

const res = await Injector.httpClient.post<StonfiQuoteResponse>(
`${this.apiUrl}/swap/simulate?${queryParams}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StonfiApiService } from './services/stonfi-api-service';
import { StonfiSwapService } from './services/stonfi-swap-service';

export class StonfiOnChainTrade extends TonOnChainTrade<TonEncodedConfig> {
public type: OnChainTradeType = ON_CHAIN_TRADE_TYPE.STONFI;
public readonly type: OnChainTradeType = ON_CHAIN_TRADE_TYPE.STONFI;

private readonly stonfiSwapService = new StonfiSwapService();

Expand Down

0 comments on commit 5c2fcef

Please sign in to comment.