mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-29 00:57:56 +03:00
Change final transfer location. Add wrap/unwrap functionality
This commit is contained in:
@@ -1,28 +1,44 @@
|
||||
import { SwapExecutor__factory, CurveRegistry__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
|
||||
import type { BigNumberish, JsonRpcProvider } from "ethers"
|
||||
import { addCallParams } from "./utils.js"
|
||||
import type { SingleSwap } from "../../../types.js"
|
||||
import {
|
||||
SwapExecutor__factory,
|
||||
CurveRegistry__factory,
|
||||
ERC20__factory,
|
||||
} from "@orionprotocol/contracts/lib/ethers-v6/index.js";
|
||||
import { MaxUint256, type BigNumberish, type JsonRpcProvider } from "ethers";
|
||||
import { addCallParams } from "./utils.js";
|
||||
import type { SingleSwap } from "../../../types.js";
|
||||
import { generateApproveCall } from "./erc20.js";
|
||||
import type { BytesLike } from "ethers";
|
||||
|
||||
export async function generateCurveStableSwapCall(
|
||||
amount: BigNumberish,
|
||||
to: string,
|
||||
swap: SingleSwap,
|
||||
provider: JsonRpcProvider,
|
||||
swapExecutorContractAddress: string,
|
||||
curveRegistry: string
|
||||
) {
|
||||
const executorInterface = SwapExecutor__factory.createInterface()
|
||||
const registry = CurveRegistry__factory.connect(curveRegistry, provider)
|
||||
const { pool, assetIn, assetOut } = swap
|
||||
const [i, j,] = await registry.get_coin_indices(pool, assetIn, assetOut)
|
||||
const executorInterface = SwapExecutor__factory.createInterface();
|
||||
const registry = CurveRegistry__factory.connect(curveRegistry, provider);
|
||||
const { pool, assetIn, assetOut } = swap;
|
||||
const firstToken = ERC20__factory.connect(assetIn, provider)
|
||||
const executorAllowance = await firstToken.allowance(swapExecutorContractAddress, pool)
|
||||
|
||||
let calldata = executorInterface.encodeFunctionData('curveSwapStableAmountIn', [
|
||||
pool,
|
||||
assetOut,
|
||||
i,
|
||||
j,
|
||||
to,
|
||||
amount,
|
||||
])
|
||||
const calls: BytesLike[] = []
|
||||
if (executorAllowance <= BigInt(amount)) {
|
||||
const approveCall = await generateApproveCall(
|
||||
assetIn,
|
||||
pool,
|
||||
MaxUint256
|
||||
);
|
||||
calls.push(approveCall);
|
||||
}
|
||||
|
||||
return addCallParams(calldata)
|
||||
}
|
||||
const [i, j] = await registry.get_coin_indices(pool, assetIn, assetOut);
|
||||
let calldata = executorInterface.encodeFunctionData(
|
||||
"curveSwapStableAmountIn",
|
||||
[pool, assetOut, i, j, to, amount]
|
||||
);
|
||||
calls.push(addCallParams(calldata))
|
||||
|
||||
return calls
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
|
||||
import { SafeArray } from "../../../utils/safeGetters.js"
|
||||
import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers"
|
||||
import { addCallParams, generateCalls } from "./utils.js"
|
||||
import { addCallParams } from "./utils.js"
|
||||
import type { SingleSwap } from "../../../types.js"
|
||||
|
||||
export async function generateUni2Calls(
|
||||
@@ -33,7 +33,7 @@ export async function generateUni2Calls(
|
||||
])
|
||||
calls.push(addCallParams(calldata))
|
||||
|
||||
return generateCalls(calls)
|
||||
return calls
|
||||
}
|
||||
|
||||
export async function generateUni2Call(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
|
||||
import { type BigNumberish , type BytesLike, ethers, JsonRpcProvider } from "ethers"
|
||||
import { type BigNumberish , ethers, JsonRpcProvider } from "ethers"
|
||||
import { SafeArray } from "../../../utils/safeGetters.js"
|
||||
import { addCallParams, generateCalls } from "./utils.js"
|
||||
import { addCallParams } from "./utils.js"
|
||||
import type { SingleSwap } from "../../../types.js"
|
||||
|
||||
export async function generateUni3Call(
|
||||
@@ -49,7 +49,7 @@ export async function generateUni3Calls(
|
||||
let calldata = executorInterface.encodeFunctionData('uniswapV3SwapTo', [encodedPools, recipient, amount])
|
||||
calldata = addCallParams(calldata)
|
||||
|
||||
return generateCalls([calldata])
|
||||
return [calldata]
|
||||
}
|
||||
|
||||
export async function generateOrion3Calls(
|
||||
@@ -67,7 +67,7 @@ export async function generateOrion3Calls(
|
||||
let calldata = executorInterface.encodeFunctionData('orionV3SwapTo', [encodedPools, recipient, amount])
|
||||
calldata = addCallParams(calldata)
|
||||
|
||||
return generateCalls([calldata])
|
||||
return [calldata]
|
||||
}
|
||||
|
||||
export async function encodePoolV3(
|
||||
|
||||
32
src/Unit/Exchange/callGenerators/weth.ts
Normal file
32
src/Unit/Exchange/callGenerators/weth.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
|
||||
import type { BigNumberish } from "ethers"
|
||||
import { type CallParams, addCallParams } from "./utils.js"
|
||||
import type { AddressLike } from "ethers"
|
||||
|
||||
export function generateWrapAndTransferCall(
|
||||
target: AddressLike,
|
||||
callParams?: CallParams
|
||||
) {
|
||||
|
||||
const executorInterface = SwapExecutor__factory.createInterface()
|
||||
const calldata = executorInterface.encodeFunctionData('wrapAndTransfer', [
|
||||
target,
|
||||
])
|
||||
|
||||
return addCallParams(calldata, callParams)
|
||||
}
|
||||
|
||||
export function generateUnwrapAndTransferCall(
|
||||
target: AddressLike,
|
||||
amount: BigNumberish,
|
||||
callParams?: CallParams
|
||||
) {
|
||||
|
||||
const executorInterface = SwapExecutor__factory.createInterface()
|
||||
const calldata = executorInterface.encodeFunctionData('unwrapAndTransfer', [
|
||||
target,
|
||||
amount
|
||||
])
|
||||
|
||||
return addCallParams(calldata, callParams)
|
||||
}
|
||||
Reference in New Issue
Block a user