Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .cursor/rules/do-before-run.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: Do before run
globs:
alwaysApply: true
---

- Step 1: Rewrite my request so that it’s maximally clear, detailed, and optimized for accuracy.
- Step 2: Show me the improved version.
- Step 3: Execute the improved version.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion apps
Submodule apps updated from d06dbc to f238d2
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@oraichain/owallet-wallet-standard": "0.1.1",
"@oraichain/tonbridge-sdk": "^1.4.2",
"@orbs-network/ton-access": "^2.3.3",
"@skip-go/client": "^1.4.0",
"@solana/spl-memo": "0.2.5",
"@solana/spl-token": "0.3.5",
"@solana/wallet-standard-chains": "1.1.0",
Expand Down Expand Up @@ -98,14 +99,15 @@
"ts-jest": "29.1.1",
"ts-loader": "^8.0.14",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"typescript": "^5.0.0",
"zx": "^4.2.0"
},
"resolutions": {
"@ledgerhq/hw-transport": "6.27.2",
"@ledgerhq/devices": "^7.0.0",
"webpack": "5.88.1",
"@cosmjs/crypto": "^0.24.0-alpha.25",
"@skip-go/client": "^1.4.0",
"@iov/crypto": "2.1.0",
"libsodium": "file:./etc/noop",
"libsodium-wrappers": "file:./etc/noop",
Expand Down Expand Up @@ -146,6 +148,7 @@
"web3": "1.7.4",
"web3-utils": "1.7.4",
"ws": "8.17.1",
"viem": "^2.33.0",
"webextension-polyfill": "^0.10.0",
"@ledgerhq/hw-app-eth": "6.29.3",
"@ton/core": "0.56.3",
Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@keplr-wallet/unit": "0.12.159",
"@owallet/crypto": "*",
"@owallet/types": "*",
"@skip-go/client": "^1.4.0",
"bitcoin-address-validation": "2.2.3",
"bitcoinjs-lib": "5.2.0",
"buffer": "^6.0.3",
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export * from "./config";
export * from "./api";
export * from "./oasis";
export * from "./bitcoin";
export * from "./universal-swap";
export * from "./swap";
export * from "./swap/api/adapters/BaseAdapter";
export * from "./swap/api/adapters/jupiter";
export * from "./swap/api/adapters/kyberswap";
export * from "./swap/api/adapters/obridge";
export * from "./swap/api/adapters/skip";
124 changes: 124 additions & 0 deletions packages/common/src/swap/api/adapters/BaseAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Route, RouteParams, Transaction } from "../../types/v2";
import { AppCurrency } from "@owallet/types";

/**
* BaseAdapter is an abstract class that defines the interface for swap providers
* All swap providers (KyberSwap, Jupiter, etc.) should extend this class
*/
export abstract class BaseAdapter {
/** Provider identifier */
abstract readonly provider: string;

/** Chains supported by this provider */
abstract readonly supportedChains: string[];
/**
* Check if this adapter supports AbortController
* Override this in adapters that don't support abort
*/
supportsAbortController(): boolean {
return true; // Default to true for most adapters
}
/**
* Get available routes for a swap
* @param params Swap parameters including tokens, amount, and slippage
* @returns Promise with array of available routes
*/
abstract getRoutes(
params: RouteParams,
signal?: AbortSignal
): Promise<Route[]>;

/**
* Build a transaction for the selected route
* @param route Selected route object
* @param userAddress User's wallet address
* @param slippageTolerance Slippage tolerance in basis points (e.g. 50 = 0.5%)
* @returns Promise with transaction data
*/
abstract buildTransaction(
route: Route,
userAddress: string,
slippageTolerance: number
): Promise<Transaction>;

/**
* Build a transaction for the selected route
* @param tx transaction data
* @param userAddress with string
* @param destinationChainCurrencies currencies for the destination chain
* @param ibcSwapConfigs IBC swap configurations (optional)
* @returns Promise with string
*/
abstract signAndSendTransaction(
tx: Transaction,
userAddress: string,
destinationChainCurrencies?: AppCurrency[],
extraSwapLogic?: Function
): Promise<string>;

/**
* Check if approval is needed for EVM tokens
* @param tokenAddress Token contract address
* @param ownerAddress Token owner address
* @param spenderAddress Address that will spend the tokens
* @param amount Amount to approve
* @returns Promise with boolean indicating if approval is needed
*/
abstract checkApprovalNeeded?(
tokenAddress: string,
ownerAddress: string,
spenderAddress: string,
amount: string,
chainId: string | number
): Promise<boolean>;

/**
* Build approval transaction for EVM tokens
* @param tokenAddress Token contract address
* @param spenderAddress Address that will spend the tokens
* @param amount Amount to approve
* @param chainId ChainId to approve
* @returns Promise with approval transaction data
*/
abstract buildApprovalTransaction?(
tokenAddress: string,
spenderAddress: string,
amount: string,
chainId: string | number
): Promise<Transaction>;

/**
* Get price impact for a swap
* @param params Parameters needed to calculate price impact
* @returns Promise with price impact data
*/
abstract getPriceImpact?(params: {
tokenInAddress: string;
tokenInDecimals: number;
tokenOutAddress: string;
tokenOutDecimals: number;
amountIn: string;
amountOut: string;
chainId: number;
}): Promise<{ priceImpact: string }>;

/**
* Helper method to abort any ongoing requests
*/
abstract abortRequests(): void;

/**
* Add affiliate fee to the transaction if supported
* @param params Parameters needed to add fee
*/
abstract addAffiliateFeeToBuildParams?(params: any): any;

/**
* Check if the provider supports a specific chain
* @param chainId Chain identifier
* @returns Boolean indicating if the chain is supported
*/
supportsChain(chainId: string): boolean {
return this.supportedChains.includes(chainId);
}
}
6 changes: 6 additions & 0 deletions packages/common/src/swap/api/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Export BaseAdapter and all adapter implementations
export { BaseAdapter } from "./BaseAdapter";
export { SkipAdapter } from "./skip";
export { KyberSwapAdapter } from "./kyberswap";
export { ObridgeAdapter } from "./obridge";
export { JupiterAdapter } from "./jupiter";
Loading
Loading