Skip to content

Commit

Permalink
Merge pull request #99 from Cryptorubic/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ottebrut authored Jun 9, 2022
2 parents 422aada + 5c755f4 commit 38c0441
Show file tree
Hide file tree
Showing 60 changed files with 2,936 additions and 1,733 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ module.exports = {
'class-methods-use-this': 'off',
complexity: ['error', 20],
eqeqeq: ['error', 'smart'],
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': [
'warn',
{
ignore: [-1, 0, 1, 2, 3, 10, 18, 100, 1000, 16, 64, 256],
detectObjects: true,
ignoreReadonlyClassProperties: true
}
],
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down Expand Up @@ -130,15 +121,6 @@ module.exports = {
'class-methods-use-this': 'off',
complexity: ['error', 20],
eqeqeq: ['error', 'smart'],
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': [
'warn',
{
ignore: [-1, 0, 1, 2, 3, 10, 100, 1000, 16, 64, 256, 5000, 10_000],
detectObjects: true,
ignoreReadonlyClassProperties: true
}
],
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down
105 changes: 98 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [sdk.updateConfiguration method](#sdkupdateconfiguration-method)
- [sdk.instantTrades readonly field](#sdkinstanttrades-readonly-field)
- [sdk.crossChain readonly field](#sdkcrosschain-readonly-field)
- [sdk.crossChainSymbiosisManger readonly field](#sdkcrosschainsymbiosismanager-readonly-field)
- [sdk.tokens readonly field](#sdktokens-readonly-field)
- [sdk.web3PublicService readonly field](#sdkweb3publicservice-readonly-field)
- [sdk.web3Private readonly field](#sdkweb3private-readonly-field)
Expand All @@ -47,6 +48,7 @@
- [isZrxLikeTradeLikeTrade function](#iszrxliketradeliketrade-function)
- [Cross Chain Manager](#cross-chain-manager)
- [sdk.crossChain.calculateTrade method](#sdkcrosschaincalculatetrade-method)
- [Wrapped Cross Chain Trade](#wrapped-cross-chain-trade)
- [Cross Chain Trade](#cross-chain-trade)
- [crossChainTrade.swap method](#crosschaintradeswap-method)
- [crossChainTrade.needAapprove method](#crosschaintradeneedapprove-method)
Expand All @@ -55,7 +57,13 @@
- [crossChainTrade.to readonly field](#crosschaintradeto-readonly-field)
- [crossChainTrade.toTokenAmountMin readonly field](#crosschaintradetotokenamountmin-readonly-field)
- [crossChainTrade.estimatedGas getter](#crosschaintradeestimatedgas-getter)
- [Celer Cross Chain Trade and Rubic Cross Chain Trade](#celer-cross-chain-trade-and-rubic-cross-chain-trade)
- [crossChainTrade.priceImpactData getter](#crosschaintradepriceimpactdata-getter)
- [Symbiosis Cross Chain Trade](#symbiosis-cross-chain-trade)
- [crossChainTrade.priceImpact readonly field](#crosschaintradepriceimpact-readonly-field)
- [Cross Chain Symbiosis Manager](#cross-chain-symbiosis-manager)
- [crossChainTrade.getUserTrades method](#crosschainsymbiosismanagergetusertrades-method)
- [crossChainTrade.revertTrade method](#crosschainsymbiosismanagerreverttrade-method)
- [Tokens](#tokens-manager)
- [Tokens Manager](#tokens-manager)
- [tokensManager.createTokenFromStruct method](#tokensmanagercreatetokenfromstruct-method)
Expand Down Expand Up @@ -510,6 +518,16 @@ Cross-chain trades manager object. Use it to calculate and create cross-chain tr
---
#### sdk.crossChainSymbiosisManager readonly field
```typescript
sdk.crossChainSymbiosisManager: CrossChainSymbiosisManager
```
Cross-chain symbiosis manager object. Use it to get pending trades and symbiosis and revert them. [See more.](#cross-chain-symbiosis-manager)
---
#### sdk.tokens readonly field
```typescript
Expand Down Expand Up @@ -950,12 +968,12 @@ sdk.crossChain.calculateTrade(
blockchain: BLOCKCHAIN_NAME;
},
options?: CrossChainOptions
): Promise<CrossChainTrade>
): Promise<WrappedCrossChainTrade>
```

> ℹ️️ You have to set up **rpc provider 🌐** for network in which you will calculate trade.

Method calculates [CrossChainTrade](#cross-chain-trade).
Method calculates [WrappedCrossChainTrade](#wrapped-cross-chain-trade).

**sdk.crossChain.calculateTrade method parameters:**

Expand All @@ -968,21 +986,41 @@ Method calculates [CrossChainTrade](#cross-chain-trade).

**CrossChainOptions description:**

| Option | Type | Description | Default |
|-----------------------|----------|-------------------------------------------------------------------------------------------------------------|---------|
| fromSlippageTolerance | `number` | Swap slippage in range 0 to 1. Defines minimum amount after swap in **first blockchain**. | 0.02 |
| toSlippageTolerance | `number` | Swap slippage in range 0 to 1. Defines minimum amount that you can get after swap in **second blockchain**. | 0.02 |
| Option | Type | Description | Default |
|-----------------------|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------|
| fromSlippageTolerance | `number` | Swap slippage in range 0 to 1. Defines minimum amount after swap in **first blockchain** (for Celer and Rubic). | 0.02 |
| toSlippageTolerance | `number` | Swap slippage in range 0 to 1. Defines minimum amount that you can get after swap in **second blockchain** (for Celer and Rubic). | 0.02 |
| slippageTolerance | `number` | Swap slippage in range 0 to 1. Defines minimum amount that you can get after swap (for Symbiosis). | 0.04 |
| fromAddress | `string` | User wallet address to calculate trade for (for Symbiosis). | Connected wallet address |
| deadline | `number` | Deadline of the trade in minutes (for Symbiosis). | 20 |
| gasCalculation | `'enabled'` &#124; `'disabled'` | Disables or enables gas limit and gas price calclation. | 'enabled' |
| disabledProviders | `CrossChainTradeType[]` | Disables passed providers. | [] |

---

### Wrapped Cross Chain Trade

```typescript
interface WrappedCrossChainTrade {
trade: CrossChainTrade | null;
minAmountError?: BigNumber;
maxAmountError?: BigNumber;
}
```

Wraps cross chain trade and possible min max amount errors. If `minAmountError` or `maxAmountError` are not empty, then you must display an error, because [`swap`](#crosschaintradeswap-method) method will return error.

---

### Cross Chain Trade

Stores information about trade and provides method to make swap.
Extends to types: `CelerCrossChainTrade`, `RubicCrossChainTrade`, `SymbiosisCrossChainTrade`.

#### crossChainTrade.swap method

```typescript
instantTrade.swap(options?: SwapTransactionOptions): Promise<TransactionReceipt>
crossChainTrade.swap(options?: SwapTransactionOptions): Promise<TransactionReceipt>
```

> ℹ️️ You have to set up **wallet provider 👛** for network in which you will execute trade swap.
Expand Down Expand Up @@ -1094,6 +1132,10 @@ Gets gasFee, that is gasLimit * gasPrice. Equals `null` if gas couldn't be calcu

---

### Celer Cross Chain Trade and Rubic Cross Chain Trade

Extend `CrossChainTrade` class.

#### crossChainTrade.priceImpactData getter

```typescript
Expand All @@ -1107,6 +1149,55 @@ Returns price impact in first and second blockchains, based on tokens usd prices

---

### Symbiosis Cross Chain Trade

Extends `CrossChainTrade` class.

#### crossChainTrade.priceImpact readonly field

```typescript
crossChainTrade.priceImpact: number
```

Returns overall price impact, based on symbiosis api.

---

### Cross Chain Symbiosis Manager

Contains methods to work with pending user trades and revert them.

#### crossChainSymbiosisManager.getUserTrades method

```typescript
crossChainSymbiosisManager.getUserTrades(fromAddress?: string): Promise<PendingRequest[]>
```

Returns pending request for `fromAddress` if provided, otherwise for connected wallet address.

---

#### crossChainSymbiosisManager.revertTrade method

```typescript
crossChainSymbiosisManager.revertTrade(
revertTransactionHash: string,
options?: SwapTransactionOptions
): Promise<string | never>
```

Reverts trade, which transaction hash is `revertTransactionHash` for connected wallet address.

**SwapTransactionOptions description:**

| Option | Type | Description | Default |
|------------|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| onConfirm? | `(hash: string) => void` | Callback that will be called after the user signs swap transaction. | Not set. |
| gasPrice? | `string` | Specifies gas price **in wei** for **swap and approve** transactions. Set this parameter only if you know exactly what you are doing. | The value obtained during the calculation of the trade. If value wasn't calculated, it will calculates automatically by user's wallet. |
| gasLimit? | `string` | Specifies gas limit for **swap and approve** transactions. Set this parameter only if you know exactly what you are doing. | The value obtained during the calculation of the trade. If value wasn't calculated, it will calculates automatically by user's wallet. |

---

### Tokens Manager

#### tokensManager.createTokenFromStruct method
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "1.3.5",
"version": "2.0.0",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -61,6 +61,8 @@
"assert": "^2.0.0",
"axios": "^0.22.0",
"bignumber.js": "^9.0.1",
"ethers": "^5.6.8",
"symbiosis-js-sdk": "^2.6.5",
"web3": "~1.7.3"
},
"devDependencies": {
Expand Down Expand Up @@ -91,11 +93,11 @@
"terser-webpack-plugin": "^5.3.0",
"ts-essentials": "^9.0.0",
"ts-jest": "^27.1.2",
"ts-loader": "^9.2.6",
"ts-loader": "^9.3.0",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"tscpaths": "^0.0.9",
"typedoc": "^0.22.15",
"typescript": "^4.4.2",
"typescript": "^4.7.2",
"webpack": "^5.65.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.1"
Expand Down
76 changes: 1 addition & 75 deletions src/core/blockchain/constants/blockchains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Blockchain } from '@core/blockchain/models/blockchain';
import { BLOCKCHAIN_NAME } from '@core/blockchain/models/blockchain-name';
import { Token } from '@core/blockchain/tokens/token';

const mainnetBlockchains: ReadonlyArray<Blockchain> = [
export const blockchains: ReadonlyArray<Blockchain> = [
{
id: 1,
name: BLOCKCHAIN_NAME.ETHEREUM,
Expand Down Expand Up @@ -115,77 +115,3 @@ const mainnetBlockchains: ReadonlyArray<Blockchain> = [
})
}
];

const testnetBlockchains: ReadonlyArray<Blockchain> = [
{
id: 42,
name: BLOCKCHAIN_NAME.KOVAN,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.KOVAN,
address: NATIVE_TOKEN_ADDRESS,
name: 'Ethereum',
symbol: 'ETH',
decimals: 18
})
},
{
id: 97,
name: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET,
address: NATIVE_TOKEN_ADDRESS,
name: 'Binance Coin',
symbol: 'BNB',
decimals: 18
})
},
{
id: 80001,
name: BLOCKCHAIN_NAME.POLYGON_TESTNET,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.POLYGON_TESTNET,
address: NATIVE_TOKEN_ADDRESS,
name: 'Polygon',
symbol: 'MATIC',
decimals: 18
})
},
{
id: 1666700000,
name: BLOCKCHAIN_NAME.HARMONY_TESTNET,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.HARMONY_TESTNET,
address: NATIVE_TOKEN_ADDRESS,
name: 'ONE',
symbol: 'ONE',
decimals: 18
})
},
{
id: 43113,
name: BLOCKCHAIN_NAME.AVALANCHE_TESTNET,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.AVALANCHE_TESTNET,
address: NATIVE_TOKEN_ADDRESS,
name: 'AVAX',
symbol: 'AVAX',
decimals: 18
})
},
{
id: NaN,
name: BLOCKCHAIN_NAME.MOONRIVER_TESTNET,
nativeCoin: new Token({
blockchain: BLOCKCHAIN_NAME.MOONRIVER_TESTNET,
address: NATIVE_TOKEN_ADDRESS,
name: 'MOVR',
symbol: 'MOVR',
decimals: 18
})
}
];

export const blockchains: ReadonlyArray<Blockchain> = [
...mainnetBlockchains,
...testnetBlockchains
];
43 changes: 0 additions & 43 deletions src/core/blockchain/constants/native-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,6 @@ export const nativeTokensList: NativeTokensList = {
symbol: 'aETH',
decimals: 18
},
// Testnets.
[BLOCKCHAIN_NAME.KOVAN]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'Ethereum',
symbol: 'ETH',
decimals: 18
},
[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'Binance Coin',
symbol: 'BNB',
decimals: 18
},
[BLOCKCHAIN_NAME.POLYGON_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'Matic Network',
symbol: 'MATIC',
decimals: 18
},
[BLOCKCHAIN_NAME.AVALANCHE_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'AVAX',
symbol: 'AVAX',
decimals: 18
},
[BLOCKCHAIN_NAME.MOONRIVER_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'MOVR',
symbol: 'MOVR',
decimals: 18
},
[BLOCKCHAIN_NAME.HARMONY_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'ONE',
symbol: 'ONE',
decimals: 18
},
[BLOCKCHAIN_NAME.FANTOM_TESTNET]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'FTM',
symbol: 'FTM',
decimals: 18
},
[BLOCKCHAIN_NAME.TELOS]: {
address: NATIVE_TOKEN_ADDRESS,
name: 'TLOS',
Expand Down
Loading

0 comments on commit 38c0441

Please sign in to comment.