-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
95 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
export const TONAPI_API_KEY = | ||
'Bearer AHSDXSKDRDYQSIYAAAAPKX74RH4QUUEZGUDSR4LJI3YA5HXWCXKC34236WTHJVNQCJTT53Q'; | ||
export const TONAPI_API_URL = 'https://tonapi.io/v2'; | ||
export const TONCENTER_API_V3_URL = 'https://toncenter.com/api/v3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...re/blockchain/web3-private-service/web3-private/ton-web3-private/ton-client/ton-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TonClient } from '@ton/ton'; | ||
|
||
export class TonClientInstance { | ||
private static instance: TonClient | null = null; | ||
|
||
private constructor() {} | ||
|
||
public static getInstance(): TonClient { | ||
if (!this.instance) { | ||
this.instance = new TonClient({ | ||
endpoint: 'https://x-api.rubic.exchange/toncenter/api/v2/jsonRPC', | ||
apiKey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' | ||
}); | ||
} | ||
|
||
return this.instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 38 additions & 38 deletions
76
...chain/calculation-manager/providers/aggregators/stonfi/services/stonfi-swap-service-v2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
import { DEX, pTON } from '@ston-fi/sdk'; | ||
import { TonClient } from '@ton/ton'; | ||
import { PriceTokenAmount } from 'src/common/tokens'; | ||
import { CHAIN_TYPE } from 'src/core/blockchain/models/chain-type'; | ||
import { TonEncodedConfig } from 'src/core/blockchain/web3-private-service/web3-private/ton-web3-private/models/ton-types'; | ||
import { Injector } from 'src/core/injector/injector'; | ||
import { TonClientInstance } from 'src/core/blockchain/web3-private-service/web3-private/ton-web3-private/ton-client/ton-client'; | ||
|
||
import { STONFI_REFERRAL_ADDRESS } from '../constants/addresses'; | ||
import { StonfiTxParamsProvider } from '../models/stonfi-abstract'; | ||
import { convertTxParamsToTonConfig } from '../utils/convert-params-to-ton-config'; | ||
|
||
export class StonfiSwapServiceV2 implements StonfiTxParamsProvider { | ||
private get tonClient(): TonClient { | ||
return ( | ||
Injector.web3PrivateService.getWeb3Private(CHAIN_TYPE.TON).tonClient || | ||
new TonClient({ | ||
endpoint: 'https://toncenter.com/api/v2/jsonRPC', | ||
apiKey: '44176ed3735504c6fb1ed3b91715ba5272cdd2bbb304f78d1ae6de6aed47d284' | ||
}) | ||
); | ||
return TonClientInstance.getInstance(); | ||
} | ||
|
||
private readonly stonfiRouter = this.tonClient.open( | ||
DEX.v2_1.Router.create('kQALh-JBBIKK7gr0o4AVf9JZnEsFndqO0qTCyT-D-yBsWk0v') | ||
); | ||
|
||
public async getTxParams( | ||
from: PriceTokenAmount, | ||
to: PriceTokenAmount, | ||
walletAddress: string, | ||
minAmountOutWei: string | ||
): Promise<TonEncodedConfig> { | ||
const stonfiRouter = this.tonClient.open( | ||
DEX.v2_2.Router.create('kQALh-JBBIKK7gr0o4AVf9JZnEsFndqO0qTCyT-D-yBsWk0v') | ||
); | ||
const proxyTon = pTON.v2_1.create('kQACS30DNoUQ7NfApPvzh7eBmSZ9L4ygJ-lkNWtba8TQT-Px'); | ||
|
||
if (from.isNative) { | ||
const txParams = await this.stonfiRouter.getSwapTonToJettonTxParams({ | ||
userWalletAddress: walletAddress, | ||
proxyTon, | ||
offerAmount: from.stringWeiAmount, | ||
askJettonAddress: to.address, | ||
minAskAmount: minAmountOutWei, | ||
referralAddress: STONFI_REFERRAL_ADDRESS | ||
}); | ||
try { | ||
if (from.isNative) { | ||
const txParams = await stonfiRouter.getSwapTonToJettonTxParams({ | ||
userWalletAddress: walletAddress, | ||
proxyTon, | ||
offerAmount: from.stringWeiAmount, | ||
askJettonAddress: to.address, | ||
minAskAmount: minAmountOutWei, | ||
referralValue: 100, | ||
referralAddress: STONFI_REFERRAL_ADDRESS | ||
}); | ||
|
||
return convertTxParamsToTonConfig(txParams); | ||
} | ||
return convertTxParamsToTonConfig(txParams); | ||
} | ||
|
||
if (to.isNative) { | ||
const txParams = await stonfiRouter.getSwapJettonToTonTxParams({ | ||
userWalletAddress: walletAddress, | ||
offerJettonAddress: from.address, | ||
offerAmount: from.stringWeiAmount, | ||
proxyTon, | ||
minAskAmount: minAmountOutWei, | ||
referralValue: 100, | ||
referralAddress: STONFI_REFERRAL_ADDRESS | ||
}); | ||
|
||
if (to.isNative) { | ||
const txParams = await this.stonfiRouter.getSwapJettonToTonTxParams({ | ||
return convertTxParamsToTonConfig(txParams); | ||
} | ||
|
||
const txParams = await stonfiRouter.getSwapJettonToJettonTxParams({ | ||
userWalletAddress: walletAddress, | ||
offerJettonAddress: from.address, | ||
offerAmount: from.stringWeiAmount, | ||
proxyTon, | ||
askJettonAddress: to.address, | ||
minAskAmount: minAmountOutWei, | ||
referralValue: 100, | ||
referralAddress: STONFI_REFERRAL_ADDRESS | ||
}); | ||
|
||
return convertTxParamsToTonConfig(txParams); | ||
} catch (err) { | ||
console.log('getTxParams_ERROR ==> ', err); | ||
throw err; | ||
} | ||
|
||
const txParams = await this.stonfiRouter.getSwapJettonToJettonTxParams({ | ||
userWalletAddress: walletAddress, | ||
offerJettonAddress: from.address, | ||
offerAmount: from.stringWeiAmount, | ||
askJettonAddress: to.address, | ||
minAskAmount: minAmountOutWei, | ||
referralAddress: STONFI_REFERRAL_ADDRESS | ||
}); | ||
|
||
return convertTxParamsToTonConfig(txParams); | ||
} | ||
} |
11 changes: 2 additions & 9 deletions
11
...on-chain/calculation-manager/providers/aggregators/stonfi/services/stonfi-swap-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2887,10 +2887,10 @@ | |
decamelize-keys "2.0.1" | ||
ofetch "1.3.4" | ||
|
||
"@ston-fi/[email protected].7": | ||
version "2.0.0-rc.7" | ||
resolved "https://registry.yarnpkg.com/@ston-fi/sdk/-/sdk-2.0.0-rc.7.tgz#479bfd6ebc00cb749d755c00b6c3c2d7199a784b" | ||
integrity sha512-5a04aX7FWq9Sm2/Ox2WayOpeoJ5VQH6Fnn/hiL8rW4wn7obwzAJgllnodwOQQNWw/z/Vb5BJHo2Ur5o7tymfXg== | ||
"@ston-fi/[email protected].8": | ||
version "2.0.0-rc.8" | ||
resolved "https://registry.yarnpkg.com/@ston-fi/sdk/-/sdk-2.0.0-rc.8.tgz#c6b7260dfe29c27ec5e63f88af84ac24a730accd" | ||
integrity sha512-9+9qBhdGzTVsC3iDHVQnrEFU7N7mdlGKbn57pHJrVfZiGm/55X5IPl4DKclbdtl9Gtjf9Kf8bBLweMEwzHntGw== | ||
|
||
"@supercharge/promise-pool@^2.1.0": | ||
version "2.4.0" | ||
|