Skip to content

Commit

Permalink
fix swap oraidex osmosis
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 committed Oct 15, 2024
1 parent da76c82 commit 236d83b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
13 changes: 12 additions & 1 deletion packages/universal-swap/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,18 @@ export class UniversalSwapHandler {
);

if (alphaSmartRoutes?.routes?.length && swapOptions.isAlphaIbcWasm) {
let receiverAddresses = UniversalSwapHelper.generateAddress({ oraiAddress, injAddress });
const addressParams = {
oraiAddress,
injAddress,
evmInfo:
!originalToToken.cosmosBased && evmAddress
? {
[originalToToken.chainId]: evmAddress
}
: {}
};

let receiverAddresses = UniversalSwapHelper.generateAddress(addressParams);
if (recipientAddress) receiverAddresses[currentToNetwork] = toAddress;

return this.alphaSmartRouterSwapNewMsg(swapRoute, universalSwapType, receiverAddresses);
Expand Down
25 changes: 18 additions & 7 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,23 +419,34 @@ export class UniversalSwapHelper {
}

/**
* useAlphaIbcWasm case: (evm -> oraichain -> osmosis -> inj/tia not using wasm)
* useAlphaIbcWasm case:
* evm -> oraichain -> osmosis -> inj/tia
* tia/inj -> osmosis -> oraichain -> evm
*/
if (swapOption.isAlphaIbcWasm && !fromToken.cosmosBased) {
if (swapOption.isAlphaIbcWasm) {
if (!alphaSmartRoute) throw generateError(`Missing router with alpha ibc wasm!`);
const routes = alphaSmartRoute.routes;
const alphaRoutes = routes[0];
let paths = alphaRoutes.paths;

if (alphaSmartRoute.routes.length > 1) throw generateError(`Missing router with alpha ibc wasm max length!`);
// if from is EVM only support one routes
if (!fromToken.cosmosBased && alphaSmartRoute.routes.length > 1) {
throw generateError(`Missing router with alpha ibc wasm max length!`);
}

const paths = alphaRoutes.paths.filter((_, index) => index > 0);
if (!fromToken.cosmosBased) {
paths = alphaRoutes.paths.filter((_, index) => index > 0);
}

let receiverAddresses = UniversalSwapHelper.generateAddress({
injAddress: addresses.injAddress,
oraiAddress: addresses.sourceReceiver,
evmInfo: {
[toToken.chainId]: addresses.evmAddress
}
evmInfo:
!toToken.cosmosBased && addresses.evmAddress
? {
[toToken.chainId]: addresses.evmAddress
}
: {}
});

if (addresses?.recipientAddress) receiverAddresses[toToken.chainId] = addresses?.recipientAddress;
Expand Down

0 comments on commit 236d83b

Please sign in to comment.