Skip to content
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

Feat/zapper 2 #333

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/publish_oraiswap_v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: publish_package_oraiswap_v3

# 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/zapper-2]

# 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/[email protected]
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
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 Oraiswap v3
id: publish-oraiswap-v3
continue-on-error: true
run: yarn deploy:beta packages/oraiswap-v3
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Contract SDK
id: publish-oraidex-contracts-sdk
continue-on-error: true
run: yarn deploy:beta packages/contracts-sdk
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Contract Build
id: publish-oraidex-contracts-build
continue-on-error: true
run: yarn deploy:beta packages/contracts-build
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-contracts-sdk",
"version": "1.0.52",
"version": "1.0.53-beta.2",
"main": "build/index.js",
"files": [
"build/",
Expand Down
90 changes: 90 additions & 0 deletions packages/contracts-sdk/src/IncentivesFundManager.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* This file was automatically generated by @oraichain/[email protected].
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @oraichain/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import {Addr, InstantiateMsg, ExecuteMsg, Uint128, AssetInfo, Asset, QueryMsg, MigrateMsg, ConfigResponse} from "./IncentivesFundManager.types";
export interface IncentivesFundManagerReadOnlyInterface {
contractAddress: string;
config: () => Promise<ConfigResponse>;
}
export class IncentivesFundManagerQueryClient implements IncentivesFundManagerReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.config = this.config.bind(this);
}
Comment on lines +21 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid Unnecessary Binding of Methods

Since you're using arrow functions for your methods, explicit binding in the constructor is unnecessary. Arrow functions lexically bind this, so you can safely remove these bindings to simplify the constructor.

Apply this diff to remove the unnecessary bindings:

- this.config = this.config.bind(this);
- this.updateConfig = this.updateConfig.bind(this);
- this.sendFund = this.sendFund.bind(this);

Also applies to: 58-59


config = async (): Promise<ConfigResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
config: {}
});
};
Comment on lines +24 to +28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add Error Handling in the config Method

The config method performs a smart contract query but lacks error handling. To enhance robustness, consider wrapping the query in a try-catch block to handle potential exceptions, such as network issues or unexpected responses.

Apply this diff to implement error handling:

config = async (): Promise<ConfigResponse> => {
+  try {
    return this.client.queryContractSmart(this.contractAddress, {
      config: {}
    });
+  } catch (error) {
+    // Handle the error appropriately
+    throw new Error(`Failed to fetch config: ${error.message}`);
+  }
};
📝 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.

Suggested change
config = async (): Promise<ConfigResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
config: {}
});
};
config = async (): Promise<ConfigResponse> => {
try {
return this.client.queryContractSmart(this.contractAddress, {
config: {}
});
} catch (error) {
// Handle the error appropriately
throw new Error(`Failed to fetch config: ${error.message}`);
}
};

}
export interface IncentivesFundManagerInterface extends IncentivesFundManagerReadOnlyInterface {
contractAddress: string;
sender: string;
updateConfig: ({
oraiswapV3,
owner
}: {
oraiswapV3?: Addr;
owner?: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
Comment on lines +30 to +39
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Inconsistent Usage of oraiswapV3 Parameter Names

The parameter oraiswapV3 is inconsistently used as oraiswap_v3 in the following files:

  • packages/contracts-sdk/src/IncentivesFundManager.client.ts
  • packages/contracts-sdk/src/OraiswapMixedRouter.client.ts

Please update these instances to oraiswapV3 to maintain consistent naming conventions across interfaces and implementations.

🔗 Analysis chain

Verify Consistency of Parameter Naming

Ensure that parameter names are consistent across your interfaces and methods. For example, check that oraiswapV3 and owner are used uniformly throughout the codebase, adhering to naming conventions.

Run the following script to check for parameter naming consistency:

Also applies to: 62-68, 76-82

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of parameter names 'oraiswapV3' and 'owner'.

# Search for 'oraiswapV3' occurrences
rg --type ts 'oraiswapV3[^A-Za-z0-9_]'

# Search for 'owner' occurrences
rg --type ts 'owner[^A-Za-z0-9_]'

# Ensure that the parameter names match across interfaces and implementations.

Length of output: 29938

sendFund: ({
asset,
receiver
}: {
asset: Asset;
receiver: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}
export class IncentivesFundManagerClient extends IncentivesFundManagerQueryClient implements IncentivesFundManagerInterface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;
Comment on lines +49 to +51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove Redundant Assignment of contractAddress

In the IncentivesFundManagerClient constructor, this.contractAddress is assigned twice—once in the superclass and again in the subclass. This redundancy is unnecessary and can be removed to streamline the code.

Apply this diff to eliminate the redundant assignment:

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
  super(client, contractAddress);
  this.client = client;
  this.sender = sender;
- this.contractAddress = contractAddress;
  this.updateConfig = this.updateConfig.bind(this);
  this.sendFund = this.sendFund.bind(this);
}

Committable suggestion was skipped due to low confidence.


constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
this.updateConfig = this.updateConfig.bind(this);
this.sendFund = this.sendFund.bind(this);
}

updateConfig = async ({
oraiswapV3,
owner
}: {
oraiswapV3?: Addr;
owner?: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_config: {
oraiswap_v3: oraiswapV3,
owner
}
}, _fee, _memo, _funds);
};
Comment on lines +69 to +75
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle Execution Errors in updateConfig Method

The updateConfig method may encounter execution failures, such as insufficient funds or unauthorized access. Implement error handling to catch and manage these exceptions, providing informative feedback to the user or calling function.

Apply this diff to add error handling:

updateConfig = async ({
  oraiswapV3,
  owner
}: {
  oraiswapV3?: Addr;
  owner?: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
+  try {
    return await this.client.execute(this.sender, this.contractAddress, {
      update_config: {
        oraiswap_v3: oraiswapV3,
        owner
      }
    }, _fee, _memo, _funds);
+  } catch (error) {
+    // Handle the error appropriately
+    throw new Error(`Failed to execute updateConfig: ${error.message}`);
+  }
};
📝 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.

Suggested change
return await this.client.execute(this.sender, this.contractAddress, {
update_config: {
oraiswap_v3: oraiswapV3,
owner
}
}, _fee, _memo, _funds);
};
updateConfig = async ({
oraiswapV3,
owner
}: {
oraiswapV3?: Addr;
owner?: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
try {
return await this.client.execute(this.sender, this.contractAddress, {
update_config: {
oraiswap_v3: oraiswapV3,
owner
}
}, _fee, _memo, _funds);
} catch (error) {
// Handle the error appropriately
throw new Error(`Failed to execute updateConfig: ${error.message}`);
}
};

sendFund = async ({
asset,
receiver
}: {
asset: Asset;
receiver: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
send_fund: {
asset,
receiver
}
}, _fee, _memo, _funds);
};
Comment on lines +83 to +89
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle Execution Errors in sendFund Method

Similar to updateConfig, the sendFund method should include error handling to manage potential execution errors. This ensures that any issues during the transaction are properly caught and communicated.

Apply this diff to add error handling:

sendFund = async ({
  asset,
  receiver
}: {
  asset: Asset;
  receiver: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
+  try {
    return await this.client.execute(this.sender, this.contractAddress, {
      send_fund: {
        asset,
        receiver
      }
    }, _fee, _memo, _funds);
+  } catch (error) {
+    // Handle the error appropriately
+    throw new Error(`Failed to execute sendFund: ${error.message}`);
+  }
};
📝 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.

Suggested change
return await this.client.execute(this.sender, this.contractAddress, {
send_fund: {
asset,
receiver
}
}, _fee, _memo, _funds);
};
sendFund = async ({
asset,
receiver
}: {
asset: Asset;
receiver: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
try {
return await this.client.execute(this.sender, this.contractAddress, {
send_fund: {
asset,
receiver
}
}, _fee, _memo, _funds);
} catch (error) {
// Handle the error appropriately
throw new Error(`Failed to execute sendFund: ${error.message}`);
}
};

}
38 changes: 38 additions & 0 deletions packages/contracts-sdk/src/IncentivesFundManager.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type Addr = string;
export interface InstantiateMsg {
oraiswap_v3: Addr;
owner?: Addr | null;
}
export type ExecuteMsg = {
update_config: {
oraiswap_v3?: Addr | null;
owner?: Addr | null;
};
} | {
send_fund: {
asset: Asset;
receiver: Addr;
};
};
export type Uint128 = string;
export type AssetInfo = {
token: {
contract_addr: Addr;
};
} | {
native_token: {
denom: string;
};
};
export interface Asset {
amount: Uint128;
info: AssetInfo;
}
export type QueryMsg = {
config: {};
};
Comment on lines +31 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider refining the QueryMsg type definition.

The current definition of QueryMsg uses an empty object {} as a type, which is discouraged. Consider refining this type to be more explicit about its structure.

Here's a suggested improvement:

export type QueryMsg = {
  config: Record<string, never>;
};

This change maintains the same functionality while addressing the static analysis warning about using {} as a type.

🧰 Tools
🪛 Biome

[error] 32-32: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

export interface MigrateMsg {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refine the MigrateMsg definition.

The MigrateMsg is currently defined as an empty interface, which is equivalent to {}. This has been flagged by the static analysis tool.

Consider changing it to a type alias if no properties are needed:

export type MigrateMsg = Record<string, never>;

This change maintains the same functionality while addressing the static analysis warning about empty interfaces.

🧰 Tools
🪛 Biome

[error] 34-34: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

export interface ConfigResponse {
oraiswap_v3: Addr;
owner: Addr;
}
9 changes: 8 additions & 1 deletion packages/contracts-sdk/src/OraiswapV3.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import {Percentage, InstantiateMsg, ExecuteMsg, Addr, Liquidity, SqrtPrice, TokenAmount, Binary, Expiration, Timestamp, Uint64, AssetInfo, PoolKey, FeeTier, SwapHop, NftExtensionMsg, QueryMsg, MigrateMsg, FeeGrowth, AllNftInfoResponse, OwnerOfResponse, Approval, NftInfoResponse, Position, PositionIncentives, ArrayOfPosition, TokensResponse, ApprovedForAllResponse, Boolean, ArrayOfFeeTier, ArrayOfLiquidityTick, LiquidityTick, Uint32, NumTokensResponse, Pool, IncentiveRecord, ArrayOfPoolWithPoolKey, PoolWithPoolKey, Uint128, ArrayOfAsset, Asset, ArrayOfPositionTick, PositionTick, QuoteResult, Tick, TickIncentive, ArrayOfTupleOfUint16AndUint64} from "./OraiswapV3.types";
import {Addr, Percentage, InstantiateMsg, ExecuteMsg, Liquidity, SqrtPrice, TokenAmount, Binary, Expiration, Timestamp, Uint64, AssetInfo, PoolKey, FeeTier, SwapHop, NftExtensionMsg, QueryMsg, MigrateMsg, FeeGrowth, AllNftInfoResponse, OwnerOfResponse, Approval, NftInfoResponse, Position, PositionIncentives, ArrayOfPosition, TokensResponse, ApprovedForAllResponse, Boolean, ArrayOfFeeTier, ArrayOfLiquidityTick, LiquidityTick, Uint32, NumTokensResponse, Pool, IncentiveRecord, ArrayOfPoolWithPoolKey, PoolWithPoolKey, Uint128, ArrayOfAsset, Asset, ArrayOfPositionTick, PositionTick, QuoteResult, Tick, TickIncentive, ArrayOfTupleOfUint16AndUint64} from "./OraiswapV3.types";
export interface OraiswapV3ReadOnlyInterface {
contractAddress: string;
admin: () => Promise<Addr>;
protocolFee: () => Promise<Percentage>;
incentivesFundManager: () => Promise<Addr>;
position: ({
index,
ownerId
Expand Down Expand Up @@ -205,6 +206,7 @@ export class OraiswapV3QueryClient implements OraiswapV3ReadOnlyInterface {
this.contractAddress = contractAddress;
this.admin = this.admin.bind(this);
this.protocolFee = this.protocolFee.bind(this);
this.incentivesFundManager = this.incentivesFundManager.bind(this);
this.position = this.position.bind(this);
this.positions = this.positions.bind(this);
this.allPosition = this.allPosition.bind(this);
Expand Down Expand Up @@ -243,6 +245,11 @@ export class OraiswapV3QueryClient implements OraiswapV3ReadOnlyInterface {
protocol_fee: {}
});
};
incentivesFundManager = async (): Promise<Addr> => {
return this.client.queryContractSmart(this.contractAddress, {
incentives_fund_manager: {}
});
};
position = async ({
index,
ownerId
Expand Down
5 changes: 4 additions & 1 deletion packages/contracts-sdk/src/OraiswapV3.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type Addr = string;
export type Percentage = number;
export interface InstantiateMsg {
incentives_fund_manager: Addr;
protocol_fee: Percentage;
}
export type ExecuteMsg = {
Expand Down Expand Up @@ -132,7 +134,6 @@ export type ExecuteMsg = {
index: number;
};
};
export type Addr = string;
export type Liquidity = string;
export type SqrtPrice = string;
export type TokenAmount = string;
Expand Down Expand Up @@ -180,6 +181,8 @@ export type QueryMsg = {
admin: {};
} | {
protocol_fee: {};
} | {
incentives_fund_manager: {};
Comment on lines +184 to +185
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Approve the new query, but refine the type definition.

The addition of the incentives_fund_manager query is a good complement to the new instantiation parameter. However, the use of {} as a type is not recommended.

Replace {} with a more specific type or void to improve type safety:

export type QueryMsg = {
  // ... other queries ...
} | {
  incentives_fund_manager: void;
} | {
  // ... remaining queries ...
};

This change addresses the static analysis warning and makes the type definition more explicit.

🧰 Tools
🪛 Biome

[error] 185-185: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

} | {
position: {
index: number;
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ export * as OraiswapMixedRouterTypes from "./OraiswapMixedRouter.types";
export * from "./OraiswapMixedRouter.client";
export * as ZapperTypes from "./Zapper.types";
export * from "./Zapper.client";
export * as IncentivesFundManagerTypes from "./IncentivesFundManager.types";
export * from "./IncentivesFundManager.client";
export * from "./types";
4 changes: 2 additions & 2 deletions packages/oraiswap-v3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraiswap-v3",
"version": "0.1.20",
"version": "0.1.20-beta.1",
"main": "build/index.js",
"files": [
"build/"
Expand All @@ -12,7 +12,7 @@
"license": "MIT",
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.31.0",
"@oraichain/oraidex-contracts-sdk": "^1.0.52",
"@oraichain/oraidex-contracts-sdk": "1.0.53-beta.2",
"@oraichain/oraidex-common": "^1.1.21"
}
}
12 changes: 12 additions & 0 deletions packages/oraiswap-v3/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ export class RouteNotFoundError extends Error {
constructor(route: string) {
super(`Route not found: ${route}`);
}
}

export class RouteNoLiquidity extends Error {
constructor() {
super(`Route has no liquidity`);
}
}

export class SpamTooManyRequestsError extends Error {
constructor() {
super(`Too many requests`);
}
}
Loading
Loading