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

Splash #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to Dexter will be documented in this file.

## [v5.4.9]
- Splash integration

## [v5.4.0]
- SundaeSwap v3 integration

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/wingriders.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/wingridersv2.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/vyfinance.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/teddyswap.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/spectrum.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/splash.png" width="30" />
</div>

### What You Can Do
Expand Down
54 changes: 52 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indigo-labs/dexter",
"version": "5.4.8",
"version": "5.4.9",
"license": "MIT",
"author": "Zachary Sluder",
"keywords": [
Expand All @@ -22,11 +22,15 @@
"prepublishOnly": "npm run test"
},
"dependencies": {
"@types/blake2b": "^2.1.3",
"@types/crypto-js": "^4.1.1",
"axios": "^0.26.1",
"axios-retry": "^3.5.1",
"blake2b": "^2.1.4",
"bottleneck": "^2.19.5",
"crypto-js": "^4.1.1",
"int64-buffer": "^1.0.1",
"js-encoding-utils": "^0.7.3",
"lodash": "^4.17.21",
"lucid-cardano": "^0.10.9"
},
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum DatumParameterKey {
/**
* Swap/wallet info.
*/
Address = 'Address',
SenderPubKeyHash = 'SenderPubKeyHash',
SenderStakingKeyHash = 'SenderStakingKeyHash',
SenderKeyHashes = 'SenderKeyHashes',
Expand All @@ -32,6 +33,10 @@ export enum DatumParameterKey {
Expiration = 'Expiration',
AllowPartialFill = 'AllowPartialFill',
Direction = 'Direction',
FeePaymentKeyHash = 'FeePaymentKeyHash',
Beacon = 'Beacon',
Batcher = 'Batcher',
InToken = 'InToken',

/**
* Trading fees.
Expand All @@ -41,6 +46,7 @@ export enum DatumParameterKey {
DepositFee = 'DepositFee',
ScooperFee = 'ScooperFee',
BaseFee = 'BaseFee',
ExecutionFee = 'ExecutionFee',
FeeSharingNumerator = 'FeeSharingNumerator',
OpeningFee = 'OpeningFee',
FinalFee = 'FinalFee',
Expand Down
63 changes: 0 additions & 63 deletions src/dex/api/spectrum-api.ts

This file was deleted.

77 changes: 77 additions & 0 deletions src/dex/api/splash-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { BaseApi } from './base-api';
import { Asset, Token } from '../models/asset';
import { LiquidityPool } from '../models/liquidity-pool';
import axios, { AxiosInstance } from 'axios';
import { RequestConfig } from '@app/types';
import { appendSlash } from '@app/utils';
import { Splash } from '@dex/splash';

const MAX_INT: bigint = 9_223_372_036_854_775_807n;

export class SplashApi extends BaseApi {

protected readonly api: AxiosInstance;
protected readonly dex: Splash;

constructor(dex: Splash, requestConfig: RequestConfig) {
super();

this.dex = dex;

this.api = axios.create({
timeout: requestConfig.timeout,
baseURL: `${appendSlash(requestConfig.proxyUrl)}https://api5.splash.trade/platform-api/v1/`,
withCredentials: false,
});
}

async liquidityPools(assetA: Token, assetB?: Token): Promise<LiquidityPool[]> {
const assets: any = (await this.assets()).data['tokens'];

return this.api.get('/pools/overview?verified=false&duplicated=false').then((response: any) => {
return response.data.map((pool: any) => this.liquidityPoolFromResponse(pool, assets)) as LiquidityPool[];
});
}

private liquidityPoolFromResponse(poolData: any, assets: any): LiquidityPool {
poolData = poolData.pool;

const tokenA: Token = poolData.x.asset === '.'
? 'lovelace'
: new Asset(poolData.x.asset.split('.')[0], poolData.x.asset.split('.')[1]);
const tokenB = poolData.y.asset === '.'
? 'lovelace'
: new Asset(poolData.y.asset.split('.')[0], poolData.y.asset.split('.')[1]);

if (tokenA !== 'lovelace' && tokenA.identifier('.') in assets) {
tokenA.decimals = assets[tokenA.identifier('.')].decimals;
}
if (tokenB !== 'lovelace' && tokenB.identifier('.') in assets) {
tokenB.decimals = assets[tokenB.identifier('.')].decimals;
}

const liquidityPool: LiquidityPool = new LiquidityPool(
Splash.identifier,
tokenA,
tokenB,
BigInt(poolData['x']['amount']) - BigInt(poolData['treasuryX']),
BigInt(poolData['y']['amount']) - BigInt(poolData['treasuryY']),
'',
'',
'',
);

const [lpTokenPolicyId, lpTokenAssetName] = poolData['lq']['asset'].split('.');

liquidityPool.lpToken = new Asset(lpTokenPolicyId, lpTokenAssetName);
liquidityPool.totalLpTokens = MAX_INT - BigInt(poolData['lq']['amount']);
liquidityPool.identifier = poolData['id'];

return liquidityPool;
}

private assets(): Promise<any> {
return axios.get('https://spectrum.fi/cardano-token-list-v2.json');
}

}
62 changes: 0 additions & 62 deletions src/dex/api/teddyswap-api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/dex/base-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class BaseDex {
/**
* Craft a swap order for this DEX.
*/
abstract buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos?: SpendUTxO[]): Promise<PayToAddress[]>;
abstract buildSwapOrder(liquidityPool: LiquidityPool, swapParameters: DatumParameters, spendUtxos?: SpendUTxO[], dataProvider?: BaseDataProvider): Promise<PayToAddress[]>;

/**
* Craft a swap order cancellation for this DEX.
Expand Down
Loading
Loading