From 66f76264654b9b3e4c7f3503cce68b5685bbc95a Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 20 Feb 2025 18:39:26 +0700 Subject: [PATCH 1/3] feat add affiliates mobile --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/handler.ts | 13 +++++-- .../universal-swap/src/msg/chains/chain.ts | 4 ++- .../universal-swap/src/msg/chains/cosmos.ts | 7 ++-- .../src/msg/chains/oraichain.ts | 12 +++---- .../universal-swap/src/msg/chains/osmosis.ts | 11 +++--- packages/universal-swap/src/msg/msgs.ts | 35 ++++++++++++------- 7 files changed, 52 insertions(+), 32 deletions(-) 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; From ef1a967f286da800d5626d863f1e49541b59b7ee Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 20 Feb 2025 18:41:24 +0700 Subject: [PATCH 2/3] feat add affiliates mobile --- .../publish_package_universal_swap.yml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/publish_package_universal_swap.yml diff --git a/.github/workflows/publish_package_universal_swap.yml b/.github/workflows/publish_package_universal_swap.yml new file mode 100644 index 00000000..94a1f7fb --- /dev/null +++ b/.github/workflows/publish_package_universal_swap.yml @@ -0,0 +1,70 @@ +name: publish_package_universal_common + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [feat/add-affiliates] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + node-version: ["18"] + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v4 + id: yarn-cache + with: + path: | + ${{ steps.yarn-cache-dir-path.outputs.dir }} + ./node_modules/ + key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install Dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn + - name: Build + run: yarn build + - name: Authenticate with private NPM package + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + - name: Publish Oraidex Common + id: publish-common + continue-on-error: true + run: yarn deploy packages/oraidex-common + env: + CI: false + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish Universal-swap + id: publish-universal-swap + continue-on-error: true + run: yarn deploy:beta packages/universal-swap + env: + CI: false + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: send result via discord + uses: appleboy/discord-action@master + with: + webhook_id: ${{ secrets.WEBHOOK_ID }} + webhook_token: ${{ secrets.WEBHOOK_TOKEN }} + username: "GitBot" + message: "Repo oraidex-sdk has just published. Oraidex common: ${{ steps.publish-common.outcome }}. Universal swap: ${{ steps.publish-universal-swap.outcome }}" From e891f577c4259d3df8f62e3deb67e57d9a6b1c69 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 21 Feb 2025 10:14:09 +0700 Subject: [PATCH 3/3] remove yaml test --- .../publish_package_universal_swap.yml | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 .github/workflows/publish_package_universal_swap.yml diff --git a/.github/workflows/publish_package_universal_swap.yml b/.github/workflows/publish_package_universal_swap.yml deleted file mode 100644 index 94a1f7fb..00000000 --- a/.github/workflows/publish_package_universal_swap.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: publish_package_universal_common - -# Controls when the action will run. -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [feat/add-affiliates] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - build: - runs-on: ubuntu-20.04 - strategy: - matrix: - node-version: ["18"] - - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.8.0 - with: - access_token: ${{ github.token }} - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v4 - id: yarn-cache - with: - path: | - ${{ steps.yarn-cache-dir-path.outputs.dir }} - ./node_modules/ - key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Install Dependencies - if: steps.yarn-cache.outputs.cache-hit != 'true' - run: yarn - - name: Build - run: yarn build - - name: Authenticate with private NPM package - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - - name: Publish Oraidex Common - id: publish-common - continue-on-error: true - run: yarn deploy packages/oraidex-common - env: - CI: false - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Publish Universal-swap - id: publish-universal-swap - continue-on-error: true - run: yarn deploy:beta packages/universal-swap - env: - CI: false - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: send result via discord - uses: appleboy/discord-action@master - with: - webhook_id: ${{ secrets.WEBHOOK_ID }} - webhook_token: ${{ secrets.WEBHOOK_TOKEN }} - username: "GitBot" - message: "Repo oraidex-sdk has just published. Oraidex common: ${{ steps.publish-common.outcome }}. Universal swap: ${{ steps.publish-universal-swap.outcome }}"