Skip to content

Commit

Permalink
update getAdapterParam
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 11, 2023
1 parent 444b16e commit 1b6d046
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/dex/smardex/smardex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,27 +678,29 @@ export class Smardex
};
}

// Encode params required by the exchange adapter
// Used for multiSwap & megaSwap
// Hint: abiCoder.encodeParameter() could be useful
getWETHAddress(srcToken: Address, destToken: Address, weth?: Address) {
if (!isETHAddress(srcToken) && !isETHAddress(destToken))
return NULL_ADDRESS;
return weth || this.dexHelper.config.data.wrappedNativeTokenAddress;
}

getAdapterParam(
srcToken: Address,
destToken: Address,
srcAmount: NumberAsString,
toAmount: NumberAsString, // required for buy case
toAmount: NumberAsString,
data: SmardexData,
side: SwapSide,
): AdapterExchangeParam {
const pools = encodePools(data.pools);
const weth = this.getWETHAddress(srcToken, destToken, data.wethAddress);
const payload = this.abiCoder.encodeParameter(
{
ParentStruct: {
weth: 'address',
pools: 'uint256[]',
path: 'address[] calldata',
receiver: 'address',
deadline: 'uint256'
},
},
{ pools, weth },
{ path: data.path, receiver: data.receiver, deadline: data.deadline },
);
return {
targetExchange: data.router,
Expand All @@ -707,12 +709,6 @@ export class Smardex
};
}

getWETHAddress(srcToken: Address, destToken: Address, weth?: Address) {
if (!isETHAddress(srcToken) && !isETHAddress(destToken))
return NULL_ADDRESS;
return weth || this.dexHelper.config.data.wrappedNativeTokenAddress;
}

async getSimpleParam(
src: Address,
dest: Address,
Expand Down

0 comments on commit 1b6d046

Please sign in to comment.