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

feat: add DLN api client #1072

Merged
merged 20 commits into from
Dec 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
env:
DEVNET_RPC_URL: "http://localhost:8899"
DEVNET_WEBSOCKET_URL: "ws://localhost:8900"
SCOPE: --scope="espressocash_backend" --scope="espressocash_api" --scope="jupiter_aggregator"
SCOPE: --scope="espressocash_backend" --scope="espressocash_api" --scope="jupiter_aggregator" --scope="dln_api"
EC_LINKS_ID: "7rE2We9zMQzj2xmhJRTvYXKP22VKDGh3krujdBqWibBL"
EC_LINKS_SO: "packages/espressocash_backend/test/bpf-programs/ec_shareable_links.so"
steps:
Expand Down
12 changes: 12 additions & 0 deletions packages/espressocash_backend/dln_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

bin/
3 changes: 3 additions & 0 deletions packages/espressocash_backend/dln_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

- Initial version.
1 change: 1 addition & 0 deletions packages/espressocash_backend/dln_api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile
2 changes: 2 additions & 0 deletions packages/espressocash_backend/dln_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mews_pedantic/analysis_options.yaml
7 changes: 7 additions & 0 deletions packages/espressocash_backend/dln_api/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
targets:
$default:
builders:
json_serializable:
options:
explicit_to_json: true
include_if_null: false
4 changes: 4 additions & 0 deletions packages/espressocash_backend/dln_api/lib/dln_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'src/client.dart';
export 'src/models/chains.dart';
export 'src/models/dto.dart';
export 'src/models/models.dart';
38 changes: 38 additions & 0 deletions packages/espressocash_backend/dln_api/lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:dio/dio.dart';
import 'package:dln_api/src/models/dto.dart';
import 'package:retrofit/retrofit.dart';

part 'client.g.dart';

/// For docs head to https://api.dln.trade/v1.0/#/DLN
@RestApi(baseUrl: 'https://api.dln.trade/v1.0/dln')
abstract class DlnApiClient {
factory DlnApiClient() => _DlnApiClient(Dio());

/// This endpoint returns the recommended take amount for creating DLN order.
@GET('/order/quote')
Future<DlnQuoteResponseDto> getQuote(
@Queries() DlnQuoteRequestDto quoteRequestDto,
);

/// This endpoint returns the data for a transaction to place a cross-chain DLN order.
@GET('/order/create-tx')
Future<CreateTxResponseDto> createTx(
@Queries() CreateTxRequestDto createTxRequestDto,
);

/// This endpoint returns the data of order.
@GET('/order/{id}')
Future<OrderResponseDto> getOrder(@Path() String id);

/// This endpoint returns the status of order.
@GET('/order/{id}/status')
Future<OrderStatusResponseDto> getStatus(@Path() String id);

@GET('/tx/{hash}/order-ids')
Future<OrderIdTxResponseDto> getOrderIdByHash(@Path() String hash);

/// This endpoint generates a transaction that cancels the given order.
@GET('/order/{id}/cancel-tx')
Future<CancelTxResponseDto> cancelTx(@Path() String id);
}
175 changes: 175 additions & 0 deletions packages/espressocash_backend/dln_api/lib/src/client.g.dart

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
enum DlnChains {
arbitrum,
avalanche,
bnb,
ethereum,
polygon,
solana,
linea,
base,
optimism
}

extension DlnChainsExt on DlnChains {
String get name => switch (this) {
DlnChains.arbitrum => 'Arbitrum',
DlnChains.avalanche => 'Avalanche',
DlnChains.bnb => 'Binance Smart Chain',
DlnChains.ethereum => 'Ethereum',
DlnChains.polygon => 'Polygon',
DlnChains.solana => 'Solana',
DlnChains.linea => 'Linea',
DlnChains.base => 'Base',
DlnChains.optimism => 'Optimism',
};

String get chainId => switch (this) {
DlnChains.arbitrum => '42161',
DlnChains.avalanche => '43114',
DlnChains.bnb => '56',
DlnChains.ethereum => '1',
DlnChains.polygon => '137',
DlnChains.solana => '7565164',
DlnChains.linea => '59144',
DlnChains.base => '8453',
DlnChains.optimism => '10',
};
}
Loading
Loading