Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yougile-64, Oneinch Fusion+ #720

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ module.exports = {
selector: 'TSEnumDeclaration',
message: "Don't declare enums"
},
'LabeledStatement',
'WithStatement'
],
'no-console': [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "5.41.2",
"version": "5.42.0-alpha.oneinch.29",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AcrossCrossChainProvider } from '../providers/across-provider/across-cr
import { EddyBridgeProvider } from '../providers/eddy-bridge/eddy-bridge-provider';
import { LayerZeroBridgeProvider } from '../providers/layerzero-bridge/layerzero-bridge-provider';
import { MesonCrossChainProvider } from '../providers/meson-provider/meson-cross-chain-provider';
import { OneinchCcrProvider } from '../providers/oneinch-provider/oneinch-ccr-provider';
import { OrbiterBridgeProvider } from '../providers/orbiter-bridge/orbiter-bridge-provider';
import { OwlToBridgeProvider } from '../providers/owl-to-bridge/owl-to-bridge-provider';
import { RangoCrossChainProvider } from '../providers/rango-provider/rango-cross-chain-provider';
Expand All @@ -40,7 +41,8 @@ const proxyProviders = [
EddyBridgeProvider,
RouterCrossChainProvider,
RetroBridgeProvider,
AcrossCrossChainProvider
AcrossCrossChainProvider,
OneinchCcrProvider
] as const;

const nonProxyProviders = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const CROSS_CHAIN_TRADE_TYPE = {
EDDY_BRIDGE: 'eddy_bridge',
ROUTER: 'router',
RETRO_BRIDGE: 'retro_bridge',
ACROSS: 'across'
ACROSS: 'across',
ONEINCH: 'oneinch'
} as const;

export type CrossChainTradeType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export abstract class CrossChainTrade<T = unknown> {
protected checkAmountChange(newWeiAmount: string, oldWeiAmount: string): void {
const oldAmount = new BigNumber(oldWeiAmount);
const newAmount = new BigNumber(newWeiAmount);
const changePercent = 0.5;
const changePercent = 0.001;
const acceptablePercentPriceChange = new BigNumber(changePercent).dividedBy(100);

const amountPlusPercent = oldAmount.multipliedBy(acceptablePercentPriceChange.plus(1));
Expand Down Expand Up @@ -219,11 +219,7 @@ export abstract class CrossChainTrade<T = unknown> {

protected async checkTradeErrors(): Promise<void | never> {
this.checkWalletConnected();
await Promise.all([
this.checkBlockchainCorrect(),
this.checkUserBalance(),
this.checkBlockchainRequirements()
]);
await Promise.all([this.checkBlockchainCorrect(), this.checkUserBalance()]);
}

protected checkWalletConnected(): never | void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ONEINCH_NATIVE_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BLOCKCHAIN_NAME } from 'src/core/blockchain/models/blockchain-name';

export const oneinchCcrSupportedChains = [
BLOCKCHAIN_NAME.ETHEREUM,
BLOCKCHAIN_NAME.OPTIMISM,
// BLOCKCHAIN_NAME.ZK_SYNC, // currently fusion+ doesnt't support zkSync
BLOCKCHAIN_NAME.BASE,
BLOCKCHAIN_NAME.ARBITRUM,
BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN,
BLOCKCHAIN_NAME.POLYGON,
BLOCKCHAIN_NAME.GNOSIS,
BLOCKCHAIN_NAME.AVALANCHE,
BLOCKCHAIN_NAME.FANTOM,
BLOCKCHAIN_NAME.KLAYTN,
BLOCKCHAIN_NAME.AURORA
] as const;

export type OneinchCcrSupportedChain = (typeof oneinchCcrSupportedChains)[number];
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"quoteId": "d1f3d8fb-9f09-4f42-8e07-9e22f92c0d67",
"srcTokenAmount": "100000000",
"dstTokenAmount": "89372434581186672834",
"presets": {
"fast": {
"auctionDuration": 180,
"startAuctionIn": 24,
"initialRateBump": 1826296,
"auctionStartAmount": "99239490737444279620",
"startAmount": "89372440568555126267",
"auctionEndAmount": "83914262536168788284",
"exclusiveResolver": null,
"costInDstToken": "9867057146411228060",
"points": [
{
"delay": 120,
"coefficient": 1253552
},
{
"delay": 60,
"coefficient": 1175849
}
],
"allowPartialFills": false,
"allowMultipleFills": false,
"gasCost": {
"gasBumpEstimate": 1175849,
"gasPriceEstimate": "8614"
},
"secretsCount": 1
},
"medium": {
"auctionDuration": 360,
"startAuctionIn": 24,
"initialRateBump": 1826296,
"auctionStartAmount": "99239490737444279620",
"startAmount": "89372440568555126267",
"auctionEndAmount": "83914262536168788284",
"exclusiveResolver": null,
"costInDstToken": "9867057146411228060",
"points": [
{
"delay": 360,
"coefficient": 1175849
}
],
"allowPartialFills": false,
"allowMultipleFills": false,
"gasCost": {
"gasBumpEstimate": 1175849,
"gasPriceEstimate": "8614"
},
"secretsCount": 1
},
"slow": {
"auctionDuration": 600,
"startAuctionIn": 24,
"initialRateBump": 1826296,
"auctionStartAmount": "99239490737444279620",
"startAmount": "89372440568555126267",
"auctionEndAmount": "83914262536168788284",
"exclusiveResolver": null,
"costInDstToken": "9867057146411228060",
"points": [
{
"delay": 600,
"coefficient": 1175849
}
],
"allowPartialFills": false,
"allowMultipleFills": false,
"gasCost": {
"gasBumpEstimate": 1175849,
"gasPriceEstimate": "8614"
},
"secretsCount": 1
}
},
"timeLocks": {
"srcWithdrawal": 36,
"srcPublicWithdrawal": 204,
"srcCancellation": 360,
"srcPublicCancellation": 480,
"dstWithdrawal": 12,
"dstPublicWithdrawal": 168,
"dstCancellation": 288
},
"srcEscrowFactory": "0xa7bcb4eac8964306f9e3764f67db6a7af6ddf99a",
"dstEscrowFactory": "0xa7bcb4eac8964306f9e3764f67db6a7af6ddf99a",
"srcSafetyDeposit": "1811058409650000",
"dstSafetyDeposit": "1050000000000000",
"whitelist": ["0x33b41fe18d3a39046ad672f8a0c8c415454f629c"],
"recommendedPreset": "fast",
"prices": {
"usd": {
"srcToken": "0.9972668030771942",
"dstToken": "0.9997786589986694"
}
},
"volume": {
"usd": {
"srcToken": "99.73",
"dstToken": "99.22"
}
},
"priceImpactPercent": 0.511,
"autoK": 5.5,
"k": 5.5,
"mxK": 37
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"typedData": {
"primaryType": "Order",
"types": {
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "version",
"type": "string"
},
{
"name": "chainId",
"type": "uint256"
},
{
"name": "verifyingContract",
"type": "address"
}
],
"Order": [
{
"name": "salt",
"type": "uint256"
},
{
"name": "maker",
"type": "address"
},
{
"name": "receiver",
"type": "address"
},
{
"name": "makerAsset",
"type": "address"
},
{
"name": "takerAsset",
"type": "address"
},
{
"name": "makingAmount",
"type": "uint256"
},
{
"name": "takingAmount",
"type": "uint256"
},
{
"name": "makerTraits",
"type": "uint256"
}
]
},
"domain": {
"name": "1inch Aggregation Router",
"version": "6",
"chainId": 1,
"verifyingContract": "0x111111125421ca6dc452d289314280a0f8842a65"
},
"message": {
"maker": "0x2210f8de2f3406aa38e7388c176b5e5c9b8352e8",
"makerAsset": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"takerAsset": "0xda0000d4000015a526378bb6fafc650cea5966f8",
"makerTraits": "62419173104490761595518734106457236408761197002983276552889498510122771546112",
"salt": "102412815603508502318180937246070791509362563834032598598791855802040821868990",
"makingAmount": "100000000",
"takingAmount": "83914262536168788284",
"receiver": "0xa7bcb4eac8964306f9e3764f67db6a7af6ddf99a"
}
},
"orderHash": "0xdaa3823cd11ee80240dbf78619a81e7c2012fb6e1a16efc6670316bede070b2f",
"extension": "0x000001390000005e0000005e0000005e0000005e0000002f0000000000000000a7bcb4eac8964306f9e3764f67db6a7af6ddf99a11f129000021a666fffabf0000b41bddf81320b0007811f129003ca7bcb4eac8964306f9e3764f67db6a7af6ddf99a11f129000021a666fffabf0000b41bddf81320b0007811f129003ca7bcb4eac8964306f9e3764f67db6a7af6ddf99a03e82210f8de2f3406aa38e7388c176b5e5c9b8352e866fffaa772f8a0c8c415454f629c00000a315b47a8c3780434b153667588db4ca628526e20000000000000000000000000000000000000000000000000000000000000000000000000000000000000003800000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000066f25e52cb75000000000000000000003baf82d03a0000000000000000120000000a80000000c000001e000000168000000cc00000024"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { PriceToken, PriceTokenAmount } from 'src/common/tokens';
import { EvmBlockchainName } from 'src/core/blockchain/models/blockchain-name';

export interface OneinchQuoteParams {
srcToken: PriceTokenAmount<EvmBlockchainName>;
dstToken: PriceToken<EvmBlockchainName>;
walletAddress: string;
}

export interface OneinchSwapOrderParams extends OneinchQuoteParams {
quote: OneinchCcrQuoteResponse;
secretHashes: string[];
}

export interface OneinchCcrQuoteResponse {
presets: {
[key in PresetKey]: Preset;
};
quoteId: string;
srcTokenAmount: string;
/** string wei amount */
dstTokenAmount: string;
srcEscrowFactory: string;
dstEscrowFactory: string;
srcSafetyDeposit: string;
dstSafetyDeposit: string;
whitelist: string[];
timeLocks: {
srcWithdrawal: number;
srcPublicWithdrawal: number;
srcCancellation: number;
srcPublicCancellation: number;
dstWithdrawal: number;
dstPublicWithdrawal: number;
dstCancellation: number;
};
prices: object;
volumes: object;
recommendedPreset: PresetKey;
}

type PresetKey = 'fast' | 'slow' | 'medium' | 'custom';

interface Preset {
allowPartialFills: boolean;
allowMultipleFills: boolean;
gasCost: {
gasBumpEstimate: number;
gasPriceEstimate: string;
};
secretsCount: number;
}

export interface OneinchSwapOrderResponse {
typedData: {
primaryType: string;
domain: OneinchOrderDomain;
types: object;
message: OneinchOrderMessage;
};

orderHash: string;
extension: string;
}

interface OneinchOrderMessage {
maker: string;
makerAsset: string;
takerAsset: string;
makerTraits: string;
salt: string;
makingAmount: string;
takingAmount: string;
receiver: string;
}

interface OneinchOrderDomain {
name: string;
version: string;
chainId: number;
verifyingContract: string;
}

export interface OneinchStatusResponse {
orderHash: string;
status: 'pending' | 'executed' | 'expired' | 'cancelled' | 'refunding' | 'refunded';
fills: Array<{
status: string;
txHash: string;
escrowEvents: Array<{
transactionHash: string;
side: 'src' | 'dst';
action:
| 'src_escrow_created'
| 'dst_escrow_created'
| 'withdrawn'
| 'funds_rescued'
| 'escrow_cancelled';
blockTimestamp: number;
}>;
}>;
}

export interface OneinchReadySecretsResponse {
fills: Array<{
idx: number;
srcEscrowDeployTxHash: string;
dstEscrowDeployTxHash: string;
}>;
}

export interface OneinchSecret {
secret: string;
hashedSecret: string;
}
Loading