mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-31 01:58:06 +03:00
feat: moved to swapUniV2Scaled function
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.76-rc114",
|
||||
"version": "0.20.76-rc115",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
|
||||
@@ -3,6 +3,15 @@ import { SafeArray } from "../../../utils/safeGetters.js"
|
||||
import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers"
|
||||
import { addCallParams } from "./utils.js"
|
||||
import type { SingleSwap } from "../../../types.js"
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
|
||||
const BILLION = 1000000000;
|
||||
const TEN_THOUSANDS = 10000;
|
||||
|
||||
function countScaledFee(fee: string) {
|
||||
// The count is needed for the swapUniV2Scaled function, where the denominator is one billion
|
||||
return new BigNumber(fee).multipliedBy(BILLION).div(TEN_THOUSANDS).toNumber();
|
||||
}
|
||||
|
||||
export async function generateUni2Calls(
|
||||
path: SafeArray<SingleSwap>,
|
||||
@@ -20,17 +29,20 @@ export async function generateUni2Calls(
|
||||
currentSwap.assetIn,
|
||||
currentSwap.assetOut,
|
||||
nextSwap.pool,
|
||||
nextSwap.fee
|
||||
currentSwap.fee
|
||||
)
|
||||
calls.push(call)
|
||||
}
|
||||
}
|
||||
|
||||
const lastSwap = path.last();
|
||||
const calldata = executorInterface.encodeFunctionData('swapUniV2', [
|
||||
const fee = lastSwap.fee ?? 3;
|
||||
const scaledFee = countScaledFee(fee.toString());
|
||||
const calldata = executorInterface.encodeFunctionData('swapUniV2Scaled', [
|
||||
lastSwap.pool,
|
||||
lastSwap.assetIn,
|
||||
lastSwap.assetOut,
|
||||
ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [concat(['0x03', recipient])]),
|
||||
ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [concat([toBeHex(scaledFee), recipient])]),
|
||||
])
|
||||
calls.push(addCallParams(calldata))
|
||||
|
||||
@@ -45,11 +57,12 @@ export function generateUni2Call(
|
||||
fee: BigNumberish = 3,
|
||||
) {
|
||||
const executorInterface = SwapExecutor__factory.createInterface()
|
||||
const calldata = executorInterface.encodeFunctionData('swapUniV2', [
|
||||
const scaledFee = countScaledFee(fee.toString());
|
||||
const calldata = executorInterface.encodeFunctionData('swapUniV2Scaled', [
|
||||
pool,
|
||||
assetIn,
|
||||
assetOut,
|
||||
ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [concat([toBeHex(fee), recipient])]),
|
||||
ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [concat([toBeHex(scaledFee), recipient])]),
|
||||
])
|
||||
return addCallParams(calldata)
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export async function generateSwapCalldata({
|
||||
swapInfo.assetOut = swapInfo.assetOut.toLowerCase()
|
||||
return swapInfo;
|
||||
});
|
||||
console.log('path', path);
|
||||
logger?.(`path: ${path}`);
|
||||
|
||||
const { assetIn: srcToken } = path.first();
|
||||
const { assetOut: dstToken } = path.last();
|
||||
|
||||
Reference in New Issue
Block a user