Skip to content

Commit

Permalink
Merge pull request #368 from oraidex/feat/build-memo-with-ton
Browse files Browse the repository at this point in the history
Feat/build memo with ton
  • Loading branch information
haunv3 authored Dec 11, 2024
2 parents 9c43bb4 + b7faa0c commit eb14329
Show file tree
Hide file tree
Showing 25 changed files with 1,426 additions and 364 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
"@cosmjs/stargate": "^0.32.4",
"@cosmjs/tendermint-rpc": "^0.32.4",
"@oraichain/common-contracts-build": "1.0.35",
"@oraichain/common-contracts-sdk": "1.0.31"
"@oraichain/common-contracts-sdk": "1.0.31",
"@oraichain/ton-bridge-contracts": "^0.15.9",
"@oraichain/tonbridge-sdk": "^1.4.2",
"@orbs-network/ton-access": "^2.3.3",
"@ton/core": "0.56.3",
"@ton/crypto": "3.3.0",
"@ton/ton": "14.0.0"
},
"devDependencies": {
"@babel/traverse": "7.24.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/oraidex-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-common",
"version": "1.1.39",
"version": "1.1.40",
"main": "build/index.js",
"files": [
"build/"
Expand Down
56 changes: 50 additions & 6 deletions packages/oraidex-common/src/alpha-network.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import {
ATOM_OSMOSIS_CONTRACT,
INJ_OSMOSIS_CONTRACT,
ORAI_OSMOSIS_CONTRACT,
TIA_OSMOSIS_CONTRACT,
TON_ALL_OSMOSIS_CONTRACT,
TON_OSMOSIS_CONTRACT,
USDC_OSMOSIS_CONTRACT
} from "./constant";
import { BridgeAppCurrency } from "./network";

export const AtomOsmosisToken: BridgeAppCurrency = {
coinDenom: "ATOM",
coinMinimalDenom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
coinMinimalDenom: ATOM_OSMOSIS_CONTRACT,
coinDecimals: 6,
coinGeckoId: "cosmos",
coinImageUrl: "https://dhj8dql1kzq2v.cloudfront.net/white/atom.png",
Expand All @@ -15,7 +24,7 @@ export const AtomOsmosisToken: BridgeAppCurrency = {

export const UsdcOsmosisToken: BridgeAppCurrency = {
coinDenom: "USDC",
coinMinimalDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
coinMinimalDenom: USDC_OSMOSIS_CONTRACT,
coinDecimals: 6,
coinGeckoId: "usd-coin",
coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png",
Expand All @@ -28,7 +37,7 @@ export const UsdcOsmosisToken: BridgeAppCurrency = {

export const OraiOsmosisToken: BridgeAppCurrency = {
coinDenom: "ORAI",
coinMinimalDenom: "ibc/161D7D62BAB3B9C39003334F1671208F43C06B643CC9EDBBE82B64793C857F1D",
coinMinimalDenom: ORAI_OSMOSIS_CONTRACT,
coinDecimals: 6,
coinGeckoId: "oraichain-token",
coinImageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/7533.png",
Expand All @@ -41,7 +50,7 @@ export const OraiOsmosisToken: BridgeAppCurrency = {

export const TiaOsmosisToken: BridgeAppCurrency = {
coinDenom: "TIA",
coinMinimalDenom: "ibc/D79E7D83AB399BFFF93433E54FAA480C191248FC556924A2A8351AE2638B3877",
coinMinimalDenom: TIA_OSMOSIS_CONTRACT,
coinDecimals: 6,
coinGeckoId: "celestia",
coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/celestia/images/celestia.png",
Expand All @@ -54,7 +63,7 @@ export const TiaOsmosisToken: BridgeAppCurrency = {

export const InjOsmosisToken: BridgeAppCurrency = {
coinDenom: "INJ",
coinMinimalDenom: "ibc/64BA6E31FE887D66C6F8F31C7B1A80C7CA179239677B4088BB55F5EA07DBE273",
coinMinimalDenom: INJ_OSMOSIS_CONTRACT,
coinDecimals: 18,
coinGeckoId: "injective-protocol",
coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/injective/images/inj.png",
Expand All @@ -65,4 +74,39 @@ export const InjOsmosisToken: BridgeAppCurrency = {
}
};

export const listOsmosisToken = [AtomOsmosisToken, OraiOsmosisToken, TiaOsmosisToken, InjOsmosisToken];
export const TonOsmosisToken: BridgeAppCurrency = {
coinDenom: "TON",
coinMinimalDenom: TON_ALL_OSMOSIS_CONTRACT,
coinDecimals: 9,
bridgeTo: ["ton", "Oraichain"],
coinGeckoId: "the-open-network",
coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ton/images/ton.png",
gasPriceStep: {
low: 0,
average: 0.025,
high: 0.04
}
};

export const TonOraiOsmosisToken: BridgeAppCurrency = {
coinDenom: "TON.orai",
coinMinimalDenom: TON_OSMOSIS_CONTRACT,
coinDecimals: 9,
bridgeTo: ["ton", "Oraichain"],
coinGeckoId: "the-open-network",
coinImageUrl: "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/ton/images/ton.png",
gasPriceStep: {
low: 0,
average: 0.025,
high: 0.04
}
};

export const listOsmosisToken = [
AtomOsmosisToken,
OraiOsmosisToken,
TiaOsmosisToken,
TonOsmosisToken,
TonOraiOsmosisToken,
InjOsmosisToken
];
38 changes: 38 additions & 0 deletions packages/oraidex-common/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@ export const WETH_CONTRACT = "orai1dqa52a7hxxuv8ghe7q5v0s36ra0cthea960q2cukznleq
export const BTC_CONTRACT = "orai10g6frpysmdgw5tdqke47als6f97aqmr8s3cljsvjce4n5enjftcqtamzsd";
export const OCH_CONTRACT = "orai1hn8w33cqvysun2aujk5sv33tku4pgcxhhnsxmvnkfvdxagcx0p8qa4l98q";

// config for Ton Token
export const TON20_USDT_CONTRACT = "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs";
export const HMSTR_TON_CONTRACT = "EQAJ8uWd7EBqsmpSWaRdf_I-8R8-XHwh3gsNKhy-UrdrPcUo";
export const jUSDC_TON_CONTRACT = "EQB-MPwrd1G6WKNkLz_VnV6WqBDd142KMQv-g1O-8QUA3728";
export const TON_CONTRACT = "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
export const TON_BRIDGE_ADAPTER = "EQC-aFP0rJXwTgKZQJPbPfTSpBFc8wxOgKHWD9cPvOl_DnaY";
export const TON_LIGHT_CLIENT = "EQDzy_POlimFDyzrHd3OQsb9sZCngyG3O7Za4GRFzM-rrO93";
export const TON_WHITE_LIST = "EQATDM6mfPZjPDMD9TVa6D9dlbmAKY5w6xOJiTXJ9Nqj_dsu";
/**
* TODO: This is the object containing the hardcoded addresses of cw20 TON Network. They are obtained from the formula below. We need to add more when we support new TON20.
* const client = await getTonClient();
* const jettonMinter = JettonMinter.createFromAddress(
* Address.parse(TON20 contractAddress) // exam: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs" => TON20_USDT_CONTRACT
* );
* const jettonMinterContract = client.open(jettonMinter);
* const jettonWalletAddress = await jettonMinterContract.getWalletAddress(
* Address.parse("orai159l8l9c5ckhqpuwdfgs9p4v599nqt3cjlfahalmtrhfuncnec2ms5mz60e")
* );
*/
export const JETTONS_ADDRESS = {
[TON_CONTRACT]: TON_CONTRACT,
[TON20_USDT_CONTRACT]: "EQANiP_ggkS0lJbR12xmDNT7hgqphdnVG0cCiJN6BN35Z498",
[HMSTR_TON_CONTRACT]: "EQC6hNI8R02lWfTV7wKXo9zueMoUP7ZBY4KZp5fkvN_Ad9Um",
[jUSDC_TON_CONTRACT]: "EQAacZPtQpnIHS1PlQgVaceb_I4v2HE3rvrZC91ynSRqXd9d"
};
export const TON_NATIVE_DENOM = "ton";

export const TON_BRIDGE_ADAPTER_ORAICHAIN = "orai159l8l9c5ckhqpuwdfgs9p4v599nqt3cjlfahalmtrhfuncnec2ms5mz60e";
export const TOKEN_FACTORY = "orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9";

// config for oraichain contract
export const FACTORY_CONTRACT = "orai1hemdkz4xx9kukgrunxu3yw0nvpyxf34v82d2c8";
export const FACTORY_V2_CONTRACT = "orai167r4ut7avvgpp3rlzksz6vw5spmykluzagvmj3ht845fjschwugqjsqhst";
Expand Down Expand Up @@ -180,6 +210,14 @@ export const BASE_API_URL = "https://api.oraidex.io";

// alpha smart router
export const OSMOSIS_ROUTER_CONTRACT = "osmo1h3jkejkcpthl45xrrm5geed3eq75p5rgfce9taufkwfr89k63muqweu2y7";
export const ATOM_OSMOSIS_CONTRACT = "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
export const USDC_OSMOSIS_CONTRACT = "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4";
export const ORAI_OSMOSIS_CONTRACT = "ibc/161D7D62BAB3B9C39003334F1671208F43C06B643CC9EDBBE82B64793C857F1D";
export const TIA_OSMOSIS_CONTRACT = "ibc/D79E7D83AB399BFFF93433E54FAA480C191248FC556924A2A8351AE2638B3877";
export const INJ_OSMOSIS_CONTRACT = "ibc/64BA6E31FE887D66C6F8F31C7B1A80C7CA179239677B4088BB55F5EA07DBE273";
export const TON_ALL_OSMOSIS_CONTRACT =
"factory/osmo12lnwf54yd30p6amzaged2atln8k0l32n7ncxf04ctg7u7ymnsy7qkqgsw4/alloyed/allTON";
export const TON_OSMOSIS_CONTRACT = "ibc/905889A7F0B94F1CE1506D9BADF13AE9141E4CBDBCD565E1DFC7AE418B3E3E98";

// websocket consts
export const WEBSOCKET_RECONNECT_ATTEMPTS = 5;
Expand Down
46 changes: 37 additions & 9 deletions packages/oraidex-common/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
MULTIPLIER,
CW20_DECIMALS
} from "./constant";
import { CoinGeckoId, NetworkChainId, cosmosChains } from "./network";
import { CoinGeckoId, NetworkChainId, cosmosChainIds, cosmosChains, evmChainIds, tonChainId } from "./network";
import {
AmountDetails,
TokenInfo,
Expand All @@ -34,6 +34,7 @@ import { StargateMsg, Tx } from "./tx";
import { BigDecimal } from "./bigdecimal";
import { TextProposal } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { defaultRegistryTypes as defaultStargateTypes, IndexedTx, logs, StargateClient } from "@cosmjs/stargate";
import { Address } from "@ton/core";

export const getEvmAddress = (bech32Address: string) => {
if (!bech32Address) throw new Error("bech32 address is empty");
Expand Down Expand Up @@ -572,19 +573,30 @@ export const validateEvmAddress = (address: string, network: string) => {
}
};

export const validateTronAddress = (address: string, network: string) => {
const isValidTronAddress = (address: string): boolean => /T[a-zA-Z0-9]{32}/.test(address);
const isValidTonAddress = (address: string): boolean => !!Address.parse(address);

export const validateAddressTonTron = (address: string, network: string) => {
try {
if (!/T[a-zA-Z0-9]{32}/.test(address)) {
throw new Error("Invalid tron address");
let isValid: boolean;
switch (network) {
case "0x2b6653dc":
isValid = isValidTronAddress(address);
break;
case "ton":
isValid = isValidTonAddress(address);
break;
default:
throw new Error("Unsupported network");
}

return {
isValid: true,
isValid,
network
};
} catch (error) {
return {
isValid: false
isValid: false,
error: error.message
};
}
};
Expand All @@ -595,11 +607,27 @@ export const checkValidateAddressWithNetwork = (address: string, network: Networ
case "0x38":
return validateEvmAddress(address, network);

// tron
// tron & ton
case "0x2b6653dc":
return validateTronAddress(address, network);
case "ton":
return validateAddressTonTron(address, network);

default:
return validateAndIdentifyCosmosAddress(address, network);
}
};

export const isCosmosChain = (chainId: string): boolean => {
const hasValue = cosmosChainIds.find((id) => id === chainId);
return Boolean(hasValue);
};

export const isEvmChain = (chainId: string): boolean => {
const hasValue = evmChainIds.find((id) => id === chainId);
return Boolean(hasValue);
};

export const isTonChain = (chainId: string): boolean => {
const hasValue = tonChainId.find((id) => id === chainId);
return Boolean(hasValue);
};
4 changes: 3 additions & 1 deletion packages/oraidex-common/src/interface/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ export enum ChainIdEnum {
BNBChainTestNet = "0x61",
TRON = "0x2b6653dc",
BitcoinTestnet = "bitcoinTestnet",
Bitcoin = "bitcoin"
Bitcoin = "bitcoin",
Ton = "ton",
TonTestnet = "ton_testnet"
}
Loading

0 comments on commit eb14329

Please sign in to comment.