-
Notifications
You must be signed in to change notification settings - Fork 10
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
[WIP] Feat/universal swap ton #328
base: main
Are you sure you want to change the base?
Conversation
…x-sdk into feat/universal-swap-ton
…x-sdk into feat/universal-swap-ton
WalkthroughThis pull request introduces several changes across multiple packages, primarily focusing on integrating support for the TON blockchain. Key modifications include updates to build scripts, the addition of new dependencies, and enhancements to various functionalities related to token swaps. The Changes
Possibly related PRs
Poem
Tip Announcements
Recent review detailsConfiguration used: CodeRabbit UI Files ignored due to path filters (1)
Files selected for processing (14)
Files skipped from review due to trivial changes (3)
Additional context usedGitleaks
Biome
Additional comments not posted (38)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
Files selected for processing (14)
- package.json (2 hunks)
- packages/oraidex-common-ui/package.json (1 hunks)
- packages/oraidex-common/package.json (1 hunks)
- packages/oraidex-common/src/alpha-network.ts (1 hunks)
- packages/oraidex-common/src/constant.ts (2 hunks)
- packages/oraidex-common/src/interface/wallet.ts (1 hunks)
- packages/oraidex-common/src/network.ts (6 hunks)
- packages/universal-swap/package.json (1 hunks)
- packages/universal-swap/src/handler.ts (13 hunks)
- packages/universal-swap/src/helper.ts (10 hunks)
- packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts (1 hunks)
- packages/universal-swap/src/types.ts (4 hunks)
- packages/universal-swap/src/universal-demos/ton-to-others.ts (1 hunks)
- packages/universal-swap/tests/index.spec.ts (14 hunks)
Files skipped from review due to trivial changes (3)
- packages/oraidex-common-ui/package.json
- packages/oraidex-common/package.json
- packages/universal-swap/src/proto/universal-swap-memo-proto-handler.ts
Additional context used
Gitleaks
packages/oraidex-common/src/constant.ts
122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
Biome
packages/universal-swap/src/handler.ts
[error] 240-240: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 980-980: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 981-989: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 991-991: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 995-995: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
Additional comments not posted (38)
packages/oraidex-common/src/interface/wallet.ts (1)
20-22
: LGTM!The addition of
Ton
andTonTestnet
to theChainIdEnum
enumeration is a valid enhancement to support additional blockchain networks.packages/universal-swap/package.json (1)
10-10
: LGTM!The changes in the
package.json
file are approved:
- Using the same
tsconfig.json
for thebuild:test
script is a good practice to simplify the build process and reduce configuration overhead.- Updating the version of
@oraichain/oraidex-common
dependency to^1.1.3
is valid to leverage new features, bug fixes, or improvements.Also applies to: 14-14
packages/universal-swap/src/universal-demos/ton-to-others.ts (1)
1-64
: LGTM!The code in the
ton-to-others.ts
file is well-structured and follows a logical flow for demonstrating a swap from TON to other tokens. The necessary imports, dependencies, and parameters are properly set up, and theUniversalSwapHandler
is used to process the swap. Error handling is also implemented.The code is approved as is.
packages/oraidex-common/src/alpha-network.ts (2)
68-79
: LGTM!The code segment correctly defines the TON currency representation as a new constant
TonOsmosisToken
of typeBridgeAppCurrency
. The properties are populated with appropriate values. This addition enhances the functionality of the module by allowing it to handle transactions involving the TON currency.
81-81
: LGTM!The code segment correctly modifies the existing
listOsmosisToken
array to include the newly definedTonOsmosisToken
. This change is consistent with the addition of theTonOsmosisToken
constant and integrates the TON currency into the list of available tokens.package.json (2)
8-12
: Verify the impact of the changes on the testing workflow and build process.The changes to the
test
andbuild:test
scripts indicate a shift in the build process prior to running tests and a consolidation of the testing build process into the main build command.Please verify the following:
- Ensure that the main build process completes successfully before tests are executed.
- Confirm that the testing workflow and test results are not negatively impacted by these changes.
- Verify that the consolidation of the testing build process into the main build command does not introduce any unintended consequences or side effects.
33-35
: Verify the usage and impact of the new dependencies.The addition of
@oraichain/tonbridge-sdk
and@ton/crypto
dependencies indicates an expansion of the project's capabilities, potentially integrating new functionalities related to the TON blockchain and cryptography.Please verify the following:
- Ensure that the new dependencies are properly utilized and integrated into the codebase.
- Confirm that the inclusion of these dependencies does not introduce any compatibility issues or conflicts with existing dependencies.
- Verify that the new functionalities or features relying on these dependencies are thoroughly tested and documented.
packages/universal-swap/src/types.ts (5)
4-4
: LGTM!The import statement for
TonWallet
from@oraichain/tonbridge-sdk/build/wallet
is consistent with the addition of the@oraichain/tonbridge-sdk
dependency in thepackage.json
file. This import enables the usage of theTonWallet
type in the file, which is necessary for integrating TON blockchain functionality.
11-13
: LGTM!The addition of the string literals
"oraichain-to-ton"
and"ton-to-others"
to theUniversalSwapType
type expands the types of supported swaps to include transactions involving the TON blockchain. This change is consistent with the overall integration of TON blockchain functionality in the codebase.
36-36
: LGTM!The addition of the optional
ton
property of typestring
to theSender
interface allows for the specification of a TON wallet address alongside existing properties for other blockchain types. This change reflects an increased capability to handle transactions involving TON wallets and is consistent with the overall integration of TON blockchain functionality.
73-73
: LGTM!The addition of the optional
tonWallet
property of typeTonWallet
to theUniversalSwapConfig
interface indicates that the configuration can now accommodate a wallet specifically for TON transactions. This change enhances the flexibility and interoperability of the swap functionality across different blockchain networks and is consistent with the overall integration of TON blockchain functionality.
278-278
: LGTM!The correction of the typographical error in the
RouterConfigSmartRoute
interface, wheredontAllowSwapAfter
was misspelled asdontAlowSwapAfter
, improves the clarity and correctness of the code. This change does not affect the logic or functionality of the code.packages/oraidex-common/src/constant.ts (3)
24-25
: LGTM!The
MIN_TON_FOR_EXECUTE
constant is well-defined with a clear purpose explained in the comment.
118-123
: LGTM!The TON-related contract and configuration constants are well-defined and serve the purpose of supporting TON integration.
Tools
Gitleaks
122-122: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
126-127
: LGTM!The
TON_BRIDGE_ADAPTER_ORAICHAIN
andTOKEN_FACTORY
constants are correctly defined.Tools
Gitleaks
127-127: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
packages/oraidex-common/src/network.ts (7)
57-59
: LGTM!The import of
TON20_USDT_CONTRACT
andTON_CONTRACT
constants is correctly added to support TON integration.
75-76
: LGTM!The addition of "Ton" to the
NetworkName
type is correctly made to support TON integration.
94-94
: LGTM!The
TonChainId
type is correctly defined to represent the Ton network's chain ID.
96-96
: LGTM!The modification of the
NetworkChainId
type to incorporateTonChainId
is correctly made to support TON integration.
123-123
: LGTM!The modification of the
NetworkType
type to include "ton" is correctly made to support TON integration.
157-157
: LGTM!The modification of the
CoinType
type to include the value607
for the Ton network is correctly made to support TON integration.
514-563
: LGTM!The
tonNetworkMainnet
constant is correctly defined to represent the Ton network's mainnet configuration. It includes all the necessary properties and settings for the Ton network.packages/universal-swap/src/helper.ts (7)
50-51
: LGTM!The import of
TON_BRIDGE_ADAPTER_ORAICHAIN
constant is correctly added to support TON integration.
83-83
: LGTM!The import of
Memo_ContractCall
type is correctly added to support the new logic for contract calls.
242-248
: LGTM!The modification of the
routerConfig
parameter to use theRouterConfigSmartRoute
type is correctly made to support the new router configuration.
242-248
: LGTM!The new conditional logic in the
getRoute
method is correctly implemented to handle specific swap routes for TON integration. It correctly identifies the "oraichain-to-ton" and "ton-to-others" swap scenarios based on the chain IDs of the tokens involved.
346-350
: LGTM!The logging statements in the
getRoute
method are correctly added to aid in debugging and tracking the flow of data. They output the relevant swap route details, includingswapRoute
,universalSwapType
, andisSmartRouter
.
418-435
: LGTM!The modification of the memo construction for the universal swap is correctly implemented to support specific actions for the "ton" destination. The
postActionContractCall
variable is populated with the necessary contract call message details when the destination chain ID is "ton".
Line range hint
407-456
: LGTM!The refinement of post-action transfers handling is correctly implemented to accommodate the new logic for contract calls and IBC transfers. The
postActionIbcWasmTransfer
,postActionIbcTransfer
, andpostActionTransfer
variables are defined based on the appropriate conditions and destination chain ID.packages/universal-swap/src/handler.ts (7)
46-50
: LGTM!The additions of TON-related imports are necessary for integrating TON functionalities.
54-55
: LGTM!The imports of
TonbridgeBridgeClient
andTonBridgeHandler
are necessary to facilitate the transfer of assets to the TON network.
71-74
: LGTM!The additions of TON-specific imports and
buildUniversalSwapMemo
are necessary for handling TON operations and building the universal swap memo.
103-108
: LGTM!The modifications to the
getUniversalSwapToAddress
method enhance its capability to handle TON addresses for swaps to the TON network.
1120-1180
: LGTM!The addition of the
swapTonToOtherNetwork
method enhances the functionality of theUniversalSwapHandler
by enabling swaps from TON to other networks. The method ensures the availability of necessary wallet addresses, handles swap route creation, and incorporates error handling and minimum receive amount calculation.
Line range hint
1274-1291
: LGTM!The destructuring of
ton
fromthis.swapData.sender
allows theprocessUniversalSwap
method to access the TON sender address from the swap data.
1325-1331
: LGTM!The addition of the
"ton-to-others"
case in theprocessUniversalSwap
method enables handling swaps from TON to other networks by invoking theswapTonToOtherNetwork
method.packages/universal-swap/tests/index.spec.ts (2)
312-313
: Verify the impact of usingtoDisplay
forfromAmount
.The change in setting the
fromAmount
property using thetoDisplay
function suggests a shift in how the value is represented.Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that the
toDisplay
function is the appropriate choice for representing thefromAmount
value and that it aligns with the expected data type and format used throughout the system.
421-422
: Verify the impact of settingminimum_receive
to a string "0".The change in setting the
minimum_receive
property to a string "0" instead of the variableminimumReceive
suggests a shift in how the value is represented.Ensure that this change is thoroughly tested and validated to confirm that it does not introduce any unintended consequences or inconsistencies in the codebase. Verify that using a hardcoded string "0" is the appropriate choice for representing the
minimum_receive
value and that it aligns with the expected data type and format used throughout the system.
case "oraichain-to-ton": | ||
if (!this.config.tonWallet) | ||
throw generateError("Cannot transfer and swap if the ton wallet is not initialized"); | ||
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN); | ||
const handler = await TonBridgeHandler.create({ | ||
wasmBridge, | ||
tonBridge: TON_BRIDGE_ADAPTER, | ||
tonSender: this.config.tonWallet.sender, | ||
tonClientParameters: { | ||
endpoint: "https://toncenter.com/api/v2/jsonRPC" | ||
// apiKey: process.env.TON_API_KEY | ||
} | ||
}); | ||
|
||
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString(); | ||
if (!tonReceiveAddress) throw generateError("Please login ton wallet!"); | ||
|
||
// TODO: need check TON_CONTRACT or Address of Token In Token | ||
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT); | ||
|
||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but fix the switch declaration issue.
The addition of the new case to handle swaps from Oraichain to TON is approved.
However, the declarations inside the switch case can be erroneously accessed by other cases.
Wrap the declarations (wasmBridge
, handler
, tonReceiveAddress
, and result
) inside the switch case in a block to restrict their access:
case "oraichain-to-ton":
+ {
if (!this.config.tonWallet)
throw generateError("Cannot transfer and swap if the ton wallet is not initialized");
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN);
const handler = await TonBridgeHandler.create({
wasmBridge,
tonBridge: TON_BRIDGE_ADAPTER,
tonSender: this.config.tonWallet.sender,
tonClientParameters: {
endpoint: "https://toncenter.com/api/v2/jsonRPC"
// apiKey: process.env.TON_API_KEY
}
});
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString();
if (!tonReceiveAddress) throw generateError("Please login ton wallet!");
// TODO: need check TON_CONTRACT or Address of Token In Token
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT);
return result;
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
case "oraichain-to-ton": | |
if (!this.config.tonWallet) | |
throw generateError("Cannot transfer and swap if the ton wallet is not initialized"); | |
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN); | |
const handler = await TonBridgeHandler.create({ | |
wasmBridge, | |
tonBridge: TON_BRIDGE_ADAPTER, | |
tonSender: this.config.tonWallet.sender, | |
tonClientParameters: { | |
endpoint: "https://toncenter.com/api/v2/jsonRPC" | |
// apiKey: process.env.TON_API_KEY | |
} | |
}); | |
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString(); | |
if (!tonReceiveAddress) throw generateError("Please login ton wallet!"); | |
// TODO: need check TON_CONTRACT or Address of Token In Token | |
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT); | |
return result; | |
case "oraichain-to-ton": | |
{ | |
if (!this.config.tonWallet) | |
throw generateError("Cannot transfer and swap if the ton wallet is not initialized"); | |
const wasmBridge = new TonbridgeBridgeClient(client, oraiAddress, TON_BRIDGE_ADAPTER_ORAICHAIN); | |
const handler = await TonBridgeHandler.create({ | |
wasmBridge, | |
tonBridge: TON_BRIDGE_ADAPTER, | |
tonSender: this.config.tonWallet.sender, | |
tonClientParameters: { | |
endpoint: "https://toncenter.com/api/v2/jsonRPC" | |
// apiKey: process.env.TON_API_KEY | |
} | |
}); | |
const tonReceiveAddress = await this.config.tonWallet.sender.address.toString(); | |
if (!tonReceiveAddress) throw generateError("Please login ton wallet!"); | |
// TODO: need check TON_CONTRACT or Address of Token In Token | |
const result = await handler.sendToTon(tonReceiveAddress, toNano(3), TON_CONTRACT); | |
return result; | |
} |
Tools
Biome
[error] 980-980: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 981-989: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 991-991: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
[error] 995-995: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.The declaration is defined in this switch clause:
Unsafe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
Summary by CodeRabbit
New Features
Bug Fixes
minimum_receive
values and inclusion ofaffiliates
property.Documentation
buildUniversalSwapMemo
function.Chores