Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
fix(swapper): osmosis multi-account swaps (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
pastaghost authored Feb 23, 2023
1 parent c9081bd commit 6b5a7ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/swapper/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type CommonTradeInput = {
sendMax: boolean
receiveAddress: string
accountNumber: number
receiveAccountNumber?: number
}

export type GetEvmTradeQuoteInput = CommonTradeInput & {
Expand Down Expand Up @@ -139,6 +140,7 @@ export interface TradeQuote<C extends ChainId> extends TradeBase<C> {

export interface Trade<C extends ChainId> extends TradeBase<C> {
receiveAddress: string
receiveAccountNumber?: number
}

export type ExecuteTradeInput<C extends ChainId> = {
Expand Down Expand Up @@ -230,6 +232,7 @@ export enum SwapErrorType {
POOL_NOT_FOUND = 'POOL_NOT_FOUND',
GET_TRADE_TXS_FAILED = 'GET_TRADE_TXS_FAILED',
TRADE_FAILED = 'TRADE_FAILED',
RECEIVE_ACCOUNT_NUMBER_NOT_PROVIDED = 'RECEIVE_ACCOUNT_NUMBER_NOT_PROVIDED',
}
export interface Swapper<T extends ChainId> {
/** Human-readable swapper name */
Expand Down
10 changes: 9 additions & 1 deletion packages/swapper/src/swappers/osmosis/OsmosisSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class OsmosisSwapper implements Swapper<ChainId> {
sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
receiveAddress,
accountNumber,
receiveAccountNumber,
} = args

if (!sellAmountCryptoBaseUnit) {
Expand Down Expand Up @@ -206,6 +207,7 @@ export class OsmosisSwapper implements Swapper<ChainId> {
sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBase, // TODO(gomes): wat?
sellAsset,
accountNumber,
receiveAccountNumber,
sources: [{ name: SwapperName.Osmosis, proportion: '100' }],
}
}
Expand Down Expand Up @@ -268,9 +270,15 @@ export class OsmosisSwapper implements Swapper<ChainId> {
buyAsset,
sellAmountBeforeFeesCryptoBaseUnit: sellAmountCryptoBaseUnit,
accountNumber,
receiveAccountNumber,
receiveAddress,
} = trade

if (!receiveAccountNumber)
throw new SwapError('Receive account number not provided', {
code: SwapErrorType.RECEIVE_ACCOUNT_NUMBER_NOT_PROVIDED,
})

const isFromOsmo = sellAsset.assetId === osmosisAssetId
const sellAssetDenom = symbolDenomMapping[sellAsset.symbol as keyof SymbolDenomMapping]
const buyAssetDenom = symbolDenomMapping[buyAsset.symbol as keyof SymbolDenomMapping]
Expand Down Expand Up @@ -357,7 +365,7 @@ export class OsmosisSwapper implements Swapper<ChainId> {
const cosmosAddress = isFromOsmo ? receiveAddress : sellAddress
const signTxInput = await buildTradeTx({
osmoAddress,
accountNumber,
accountNumber: receiveAccountNumber,
adapter: osmosisAdapter,
buyAssetDenom,
sellAssetDenom,
Expand Down

0 comments on commit 6b5a7ab

Please sign in to comment.