Merge branch 'refs/heads/main' into feat/OP-4308-cross-chain-swap

# Conflicts:
#	package-lock.json
#	package.json
This commit is contained in:
TheJuze
2024-06-11 16:06:28 +03:00
24 changed files with 79 additions and 45 deletions

1
.gitignore vendored
View File

@@ -132,3 +132,4 @@ lib
.pnp.*
src/artifacts/contracts/
.DS_store

33
package-lock.json generated
View File

@@ -1,18 +1,19 @@
{
"name": "@orionprotocol/sdk",
"version": "0.22.0-rc25",
"version": "0.22.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.22.0-rc25",
"version": "0.22.3",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.21.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@orionprotocol/contracts": "1.23.4-rc",
"@orionprotocol/contracts": "^1.23.9",
"@types/lodash.clonedeep": "^4.5.9",
"bignumber.js": "^9.1.1",
"bson-objectid": "^2.0.4",
@@ -26,7 +27,7 @@
"merge-anything": "^5.1.7",
"neverthrow": "^6.0.0",
"patch-package": "^8.0.0",
"simple-typed-fetch": "0.2.5",
"simple-typed-fetch": "0.2.3",
"stream-browserify": "^3.0.0",
"tiny-invariant": "^1.3.1",
"ts-is-present": "^1.2.2",
@@ -2421,9 +2422,9 @@
}
},
"node_modules/@orionprotocol/contracts": {
"version": "1.23.4-rc",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.4-rc.tgz",
"integrity": "sha512-Cd5oMVZzMuQbOqbVBnwUbLXr6jpwOq4MtwoLo/l6T1BxWh/s1hKF8VuIvUJgGbzI0HEg3AGa1DCT4chwe9721Q=="
"version": "1.23.9",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz",
"integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q=="
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
@@ -10398,9 +10399,9 @@
"dev": true
},
"node_modules/simple-typed-fetch": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/simple-typed-fetch/-/simple-typed-fetch-0.2.5.tgz",
"integrity": "sha512-T/KKUHKOZgaYVp3dbjE1wEK5cAGmG5N7FNAzP6ZGqLDhzBsRm3Gpt8bO/kowV6bt8duXDWiapYFQibW/8iHp6Q==",
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/simple-typed-fetch/-/simple-typed-fetch-0.2.3.tgz",
"integrity": "sha512-EXP2mVVsVf4A3+5QGevs8789ztnT6FozsYyMrIrUYhfqtX2V+X9xETHeGXffmgv7YQ0p+GrW7N+5x+b+pBW59Q==",
"dependencies": {
"isomorphic-unfetch": "^4.0.2",
"neverthrow": "^6.0.0",
@@ -13488,9 +13489,9 @@
}
},
"@orionprotocol/contracts": {
"version": "1.23.4-rc",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.4-rc.tgz",
"integrity": "sha512-Cd5oMVZzMuQbOqbVBnwUbLXr6jpwOq4MtwoLo/l6T1BxWh/s1hKF8VuIvUJgGbzI0HEg3AGa1DCT4chwe9721Q=="
"version": "1.23.9",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.9.tgz",
"integrity": "sha512-tx21XokSK8kBYmuzfYrXoDattirm6yaG3dslrOKZTHgGP1wC6c6SbQF69pVCCAnPNGvQCt4lw0I/8fxm9Cx23Q=="
},
"@sinclair/typebox": {
"version": "0.27.8",
@@ -19335,9 +19336,9 @@
"dev": true
},
"simple-typed-fetch": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/simple-typed-fetch/-/simple-typed-fetch-0.2.5.tgz",
"integrity": "sha512-T/KKUHKOZgaYVp3dbjE1wEK5cAGmG5N7FNAzP6ZGqLDhzBsRm3Gpt8bO/kowV6bt8duXDWiapYFQibW/8iHp6Q==",
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/simple-typed-fetch/-/simple-typed-fetch-0.2.3.tgz",
"integrity": "sha512-EXP2mVVsVf4A3+5QGevs8789ztnT6FozsYyMrIrUYhfqtX2V+X9xETHeGXffmgv7YQ0p+GrW7N+5x+b+pBW59Q==",
"requires": {
"isomorphic-unfetch": "^4.0.2",
"neverthrow": "^6.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.22.0-rc25",
"version": "0.23.0-rc0",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,7 +1,7 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import clone from 'just-clone';
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import { APPROVE_ERC20_GAS_LIMIT, NATIVE_CURRENCY_PRECISION } from './constants/index.js';
import type {
AggregatedBalanceRequirement, ApproveFix, Asset, BalanceIssue, BalanceRequirement, Source,

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js';

View File

@@ -0,0 +1,27 @@
import { SwapExecutor__factory, AeroPool__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import { type BigNumberish, JsonRpcProvider } from "ethers"
import { SafeArray } from "../../../utils/safeGetters.js"
import { addCallParams } from "./utils.js"
import type { SingleSwap } from "../../../types.js"
export async function generateAeroCalls(
path: SafeArray<SingleSwap>,
amount: BigNumberish,
recipient: string,
provider: JsonRpcProvider
) {
const pools: string[] = [];
const direct: boolean[] = [];
for (const swap of path) {
pools.push(swap.pool);
const token0 = await AeroPool__factory.connect(swap.pool, provider).token0();
direct.push(swap.assetIn.toLowerCase() === token0.toLowerCase());
}
const executorInterface = SwapExecutor__factory.createInterface()
let calldata = executorInterface.encodeFunctionData('swapAeroMulti', [pools, direct, amount, recipient]);
calldata = addCallParams(calldata)
return [calldata]
}

View File

@@ -2,7 +2,7 @@ import {
SwapExecutor__factory,
CurveRegistry__factory,
ERC20__factory,
} from "@orionprotocol/contracts/lib/ethers-v6/index.js";
} from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js";
import { MaxUint256, type BigNumberish, type JsonRpcProvider } from "ethers";
import { addCallParams, pathCallWithBalance } from "./utils.js";
import type { SingleSwap } from "../../../types.js";
@@ -45,5 +45,5 @@ export async function generateCurveStableSwapCall(
}
calls.push(calldata)
return calls
return calls
}

View File

@@ -1,4 +1,4 @@
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import type { BigNumberish, AddressLike } from "ethers"
import { type CallParams, addCallParams } from "./utils.js"
@@ -15,7 +15,7 @@ export function generateTransferCall(
target,
amount
])
return addCallParams(calldata, callParams)
}
@@ -31,6 +31,6 @@ export function generateApproveCall(
target,
amount
])
return addCallParams(calldata, callParams)
}

View File

@@ -1,4 +1,4 @@
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import type { BigNumberish, AddressLike } from "ethers"
import { type CallParams, addCallParams } from "./utils.js"
@@ -16,6 +16,6 @@ export function generateFeePaymentCall(
token,
amount
])
return addCallParams(calldata, callParams)
}

View File

@@ -1,4 +1,4 @@
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import { SafeArray } from "../../../utils/safeGetters.js"
import { type BytesLike, type BigNumberish, concat, ethers, toBeHex } from "ethers"
import { addCallParams } from "./utils.js"

View File

@@ -1,4 +1,4 @@
import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { SwapExecutor__factory, UniswapV3Pool__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import { type BigNumberish , ethers, JsonRpcProvider } from "ethers"
import { SafeArray } from "../../../utils/safeGetters.js"
import { addCallParams } from "./utils.js"

View File

@@ -1,4 +1,4 @@
import { ERC20__factory, SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { ERC20__factory, SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import type { AddressLike } from "ethers"
import { type BytesLike, ethers, type BigNumberish } from "ethers"

View File

@@ -1,4 +1,4 @@
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6/index.js"
import { SwapExecutor__factory } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js"
import type { BigNumberish } from "ethers"
import { type CallParams, addCallParams } from "./utils.js"
import type { AddressLike } from "ethers"
@@ -12,7 +12,7 @@ export function generateWrapAndTransferCall(
const calldata = executorInterface.encodeFunctionData('wrapAndTransfer', [
target,
])
return addCallParams(calldata, callParams)
}
@@ -27,6 +27,6 @@ export function generateUnwrapAndTransferCall(
target,
amount
])
return addCallParams(calldata, callParams)
}

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import type Unit from '../index.js';

View File

@@ -1,4 +1,4 @@
import type { LibValidator } from '@orionprotocol/contracts/lib/ethers-v6/Exchange.js';
import type { LibValidator } from '@orionprotocol/contracts/lib/ethers-v6-cjs/Exchange.js';
import { ethers, ZeroAddress } from 'ethers';
import type { AddressLike, JsonRpcProvider, BigNumberish, BytesLike } from 'ethers';
import cloneDeep from 'lodash.clonedeep';
@@ -20,8 +20,9 @@ import { addressLikeToString } from '../../utils/addressLikeToString.js';
import { generateUnwrapAndTransferCall, generateWrapAndTransferCall } from './callGenerators/weth.js';
import { getExchangeAllowance, getTotalBalance } from '../../utils/getBalance.js';
import { generateFeePaymentCall } from './callGenerators/feePayment.js';
import { generateAeroCalls } from './callGenerators/aero.js';
export type Factory = 'UniswapV2' | 'UniswapV3' | 'Curve' | 'OrionV2' | 'OrionV3';
export type Factory = 'UniswapV2' | 'UniswapV3' | 'Curve' | 'OrionV2' | 'OrionV3' | 'Aero';
type BaseGenerateSwapCalldataParams = {
amount: BigNumberish
@@ -276,6 +277,10 @@ async function processSingleFactorySwaps(
calls = await generateOrion3Calls(path, amount, swapExecutorContractAddress, provider);
break;
}
case "Aero": {
calls = await generateAeroCalls(path, amount, swapExecutorContractAddress, provider);
break;
}
case 'Curve': {
if (path.length > 1) {
throw new Error('Supporting only single stable swap on curve');

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js';

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js';

View File

@@ -1,6 +1,6 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import type Unit from '../index.js';

View File

@@ -4,7 +4,7 @@ import {pmmOrderSchema} from "./schemas/order";
import {simpleFetch} from "simple-typed-fetch";
import {ethers, Wallet} from "ethers";
import {BigNumber} from "bignumber.js";
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import {orionRFQContractABI} from "./abi/OrionRFQ";
export default class Pmm {

View File

@@ -1 +1 @@
export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3"] as const
export default ["UniswapV2", "UniswapV3", "Curve", "OrionV2", "OrionV3", "Aero"] as const

View File

@@ -1,4 +1,4 @@
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import { ethers } from 'ethers';
import invariant from 'tiny-invariant';

View File

@@ -1,4 +1,4 @@
import { ERC20__factory, Exchange__factory, type Exchange } from "@orionprotocol/contracts/lib/ethers-v6/index.js";
import { ERC20__factory, Exchange__factory, type Exchange } from "@orionprotocol/contracts/lib/ethers-v6-cjs/index.js";
import type { BigNumber } from "bignumber.js";
import { ZeroAddress, ethers } from "ethers";
import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION } from "../constants/index.js";
@@ -195,5 +195,5 @@ export async function getTotalBalance(
walletBalance,
exchangeBalance,
totalBalance: walletBalance + exchangeBalance
}
}
}

View File

@@ -1,4 +1,4 @@
import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import type { BigNumber } from 'bignumber.js';
import type { ethers } from 'ethers';
import type { Aggregator } from '../services/Aggregator/index.js';

View File

@@ -1,4 +1,4 @@
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js';
import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6-cjs/index.js';
import { ethers } from 'ethers';
import { z } from 'zod';