Skip to content

Commit

Permalink
Merge pull request #348 from oraichain/feat/support-swap-oraidex-osmosis
Browse files Browse the repository at this point in the history
Feat/support swap oraidex osmosis
  • Loading branch information
trung2891 authored Oct 10, 2024
2 parents 2f20b38 + 50df241 commit 09c7db1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/universal-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-universal-swap",
"version": "1.1.13",
"version": "1.1.14",
"main": "build/index.js",
"files": [
"build/"
Expand Down
1 change: 0 additions & 1 deletion packages/universal-swap/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ export class UniversalSwapHandler {
originalAmount: toDisplay(subRelayerFee),
routerClient: routerClient,
routerOption: {
useAlphaSmartRoute: true,
useIbcWasm: true
},
routerConfig: {
Expand Down
15 changes: 5 additions & 10 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ export class UniversalSwapHelper {
maxSplits: routerConfig.maxSplits,
swapConfig: {
dontAlowSwapAfter: routerConfig.dontAllowSwapAfter
}
},
ignoreFee: routerConfig.ignoreFee
}
};
const res: {
Expand All @@ -648,13 +649,7 @@ export class UniversalSwapHelper {
askInfo: AssetInfo,
askChainId: string,
offerAmount: string,
routerConfig: RouterConfigSmartRoute = {
url: "https://osor.oraidex.io",
path: "/smart-router",
protocols: ["Oraidex", "OraidexV3"],
dontAllowSwapAfter: ["Oraidex", "OraidexV3"],
maxSplits: 10
}
routerConfig: RouterConfigSmartRoute
): Promise<SmartRouterResponse> => {
const { returnAmount, routes } = await UniversalSwapHelper.querySmartRoute(
offerInfo,
Expand Down Expand Up @@ -800,7 +795,6 @@ export class UniversalSwapHelper {
originalAmount: number;
routerClient: OraiswapRouterReadOnlyInterface;
routerOption?: {
useAlphaSmartRoute?: boolean;
useIbcWasm?: boolean;
useAlphaIbcWasm?: boolean;
};
Expand Down Expand Up @@ -832,7 +826,8 @@ export class UniversalSwapHelper {
path: query?.routerConfig?.path ?? "/smart-router/alpha-router",
protocols: query?.routerConfig?.protocols ?? ["Oraidex", "OraidexV3"],
dontAllowSwapAfter: query?.routerConfig?.dontAllowSwapAfter ?? ["Oraidex", "OraidexV3"],
maxSplits: query?.routerConfig?.maxSplits ?? 10
maxSplits: query?.routerConfig?.maxSplits ?? 10,
ignoreFee: query?.routerConfig?.ignoreFee ?? false
};

let fromInfo = getTokenOnOraichain(query.originalFromInfo.coinGeckoId);
Expand Down
14 changes: 12 additions & 2 deletions packages/universal-swap/src/msg/msgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const buildMemoSwap = (
switch (currentChain) {
case "Oraichain": {
let prefix = getDestPrefixForBridgeToEvmOnOrai(path.tokenOutChainId);
let oBridgeAddress = addresses["oraibridge-subnet-2"];
const ORAIBRIDGE_SUBNET = "oraibridge-subnet-2";
let oBridgeAddress = addresses[ORAIBRIDGE_SUBNET];
if (!oBridgeAddress) {
throw generateError(`Missing oBridge address for ${ORAIBRIDGE_SUBNET}`);
}

let oraichainMsg = new OraichainMsg(path, "1", receiver, currentAddress, memo, prefix, oBridgeAddress);
oraichainMsg.setMinimumReceiveForSwap(slippage);
// we have 2 cases:
Expand Down Expand Up @@ -82,7 +87,12 @@ const buildExecuteMsg = (
switch (currentChain) {
case "Oraichain": {
let prefix = getDestPrefixForBridgeToEvmOnOrai(path.tokenOutChainId);
let oBridgeAddress = addresses["oraibridge-subnet-2"];
const ORAIBRIDGE_SUBNET = "oraibridge-subnet-2";
let oBridgeAddress = addresses[ORAIBRIDGE_SUBNET];
if (!oBridgeAddress) {
throw generateError(`Missing oBridge address for ${ORAIBRIDGE_SUBNET}`);
}

let oraichainMsg = new OraichainMsg(path, "1", receiver, currentAddress, memo, prefix, oBridgeAddress);
oraichainMsg.setMinimumReceiveForSwap(slippage);
return oraichainMsg.genExecuteMsg();
Expand Down
1 change: 1 addition & 0 deletions packages/universal-swap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,5 @@ export interface RouterConfigSmartRoute {
protocols?: string[];
dontAllowSwapAfter?: string[];
maxSplits?: number;
ignoreFee?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const simulate = async () => {
originalAmount: fromAmount,
routerClient: "" as any,
routerOption: {
useAlphaSmartRoute: true,
useIbcWasm: true
},
routerConfig: {
Expand Down

0 comments on commit 09c7db1

Please sign in to comment.