diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 1346e6b9..ed081a8e 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.3.2", + "version": "1.3.3", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 0225d50f..76ed496d 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -830,7 +830,8 @@ export class UniversalSwapHandler { simulateAmount, alphaSmartRoutes, userSlippage, - recipientAddress + recipientAddress, + affiliates } = this.swapData; const universalSwapTypeFromCosmos = [ @@ -870,8 +871,14 @@ export class UniversalSwapHandler { } const msgs = alphaSmartRoutes.routes.map((route) => { - return generateMsgSwap(route, userSlippage / 100, receiverAddresses, this.oraidexCommon, recipientAddress); - // return generateMsgSwap(route, userSlippage / 100, receiverAddresses, recipientAddress); + return generateMsgSwap( + route, + userSlippage / 100, + receiverAddresses, + this.oraidexCommon, + recipientAddress, + affiliates + ); }); const { client } = await this.config.cosmosWallet.getCosmWasmClient( diff --git a/packages/universal-swap/src/msg/chains/chain.ts b/packages/universal-swap/src/msg/chains/chain.ts index 34b266a2..f90b8259 100644 --- a/packages/universal-swap/src/msg/chains/chain.ts +++ b/packages/universal-swap/src/msg/chains/chain.ts @@ -1,6 +1,7 @@ import { OraidexCommon } from "@oraichain/oraidex-common"; import { Path } from "../../types"; import { validatePath, validateReceiver } from "../common"; +import { Affiliate } from "@oraichain/oraidex-contracts-sdk/build/OraiswapMixedRouter.types"; export class ChainMsg { constructor( @@ -9,7 +10,8 @@ export class ChainMsg { protected receiver: string, protected currentChainAddress: string, protected memo: string = "", - protected oraidexCommon: OraidexCommon + protected oraidexCommon: OraidexCommon, + protected affiliates: Affiliate[] = [] ) { // validate path validatePath(path); diff --git a/packages/universal-swap/src/msg/chains/cosmos.ts b/packages/universal-swap/src/msg/chains/cosmos.ts index 8c95d4e1..fc108e66 100644 --- a/packages/universal-swap/src/msg/chains/cosmos.ts +++ b/packages/universal-swap/src/msg/chains/cosmos.ts @@ -1,6 +1,6 @@ import { BridgeMsgInfo, MiddlewareResponse } from "../types"; import { ActionType, Path } from "../../types"; -import { Action } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; +import { Action, Affiliate } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; import { BigDecimal, calculateTimeoutTimestamp, @@ -19,9 +19,10 @@ export class CosmosMsg extends ChainMsg { receiver: string, currentChainAddress: string, memo: string = "", - oraidexCommon: OraidexCommon + oraidexCommon: OraidexCommon, + affiliates: Affiliate[] ) { - super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon); + super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon, affiliates); } setMinimumReceiveForSwap(slippage: number = 0.01) { diff --git a/packages/universal-swap/src/msg/chains/oraichain.ts b/packages/universal-swap/src/msg/chains/oraichain.ts index cb38f14d..0de374e9 100644 --- a/packages/universal-swap/src/msg/chains/oraichain.ts +++ b/packages/universal-swap/src/msg/chains/oraichain.ts @@ -1,7 +1,7 @@ import { BridgeMsgInfo, MiddlewareResponse } from "../types"; import { ActionType, Path } from "../../types"; import { SwapOperation } from "@oraichain/osor-api-contracts-sdk/src/types"; -import { Action, ExecuteMsg } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; +import { Action, Affiliate, ExecuteMsg } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; import { isCw20Token } from "../common"; import { BigDecimal, @@ -36,11 +36,11 @@ export class OraichainMsg extends ChainMsg { currentChainAddress: string, memo: string = "", oraidexCommon: OraidexCommon, - protected destPrefix: string = undefined, - protected obridgeAddress: string = undefined + protected obridgeAddress: string = undefined, + affiliates: Affiliate[] = [] ) { - super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon); + super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon, affiliates); // check chainId = "Oraichain" if (path.chainId !== "Oraichain") { throw generateError("This path must be on Oraichain"); @@ -445,7 +445,7 @@ export class OraichainMsg extends ChainMsg { min_asset: min_asset, timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), post_swap_action: this.getPostAction(bridgeInfo), - affiliates: [] + affiliates: this.affiliates } }; @@ -615,7 +615,7 @@ export class OraichainMsg extends ChainMsg { // swap and action let msg: ExecuteMsg = { swap_and_action: { - affiliates: [], + affiliates: this.affiliates, min_asset, post_swap_action: this.getPostAction(bridgeInfo), timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), diff --git a/packages/universal-swap/src/msg/chains/osmosis.ts b/packages/universal-swap/src/msg/chains/osmosis.ts index a0ffefd3..1981b079 100644 --- a/packages/universal-swap/src/msg/chains/osmosis.ts +++ b/packages/universal-swap/src/msg/chains/osmosis.ts @@ -1,7 +1,7 @@ import { BridgeMsgInfo, MiddlewareResponse } from "../types"; import { ActionType, Path } from "../../types"; import { SwapOperation } from "@oraichain/osor-api-contracts-sdk/src/types"; -import { Swap, Action, ExecuteMsg } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; +import { Swap, Action, ExecuteMsg, Affiliate } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; import { isCw20Token } from "../common"; import { BigDecimal, @@ -26,9 +26,10 @@ export class OsmosisMsg extends ChainMsg { receiver: string, currentChainAddress: string, memo: string = "", - oraidexCommon: OraidexCommon + oraidexCommon: OraidexCommon, + affiliates: Affiliate[] = [] ) { - super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon); + super(path, minimumReceive, receiver, currentChainAddress, memo, oraidexCommon, affiliates); // check chainId = "osmosis-1" if (path.chainId !== "osmosis-1") { throw generateError("This path must be on Osmosis"); @@ -197,7 +198,7 @@ export class OsmosisMsg extends ChainMsg { min_asset: min_asset, timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), post_swap_action: this.getPostAction(bridgeInfo), - affiliates: [] + affiliates: this.affiliates } }; @@ -264,7 +265,7 @@ export class OsmosisMsg extends ChainMsg { // swap and action let msg: ExecuteMsg = { swap_and_action: { - affiliates: [], + affiliates: this.affiliates, min_asset, post_swap_action: this.getPostAction(bridgeInfo), timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), diff --git a/packages/universal-swap/src/msg/msgs.ts b/packages/universal-swap/src/msg/msgs.ts index 62fb0c57..2ce77a12 100644 --- a/packages/universal-swap/src/msg/msgs.ts +++ b/packages/universal-swap/src/msg/msgs.ts @@ -13,6 +13,7 @@ import { CosmosMsg, OraichainMsg, OsmosisMsg } from "./chains"; import { MiddlewareResponse } from "./types"; import { EncodeObject } from "@cosmjs/proto-signing"; import { NetworkChainId } from "@oraichain/common"; +import { Affiliate } from "@oraichain/oraidex-contracts-sdk/build/OraiswapMixedRouter.types"; const getDestPrefixForBridgeToEvmOnOrai = (chainId: string): string => { const prefixMap: { [key: string]: string } = { @@ -37,7 +38,8 @@ const buildMemoSwap = ( addresses: { [chainId: string]: string }, slippage: number = 0.01, oraidexCommon: OraidexCommon, - previousChain?: string + previousChain?: string, + affiliates?: Affiliate[] ): MiddlewareResponse => { let currentChain = path.chainId; let currentAddress = addresses[currentChain]; @@ -59,7 +61,8 @@ const buildMemoSwap = ( memo, oraidexCommon, prefix, - oBridgeAddress + oBridgeAddress, + affiliates ); oraichainMsg.setMinimumReceiveForSwap(slippage); // we have 2 cases: @@ -73,7 +76,7 @@ const buildMemoSwap = ( return msgInfo; } case "osmosis-1": { - let cosmosMsg = new OsmosisMsg(path, "1", receiver, currentAddress, memo, oraidexCommon); + let cosmosMsg = new OsmosisMsg(path, "1", receiver, currentAddress, memo, oraidexCommon, []); cosmosMsg.setMinimumReceiveForSwap(slippage); let msgInfo = cosmosMsg.genMemoAsMiddleware(); return msgInfo; @@ -85,7 +88,7 @@ const buildMemoSwap = ( if (currentChain.startsWith("0x")) { throw generateError("Don't support universal swap in EVM"); } - let cosmosMsg = new CosmosMsg(path, "1", receiver, currentAddress, memo, oraidexCommon); + let cosmosMsg = new CosmosMsg(path, "1", receiver, currentAddress, memo, oraidexCommon, []); cosmosMsg.setMinimumReceiveForSwap(slippage); let msgInfo = cosmosMsg.genMemoAsMiddleware(); return msgInfo; @@ -99,7 +102,8 @@ const buildExecuteMsg = ( memo: string, addresses: { [chainId: string]: string }, slippage: number = 0.01, - oraidexCommon: OraidexCommon + oraidexCommon: OraidexCommon, + affiliates?: Affiliate[] ): EncodeObject => { let currentChain = path.chainId; let currentAddress = addresses[currentChain]; @@ -120,13 +124,14 @@ const buildExecuteMsg = ( memo, oraidexCommon, prefix, - oBridgeAddress + oBridgeAddress, + affiliates ); oraichainMsg.setMinimumReceiveForSwap(slippage); return oraichainMsg.genExecuteMsg(); } case "osmosis-1": { - let cosmosMsg = new OsmosisMsg(path, "1", receiver, currentAddress, memo, oraidexCommon); + let cosmosMsg = new OsmosisMsg(path, "1", receiver, currentAddress, memo, oraidexCommon, []); cosmosMsg.setMinimumReceiveForSwap(slippage); return cosmosMsg.genExecuteMsg(); } @@ -137,7 +142,7 @@ const buildExecuteMsg = ( if (currentChain.startsWith("0x")) { throw generateError("Don't support universal swap in EVM"); } - let cosmosMsg = new CosmosMsg(path, "1", receiver, currentAddress, memo, oraidexCommon); + let cosmosMsg = new CosmosMsg(path, "1", receiver, currentAddress, memo, oraidexCommon, []); cosmosMsg.setMinimumReceiveForSwap(slippage); return cosmosMsg.genExecuteMsg(); } @@ -149,7 +154,8 @@ export const generateMsgSwap = ( slippage: number = 0.01, addresses: { [chainId: string]: string }, oraidexCommon: OraidexCommon, - recipientAddress?: string + recipientAddress?: string, + affiliates?: Affiliate[] ): EncodeObject => { if (route.paths.length == 0) { throw generateError("Require at least 1 action"); @@ -177,13 +183,14 @@ export const generateMsgSwap = ( addresses, slippage, oraidexCommon, - route.paths[i - 1].chainId + route.paths[i - 1].chainId, + affiliates ); memo = swapInfo.memo; receiver = swapInfo.receiver; } - return buildExecuteMsg(route.paths[0], receiver, memo, addresses, slippage, oraidexCommon); + return buildExecuteMsg(route.paths[0], receiver, memo, addresses, slippage, oraidexCommon, affiliates); }; export const generateMemoSwap = ( @@ -192,7 +199,8 @@ export const generateMemoSwap = ( addresses: { [chainId: string]: string }, oraidexCommon: OraidexCommon, recipientAddress?: string, - previousChain?: string + previousChain?: string, + affiliates?: Affiliate[] ): MiddlewareResponse => { if (route.paths.length == 0) { return { @@ -223,7 +231,8 @@ export const generateMemoSwap = ( addresses, slippage, oraidexCommon, - route.paths[i - 1].chainId + route.paths[i - 1].chainId, + affiliates ); memo = swapInfo.memo; receiver = swapInfo.receiver;