diff --git a/package-lock.json b/package-lock.json index ebb7752..0196ef9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.88-rc0", + "version": "0.19.88-rc1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.19.88-rc0", + "version": "0.19.88-rc1", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 345113a..426e014 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.88-rc0", + "version": "0.19.88-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index e96b992..c781c28 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -7,47 +7,27 @@ import type Unit from '../index.js'; import { simpleFetch } from 'simple-typed-fetch'; import type { PromiseOrValue } from '@orionprotocol/contracts/lib/ethers-v5/common.js'; -const EXECUTOR_SWAP_FUNCTION = "func_70LYiww" - -export type Factory = "UniswapV2" | "UniswapV3" | "Curve" | "OrionV2" | "OrionV3" - -const exchangeToType: Partial> = { - 'SPOOKYSWAP': 'UniswapV2', - 'PANCAKESWAP': 'UniswapV2', - 'UNISWAP': 'UniswapV2', - 'QUICKSWAP': 'UniswapV2', - 'ORION_POOL': 'UniswapV2', - 'CHERRYSWAP': 'UniswapV2', - 'OKXSWAP': 'UniswapV2', - 'INTERNAL_POOL_V2': 'UniswapV2', - 'INTERNAL_POOL_V3': "OrionV3", - 'INTERNAL_POOL_V3_0_01': "OrionV3", - 'INTERNAL_POOL_V3_0_05': "OrionV3", - 'INTERNAL_POOL_V3_0_3': "OrionV3", - 'INTERNAL_POOL_V3_1_0': "OrionV3", - 'CURVE': "Curve", - 'CURVE_FACTORY': "Curve", -} +const EXECUTOR_SWAP_FUNCTION = 'func_70LYiww' export type SwapInfo = { - pool: string, - assetIn: string, - assetOut: string, + pool: string + assetIn: string + assetOut: string factory: string } export type CallParams = { - isMandatory?: boolean, - target?: string, - gaslimit?: BigNumber, + isMandatory?: boolean + target?: string + gaslimit?: BigNumber value?: BigNumber } export type GenerateSwapCalldataParams = { - amount: BigNumberish, - minReturnAmount: BigNumberish, - receiverAddress: string, - path: ArrayLike, + amount: BigNumberish + minReturnAmount: BigNumberish + receiverAddress: string + path: ArrayLike unit: Unit } @@ -60,28 +40,27 @@ export default async function generateSwapCalldata({ }: GenerateSwapCalldataParams ): Promise<{ calldata: string, swapDescription: ExchangeWithGenericSwap.SwapDescriptionStruct }> { if (path_ == undefined || path_.length == 0) { - throw new Error(`Empty path`); + throw new Error('Empty path'); } - const wethAddress = safeGet(unit.contracts, "WETH") - const curveRegistryAddress = safeGet(unit.contracts, "curveRegistry") + const wethAddress = safeGet(unit.contracts, 'WETH') + const curveRegistryAddress = safeGet(unit.contracts, 'curveRegistry') const { assetToAddress, swapExecutorContractAddress, exchangeContractAddress } = await simpleFetch(unit.blockchainService.getInfo)(); let path = SafeArray.from(path_).map((swapInfo) => { swapInfo.assetIn = safeGet(assetToAddress, swapInfo.assetIn); swapInfo.assetOut = safeGet(assetToAddress, swapInfo.assetOut); - return swapInfo; + return swapInfo; }) const factory = path.first().factory if (!path.every(swapInfo => swapInfo.factory === factory)) { - throw new Error(`Supporting only swaps with single factory`); + throw new Error('Supporting only swaps with single factory'); } - const swapDescription: ExchangeWithGenericSwap.SwapDescriptionStruct = { srcToken: path.first().assetIn, dstToken: path.last().assetOut, srcReceiver: swapExecutorContractAddress ?? '', dstReceiver: receiverAddress, - amount: amount, - minReturnAmount: minReturnAmount, + amount, + minReturnAmount, flags: 0 } @@ -101,29 +80,28 @@ export default async function generateSwapCalldata({ if (swapInfo.assetOut == ethers.constants.AddressZero) swapInfo.assetOut = wethAddress return swapInfo; }); - let calldata: string - switch (exchangeToType[factory]) { - case "OrionV2": { + switch (factory) { + case 'OrionV2': { swapDescription.srcReceiver = path.first().pool calldata = await generateUni2Calls(exchangeContractAddress, path); break; } - case "UniswapV2": { + case 'UniswapV2': { swapDescription.srcReceiver = path.first().pool calldata = await generateUni2Calls(exchangeContractAddress, path); break; } - case "UniswapV3": { + case 'UniswapV3': { calldata = await generateUni3Calls(amountNativeDecimals, exchangeContractAddress, path, unit.provider) break; } - case "OrionV3": { + case 'OrionV3': { calldata = await generateOrion3Calls(amountNativeDecimals, exchangeContractAddress, path, unit.provider) break; } - case "Curve": { + case 'Curve': { calldata = await generateCurveStableSwapCalls( amountNativeDecimals, exchangeContractAddress, @@ -152,26 +130,26 @@ export async function generateUni2Calls( const currentSwap = path.get(i) const nextSwap = path.get(i + 1) - const calldata = executorInterface.encodeFunctionData("swapUniV2", [ + const calldata = executorInterface.encodeFunctionData('swapUniV2', [ currentSwap.pool, currentSwap.assetIn, currentSwap.assetOut, - defaultAbiCoder.encode(["uint256"], [concat(["0x03", nextSwap.pool])]), + defaultAbiCoder.encode(['uint256'], [concat(['0x03', nextSwap.pool])]), ] ) calls.push(addCallParams(calldata)) } } const lastSwap = path.last(); - const calldata = executorInterface.encodeFunctionData("swapUniV2", [ + const calldata = executorInterface.encodeFunctionData('swapUniV2', [ lastSwap.pool, lastSwap.assetIn, lastSwap.assetOut, - defaultAbiCoder.encode(["uint256"], [concat(["0x03", exchangeAddress])]), + defaultAbiCoder.encode(['uint256'], [concat(['0x03', exchangeAddress])]), ]) calls.push(addCallParams(calldata)) - return generateCalls(calls) + return await generateCalls(calls) } async function generateUni3Calls( @@ -187,20 +165,20 @@ async function generateUni3Calls( const zeroForOne = token0.toLowerCase() === swap.assetIn.toLowerCase() const unwrapWETH = swap.assetOut === ethers.constants.AddressZero - let encodedPool = ethers.utils.solidityPack(["uint256"], [pool.address]) + let encodedPool = ethers.utils.solidityPack(['uint256'], [pool.address]) encodedPool = ethers.utils.hexDataSlice(encodedPool, 1) let firstByte = 0 if (unwrapWETH) firstByte += 32 if (!zeroForOne) firstByte += 128 - const encodedFirstByte = ethers.utils.solidityPack(["uint8"], [firstByte]) + const encodedFirstByte = ethers.utils.solidityPack(['uint8'], [firstByte]) encodedPool = ethers.utils.hexlify(ethers.utils.concat([encodedFirstByte, encodedPool])) encodedPools.push(encodedPool) } const executorInterface = SwapExecutor__factory.createInterface() - let calldata = executorInterface.encodeFunctionData("uniswapV3SwapTo", [encodedPools, exchangeContractAddress, amount]) + let calldata = executorInterface.encodeFunctionData('uniswapV3SwapTo', [encodedPools, exchangeContractAddress, amount]) calldata = addCallParams(calldata) - return generateCalls([calldata]) + return await generateCalls([calldata]) } async function generateOrion3Calls( @@ -216,20 +194,20 @@ async function generateOrion3Calls( const zeroForOne = token0.toLowerCase() === swap.assetIn.toLowerCase() const unwrapWETH = swap.assetOut === ethers.constants.AddressZero - let encodedPool = ethers.utils.solidityPack(["uint256"], [pool.address]) + let encodedPool = ethers.utils.solidityPack(['uint256'], [pool.address]) encodedPool = ethers.utils.hexDataSlice(encodedPool, 1) let firstByte = 0 if (unwrapWETH) firstByte += 32 if (!zeroForOne) firstByte += 128 - const encodedFirstByte = ethers.utils.solidityPack(["uint8"], [firstByte]) + const encodedFirstByte = ethers.utils.solidityPack(['uint8'], [firstByte]) encodedPool = ethers.utils.hexlify(ethers.utils.concat([encodedFirstByte, encodedPool])) encodedPools.push(encodedPool) } const executorInterface = SwapExecutor__factory.createInterface() - let calldata = executorInterface.encodeFunctionData("orionV3SwapTo", [encodedPools, exchangeContractAddress, amount]) + let calldata = executorInterface.encodeFunctionData('orionV3SwapTo', [encodedPools, exchangeContractAddress, amount]) calldata = addCallParams(calldata) - return generateCalls([calldata]) + return await generateCalls([calldata]) } async function generateCurveStableSwapCalls( @@ -241,7 +219,7 @@ async function generateCurveStableSwapCalls( curveRegistry: string ) { if (path.length > 1) { - throw new Error("Supporting only single stable swap on curve") + throw new Error('Supporting only single stable swap on curve') } const executorInterface = SwapExecutor__factory.createInterface() const registry = CurveRegistry__factory.connect(curveRegistry, provider) @@ -255,7 +233,7 @@ async function generateCurveStableSwapCalls( const calls: BytesLike[] = [] if (executorAllowance.lt(amount)) { const calldata = addCallParams( - executorInterface.encodeFunctionData("safeApprove", [ + executorInterface.encodeFunctionData('safeApprove', [ swap.assetIn, swap.pool, ethers.constants.MaxUint256 @@ -263,7 +241,7 @@ async function generateCurveStableSwapCalls( ) calls.push(calldata) } - let calldata = executorInterface.encodeFunctionData("curveSwapStableAmountIn", [ + let calldata = executorInterface.encodeFunctionData('curveSwapStableAmountIn', [ pool, assetOut, i, @@ -275,7 +253,7 @@ async function generateCurveStableSwapCalls( calldata = addCallParams(calldata) calls.push(calldata) - return generateCalls(calls) + return await generateCalls(calls) } // Adds additional byte to single swap with settings @@ -285,31 +263,30 @@ function addCallParams( ) { let firstByte = 0 if (callParams) { - if (callParams.value !== undefined) { + if (callParams.value !== undefined) { firstByte += 16 // 00010000 - const encodedValue = ethers.utils.solidityPack(["uint128"], [callParams.value]) + const encodedValue = ethers.utils.solidityPack(['uint128'], [callParams.value]) calldata = ethers.utils.hexlify(ethers.utils.concat([encodedValue, calldata])) } if (callParams.target !== undefined) { firstByte += 32 // 00100000 - const encodedAddress = ethers.utils.solidityPack(["address"], [callParams.target]) + const encodedAddress = ethers.utils.solidityPack(['address'], [callParams.target]) calldata = ethers.utils.hexlify(ethers.utils.concat([encodedAddress, calldata])) } if (callParams.gaslimit !== undefined) { firstByte += 64 // 01000000 - const encodedGaslimit = ethers.utils.solidityPack(["uint32"], [callParams.gaslimit]) + const encodedGaslimit = ethers.utils.solidityPack(['uint32'], [callParams.gaslimit]) calldata = ethers.utils.hexlify(ethers.utils.concat([encodedGaslimit, calldata])) } if (callParams.isMandatory !== undefined) firstByte += 128 // 10000000 } - const encodedFirstByte = ethers.utils.solidityPack(["uint8"], [firstByte]) + const encodedFirstByte = ethers.utils.solidityPack(['uint8'], [firstByte]) calldata = ethers.utils.hexlify(ethers.utils.concat([encodedFirstByte, calldata])) return calldata } - async function generateCalls(calls: BytesLike[]) { const executorInterface = SwapExecutor__factory.createInterface() - return "0x" + executorInterface.encodeFunctionData(EXECUTOR_SWAP_FUNCTION, [ethers.constants.AddressZero, calls]).slice(74) + return '0x' + executorInterface.encodeFunctionData(EXECUTOR_SWAP_FUNCTION, [ethers.constants.AddressZero, calls]).slice(74) } diff --git a/src/config/chains.json b/src/config/chains.json index ea3dd8e..33b7724 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -5,7 +5,7 @@ "label": "Ethereum", "shortName": "ETH", "code": "eth", - "rpc": "https://trade.orionprotocol.io/eth-mainnet/rpc", + "rpc": "https://trade.orion.xyz/eth-mainnet/rpc", "baseCurrencyName": "ETH", "contracts": { "WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", @@ -44,7 +44,7 @@ "label": "Ropsten", "shortName": "ETH-Ropsten", "code": "eth", - "rpc": "https://testing.orionprotocol.io/eth-ropsten/rpc", + "rpc": "https://testing.orion.xyz/eth-ropsten/rpc", "baseCurrencyName": "ETH", "contracts": { "WETH": "", @@ -57,7 +57,7 @@ "label": "Goerli", "shortName": "ETH-Goerli", "code": "eth", - "rpc": "https://testing.orionprotocol.io/eth-goerli/rpc", + "rpc": "https://testing.orion.xyz/eth-goerli/rpc", "baseCurrencyName": "ETH", "contracts": { "WETH": "", diff --git a/src/config/envs.json b/src/config/envs.json index fd2bb30..1c193bf 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -1,10 +1,10 @@ { "production": { - "analyticsAPI": "https://trade.orionprotocol.io/api/stats", - "referralAPI": "https://trade.orionprotocol.io/referral-api", + "analyticsAPI": "https://trade.orion.xyz/api/stats", + "referralAPI": "https://trade.orion.xyz/referral-api", "networks": { "1": { - "api": "https://trade.orionprotocol.io/eth-mainnet", + "api": "https://trade.orion.xyz/eth-mainnet", "services": { "aggregator": { "http": "/backend", @@ -20,7 +20,7 @@ "liquidityMigratorAddress": "0x23a1820a47BcD022E29f6058a5FD224242F50D1A" }, "56": { - "api": "https://trade.orionprotocol.io/bsc-mainnet", + "api": "https://trade.orion.xyz/bsc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -35,7 +35,7 @@ } }, "250": { - "api": "https://trade.orionprotocol.io/ftm-mainnet", + "api": "https://trade.orion.xyz/ftm-mainnet", "services": { "aggregator": { "http": "/backend", @@ -50,7 +50,7 @@ } }, "137": { - "api": "https://trade.orionprotocol.io/polygon-mainnet", + "api": "https://trade.orion.xyz/polygon-mainnet", "services": { "aggregator": { "http": "/backend", @@ -65,7 +65,7 @@ } }, "66": { - "api": "https://trade.orionprotocol.io/okc-mainnet", + "api": "https://trade.orion.xyz/okc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -82,11 +82,11 @@ } }, "testing": { - "analyticsAPI": "https://trade.orionprotocol.io/api/stats", - "referralAPI": "https://testing.orionprotocol.io/referral-api", + "analyticsAPI": "https://trade.orion.xyz/api/stats", + "referralAPI": "https://testing.orion.xyz/referral-api", "networks": { "97": { - "api": "https://testing.orionprotocol.io/bsc-testnet", + "api": "https://testing.orion.xyz/bsc-testnet", "services": { "aggregator": { "http": "/backend", @@ -102,7 +102,7 @@ "liquidityMigratorAddress": "0x01b10dds12478C88A5E18e2707E729906bC25CfF6" }, "5": { - "api": "https://testing.orionprotocol.io/eth-goerli", + "api": "https://testing.orion.xyz/eth-goerli", "services": { "aggregator": { "http": "/backend", @@ -117,7 +117,7 @@ } }, "421613": { - "api": "https://testing.orionprotocol.io/arbitrum-goerli", + "api": "https://testing.orion.xyz/arbitrum-goerli", "services": { "aggregator": { "http": "/backend", @@ -132,7 +132,7 @@ } }, "4002": { - "api": "https://testing.orionprotocol.io/ftm-testnet", + "api": "https://testing.orion.xyz/ftm-testnet", "services": { "aggregator": { "http": "/backend", @@ -147,7 +147,7 @@ } }, "80001": { - "api": "https://testing.orionprotocol.io/polygon-mumbai", + "api": "https://testing.orion.xyz/polygon-mumbai", "services": { "aggregator": { "http": "/backend", @@ -162,7 +162,7 @@ } }, "56303": { - "api": "https://testing.orionprotocol.io/drip-testnet", + "api": "https://testing.orion.xyz/drip-testnet", "services": { "aggregator": { "http": "/backend", @@ -179,11 +179,11 @@ } }, "staging": { - "analyticsAPI": "https://trade.orionprotocol.io/api/stats", - "referralAPI": "https://staging.orionprotocol.io/referral-api", + "analyticsAPI": "https://trade.orion.xyz/api/stats", + "referralAPI": "https://staging.orion.xyz/referral-api", "networks": { "1": { - "api": "https://staging.orionprotocol.io/eth-mainnet", + "api": "https://staging.orion.xyz/eth-mainnet", "services": { "aggregator": { "http": "/backend", @@ -198,7 +198,7 @@ } }, "56": { - "api": "https://staging.orionprotocol.io/bsc-mainnet", + "api": "https://staging.orion.xyz/bsc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -213,7 +213,7 @@ } }, "250": { - "api": "https://staging.orionprotocol.io/ftm-mainnet", + "api": "https://staging.orion.xyz/ftm-mainnet", "services": { "aggregator": { "http": "/backend", @@ -228,7 +228,7 @@ } }, "137": { - "api": "https://staging.orionprotocol.io/polygon-mainnet", + "api": "https://staging.orion.xyz/polygon-mainnet", "services": { "aggregator": { "http": "/backend", @@ -243,7 +243,7 @@ } }, "66": { - "api": "https://staging.orionprotocol.io/okc-mainnet", + "api": "https://staging.orion.xyz/okc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -260,11 +260,11 @@ } }, "experimental": { - "analyticsAPI": "https://trade.orionprotocol.io/api/stats", - "referralAPI": "https://testing.orionprotocol.io/referral-api", + "analyticsAPI": "https://trade.orion.xyz/api/stats", + "referralAPI": "https://testing.orion.xyz/referral-api", "networks": { "97": { - "api": "https://dn-dev.orionprotocol.io/bsc-testnet", + "api": "https://dn-dev.orion.xyz/bsc-testnet", "services": { "aggregator": { "http": "/backend", @@ -279,7 +279,7 @@ } }, "3": { - "api": "https://dn-dev.orionprotocol.io/eth-ropsten", + "api": "https://dn-dev.orion.xyz/eth-ropsten", "services": { "aggregator": { "http": "/backend", @@ -296,11 +296,11 @@ } }, "kucoin-production": { - "analyticsAPI": "https://trade.orionprotocol.io/api/stats", - "referralAPI": "https://trade.orionprotocol.io/referral-api", + "analyticsAPI": "https://trade.orion.xyz/api/stats", + "referralAPI": "https://trade.orion.xyz/referral-api", "networks": { "1": { - "api": "https://trade.orionprotocol.io/eth-mainnet", + "api": "https://trade.orion.xyz/eth-mainnet", "services": { "aggregator": { "http": "/backend", @@ -316,7 +316,7 @@ "liquidityMigratorAddress": "0x23a1820a47BcD022E29f6058a5FD224242F50D1A" }, "56": { - "api": "https://trade.orionprotocol.io/bsc-mainnet", + "api": "https://trade.orion.xyz/bsc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -331,7 +331,7 @@ } }, "250": { - "api": "https://trade.orionprotocol.io/ftm-mainnet", + "api": "https://trade.orion.xyz/ftm-mainnet", "services": { "aggregator": { "http": "/backend", @@ -346,7 +346,7 @@ } }, "137": { - "api": "https://trade.orionprotocol.io/polygon-mainnet", + "api": "https://trade.orion.xyz/polygon-mainnet", "services": { "aggregator": { "http": "/backend", @@ -361,7 +361,7 @@ } }, "66": { - "api": "https://trade.orionprotocol.io/okc-mainnet", + "api": "https://trade.orion.xyz/okc-mainnet", "services": { "aggregator": { "http": "/backend", @@ -377,4 +377,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts index c03ff97..288838b 100644 --- a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts +++ b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts @@ -37,7 +37,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({ p: z.string(), // pool address ai: z.string().toUpperCase(), // asset in ao: z.string().toUpperCase(), // asset out - f: z.string().toUpperCase(), // factory + f: z.string(), // factory })) }); diff --git a/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts b/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts index 620aef0..3597bd9 100644 --- a/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts +++ b/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts @@ -15,8 +15,16 @@ const distinctAnalyticsSchema = z.object({ latest_block: z.number(), }), ), - total_earned: z.number(), total_sent_to_governance: z.number(), + total_earned: z.number(), + total_volume: z.number(), + total_trades: z.number(), + all_time_earnings_boost_only: z.number(), + all_time_earnings_boost_only_usd: z.number(), + all_time_earnings: z.number(), + all_time_earnings_usd: z.number(), + all_weekly_earnings: z.number(), + all_weekly_earnings_usd: z.number(), }); export default distinctAnalyticsSchema; diff --git a/src/services/ReferralSystem/schemas/ratingSchema.ts b/src/services/ReferralSystem/schemas/ratingSchema.ts index c72b70b..57489bb 100644 --- a/src/services/ReferralSystem/schemas/ratingSchema.ts +++ b/src/services/ReferralSystem/schemas/ratingSchema.ts @@ -4,6 +4,8 @@ const ratingSchema = z.object({ info: z.object({ weekly_boost_budget: z.string(), weekly_boost_budget_fmt: z.number(), + monthly_boost_budget: z.string(), + monthly_boost_budget_fmt: z.number(), time_left_for_the_reward: z.number(), time_left_for_the_reward_local: z.string(), time_left_for_the_reward_utc: z.string(), @@ -33,6 +35,11 @@ const ratingSchema = z.object({ weighted_volume_fmt: z.number(), total_weight: z.string(), total_weight_fmt: z.number(), + total_volume_fmt: z.number(), + weekly_earnings_fmt: z.number(), + total_earnings_fmt: z.number(), + referrals_count_fmt: z.number(), + total_trades_fmt: z.number(), reward: z.string(), reward_fmt: z.number() })),