Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat stonfi and ton #396

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"repository": "https://github.com/hummingbot/gateway",
"scripts": {
"prebuild": "rimraf dist && mkdir dist",
"build": "tsc --skipLibCheck --project ./ && yarn copy-files",
"build": "tsc --skipLibCheck --noEmitOnError false --project ./ && yarn copy-files",
"clean": "rm -rf ./node_modules && rm -rf ./coverage && rm -rf ./logs && yarn run clean:config",
"clean:config": "find ./conf -maxdepth 1 -regextype posix-extended -regex '.*.*' -delete",
"format": "prettier . --write",
Expand All @@ -26,6 +26,7 @@
"@_etcswap/smart-order-router": "^3.15.2",
"@balancer-labs/sdk": "^1.1.5",
"@bancor/carbon-sdk": "^0.0.93-DEV",
"@coral-xyz/anchor": "^0.29.0",
"@cosmjs/amino": "^0.32.2",
"@cosmjs/cosmwasm-stargate": "^0.31.1",
"@cosmjs/proto-signing": "^0.31.1",
Expand All @@ -42,6 +43,8 @@
"@harmony-js/utils": "^0.1.56",
"@improbable-eng/grpc-web": "^0.13.0",
"@injectivelabs/sdk-ts": "^1.10.58",
"@jup-ag/api": "^6.0.29",
"@orbs-network/ton-access": "^2.3.3",
"@osmonauts/math": "^1.11.3",
"@pancakeswap/sdk": "^4.0.0",
"@pancakeswap/smart-router": "^4.2.1",
Expand All @@ -51,17 +54,22 @@
"@pancakeswap/v3-periphery": "^1.0.2",
"@pancakeswap/v3-sdk": "^3.7.0",
"@pangolindex/sdk": "^1.1.0",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.95.8",
"@solana/spl-token": "0.4.8",
"@solana/spl-token-registry": "^0.2.4574",
"@solana/web3.js": "^1.95.8",
"@solflare-wallet/utl-sdk": "^1.4.0",
"@jup-ag/api": "^6.0.29",
"@ston-fi/api": "^0.14.0",
"@ston-fi/omniston-sdk": "^0.3.0",
"@ston-fi/sdk": "^2.1.0",
"@sushiswap/sdk": "^5.0.0-canary.116",
"@taquito/rpc": "^17.0.0",
"@taquito/signer": "^17.0.0",
"@taquito/taquito": "^17.0.0",
"@tinymanorg/tinyman-js-sdk": "^3.0.0",
"@ton-api/client": "^0.3.0",
"@ton/core": "^0.59.0",
"@ton/crypto": "^3.3.0",
"@ton/ton": "^15.1.0",
"@traderjoe-xyz/sdk-v2": "^2.0.5",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.178",
Expand Down Expand Up @@ -107,6 +115,7 @@
"quickswap-sdk": "^3.0.8",
"swagger-ui-express": "^4.1.6",
"swap-router-sdk": "^1.21.1",
"tonweb": "^0.0.66",
"tslib": "^2.3.1",
"uuid": "^8.3.2",
"vvs-sdk": "^2.4.0",
Expand Down Expand Up @@ -170,6 +179,7 @@
"viem": "^0.3.x"
},
"resolutions": {
"web3-utils": "1.7.3"
"web3-utils": "1.7.3",
"@ston-fi/api/web3-utils": "1.8.2"
}
}
}
38 changes: 27 additions & 11 deletions src/amm/amm.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import {
trade as tinymanTrade,
estimateGas as tinymanEstimateGas,
} from '../connectors/tinyman/tinyman.controllers';
import {
price as stonfiPrice,
trade as stonfiTrade,
estimateGas as stonfiEstimateGas,
} from '../connectors/ston_fi/ston_fi.controllers';

import {
price as plentyPrice,
trade as plentyTrade,
Expand All @@ -63,17 +69,21 @@ import { Osmosis } from '../chains/osmosis/osmosis';
import { Solana } from '../chains/solana/solana';
import { Jupiter } from '../connectors/jupiter/jupiter';
import { Carbonamm } from '../connectors/carbon/carbonAMM';
import { Ton } from '../chains/ton/ton';
import { Stonfi } from '../connectors/ston_fi/ston_fi';

export async function price(req: PriceRequest): Promise<PriceResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Tezosish | Osmosis | Solana
Algorand | Ethereumish | Tezosish | Osmosis | Solana | Ton
>(req.chain, req.network);


if (chain instanceof Osmosis){
return chain.controller.price(chain as unknown as Osmosis, req);
}

const connector: Uniswapish | Tinyman | Plenty =
await getConnector<Uniswapish | Tinyman | Plenty>(
const connector: Uniswapish | Tinyman | Plenty | Stonfi =
await getConnector<Uniswapish | Tinyman | Plenty | Stonfi >(
req.chain,
req.network,
req.connector
Expand All @@ -88,20 +98,22 @@ export async function price(req: PriceRequest): Promise<PriceResponse> {
} else if ('routerAbi' in connector) {
// we currently use the presence of routerAbi to distinguish Uniswapish from RefAMMish
return uniswapPrice(<Ethereumish>chain, connector, req);
} else return tinymanPrice(chain as unknown as Algorand, connector, req);
} else if (connector instanceof Stonfi) {
return stonfiPrice(chain as unknown as Ton, connector, req);

} else return tinymanPrice(chain as unknown as Algorand, connector, req);
}

export async function trade(req: TradeRequest): Promise<TradeResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Tezosish | Osmosis | Solana
Algorand | Ethereumish | Tezosish | Osmosis | Solana | Ton
>(req.chain, req.network);
if (chain instanceof Osmosis){
return chain.controller.trade(chain as unknown as Osmosis, req);
}

const connector: Uniswapish | Tinyman | Plenty =
await getConnector<Uniswapish | Tinyman | Plenty>(
const connector: Uniswapish | Tinyman | Plenty | Stonfi =
await getConnector<Uniswapish | Tinyman | Plenty | Stonfi >(
req.chain,
req.network,
req.connector
Expand All @@ -115,6 +127,8 @@ export async function trade(req: TradeRequest): Promise<TradeResponse> {
return carbonTrade(<Ethereumish>chain, connector, req);
} else if ('routerAbi' in connector) {
return uniswapTrade(<Ethereumish>chain, connector, req);
} else if (connector instanceof Stonfi) {
return stonfiTrade(<Ton>chain, connector, req);
} else {
return tinymanTrade(chain as unknown as Algorand, connector, req);
}
Expand Down Expand Up @@ -201,14 +215,14 @@ export async function estimateGas(
req: NetworkSelectionRequest
): Promise<EstimateGasResponse> {
const chain = await getInitializedChain<
Algorand | Ethereumish | Tezosish | Osmosis | Solana
Algorand | Ethereumish | Tezosish | Osmosis | Solana | Ton
>(req.chain, req.network);
if (chain instanceof Osmosis){
return chain.controller.estimateGas(chain as unknown as Osmosis);
}
const connector: Uniswapish | Tinyman | Plenty | Jupiter =
await getConnector<Uniswapish | Tinyman | Plenty | Jupiter>(

const connector: Uniswapish | Tinyman | Plenty | Jupiter | Stonfi =
await getConnector<Uniswapish | Tinyman | Plenty | Jupiter | Stonfi >(
req.chain,
req.network,
req.connector
Expand All @@ -222,6 +236,8 @@ export async function estimateGas(
return carbonEstimateGas(<Ethereumish>chain, connector);
} else if ('routerAbi' in connector) {
return uniswapEstimateGas(<Ethereumish>chain, connector);
} else if (connector instanceof Stonfi) {
return stonfiEstimateGas(<Ton>chain, connector);
} else {
return tinymanEstimateGas(chain as unknown as Algorand, connector);
}
Expand Down
18 changes: 9 additions & 9 deletions src/chains/chain.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {

export async function poll(
chain: Chain,
req: PollRequest
req: PollRequest,
): Promise<PollResponse> {
const initTime = Date.now();
const poll = await chain.controller.poll(chain, req);
Expand All @@ -42,7 +42,7 @@ export async function poll(

export async function nonce(
chain: Chain,
req: NonceRequest
req: NonceRequest,
): Promise<NonceResponse> {
const initTime = Date.now();
const nonce = await chain.controller.nonce(chain, req);
Expand All @@ -56,7 +56,7 @@ export async function nonce(

export async function nextNonce(
chain: Chain,
req: NonceRequest
req: NonceRequest,
): Promise<NonceResponse> {
const initTime = Date.now();
const nextNonce = await chain.controller.nextNonce(chain, req);
Expand All @@ -70,7 +70,7 @@ export async function nextNonce(

export async function getTokens(
chain: Chain,
req: TokensRequest
req: TokensRequest,
): Promise<TokensResponse> {
const initTime = Date.now();
const tokens = await chain.controller.getTokens(chain, req);
Expand All @@ -84,7 +84,7 @@ export async function getTokens(

export async function allowances(
chain: Chain,
req: AllowancesRequest
req: AllowancesRequest,
): Promise<AllowancesResponse | string> {
const initTime = Date.now();
const allowances = await chain.controller.allowances(chain, req);
Expand All @@ -99,7 +99,7 @@ export async function allowances(

export async function balances(
chain: Chain,
req: BalanceRequest
req: BalanceRequest,
): Promise<BalanceResponse | string> {
const initTime = Date.now();
const balances = await chain.controller.balances(chain, req);
Expand All @@ -114,7 +114,7 @@ export async function balances(

export async function approve(
chain: Chain,
req: ApproveRequest
req: ApproveRequest,
): Promise<ApproveResponse | string> {
const initTime = Date.now();
const approveTx = await chain.controller.approve(chain, req);
Expand All @@ -129,7 +129,7 @@ export async function approve(

export async function cancel(
chain: Chain,
req: CancelRequest
req: CancelRequest,
): Promise<CancelResponse> {
const initTime = Date.now();
const cancelTx = await chain.controller.cancel(chain, req);
Expand All @@ -144,7 +144,7 @@ export async function cancel(

export async function transfer(
chain: Chain,
req: TransferRequest
req: TransferRequest,
): Promise<TransferResponse> {
const initTime = Date.now();
const transfer = await chain.controller.transfer(chain, req);
Expand Down
91 changes: 91 additions & 0 deletions src/chains/ton/ton.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { ConfigManagerV2 } from '../../services/config-manager-v2';

export interface NetworkConfig {
name: string;
nodeURL: string;
assetListType: string;
assetListSource: string;
maxLRUCacheInstances: number;
scanUrl: string;
}

export interface Config {
network: NetworkConfig;
nativeCurrencySymbol: string;
defaultMaxNumberOfRetries: number;
defaultDelayBetweenRetries: number;
defaultTimeout: number;
defaultBatchSize: number;
defaultDelayBetweenBatches: number;
defaultPollInterval: number;
defaultMaxPollAttempts: number;
gasPrice: number;
gasLimit: number;
gasCost: number;
workchain: number;
apiKey: string;
rpcType: string;
availableWalletVersions: string[];
walletVersion: string;
}

export function getTonConfig(network: string): Config {
return {
network: {
name: network,
nodeURL: ConfigManagerV2.getInstance().get(
'ton.networks.' + network + '.nodeURL',
),
scanUrl:
network == 'mainnet'
? 'https://tonscan.org'
: 'https://testnet.tonscan.org',
assetListType: ConfigManagerV2.getInstance().get(
'ton.networks.' + network + '.assetListType',
),
assetListSource: ConfigManagerV2.getInstance().get(
'ton.networks.' + network + '.assetListSource',
),
maxLRUCacheInstances: 10,
},
nativeCurrencySymbol: ConfigManagerV2.getInstance().get(
'ton.nativeCurrencySymbol',
),
defaultMaxNumberOfRetries:
ConfigManagerV2.getInstance().get('ton.defaultMaxNumberOfRetries') || 3,
defaultDelayBetweenRetries:
ConfigManagerV2.getInstance().get(
'ton.defaultDelayDelayBetweenRetries',
) || 5,
defaultTimeout:
ConfigManagerV2.getInstance().get('ton.defaultTimeout') || 60,
defaultBatchSize:
ConfigManagerV2.getInstance().get('ton.defaultBatchSize') || 100,
defaultDelayBetweenBatches:
ConfigManagerV2.getInstance().get('ton.defaultDelayBetweenBatches') || 5,
defaultPollInterval:
ConfigManagerV2.getInstance().get('ton.defaultPollInterval') || 2000,
defaultMaxPollAttempts:
ConfigManagerV2.getInstance().get('ton.defaultMaxPollAttempts') || 30,
gasPrice: ConfigManagerV2.getInstance().get('ton.gasPrice') || 0,
gasLimit: ConfigManagerV2.getInstance().get('ton.gasLimit') || 0,
gasCost: ConfigManagerV2.getInstance().get('ton.gasCost') || 1,
workchain: ConfigManagerV2.getInstance().get('ton.workchain') || 0,
apiKey: ConfigManagerV2.getInstance().get('ton.apiKey') || 0,
rpcType: ConfigManagerV2.getInstance().get('ton.rpcType') || 0,
availableWalletVersions: [
'v1r1',
'v1r2',
'v1r3',
'v2r1',
'v2r2',
'v3r1',
'v3r2',
'v4',
'v5R1',
'v5Beta',
],
walletVersion:
ConfigManagerV2.getInstance().get('ton.walletVersion') || null,
};
}
Loading