Skip to content

Commit 20cdadd

Browse files
authored
Merge pull request #45 from deltadefi-protocol/feat-internal-transfer
Feat internal transfer
2 parents 3ede5a7 + cd6de2c commit 20cdadd

File tree

6 files changed

+137
-28
lines changed

6 files changed

+137
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@deltadefi-protocol/sdk",
33
"description": "The Typescript SDK for DeltaDeFi protocol",
4-
"version": "0.3.29",
4+
"version": "0.3.30",
55
"main": "./dist/index.cjs",
66
"browser": "./dist/index.js",
77
"module": "./dist/index.js",

src/client/accounts/index.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ import {
2424
BuildTransferalTransactionResponse,
2525
SubmitTransferalTransactionRequest,
2626
SubmitTransferalTransactionResponse,
27+
BuildTransferalRequestTransactionRequest,
28+
BuildTransferalRequestTransactionResponse,
29+
SubmitTransferalRequestTransactionRequest,
30+
SubmitTransferalRequestTransactionResponse,
31+
GetTransferalRecordsResponse,
32+
GetTransferalRecordsRequest,
33+
GetTransferalRecordByTxHashRequest,
34+
GetTransferalRecordByTxHashResponse,
2735
} from '../../types';
2836
import { Api } from '../api';
2937

@@ -116,6 +124,30 @@ export class Accounts extends Api {
116124
return this.resolveAxiosData(res);
117125
}
118126

127+
/**
128+
* Retrieves transferal records.
129+
* @param data - The transferal records request parameters.
130+
* @returns A promise that resolves to the transferal records response.
131+
*/
132+
public getTransferalRecords(
133+
data: GetTransferalRecordsRequest,
134+
): Promise<GetTransferalRecordsResponse> {
135+
const res = this.axiosInstance.get(`/accounts/transferal-records`, { params: data });
136+
return this.resolveAxiosData(res);
137+
}
138+
139+
/**
140+
* Retrieves a single transferal record by transaction hash.
141+
* @param txHash - The transaction hash of the transferal record to retrieve.
142+
* @returns A promise that resolves to the transferal record response.
143+
*/
144+
public getTransferalRecordByTxHash(
145+
data: GetTransferalRecordByTxHashRequest,
146+
): Promise<GetTransferalRecordByTxHashResponse> {
147+
const res = this.axiosInstance.get(`/accounts/transferal-records/${data.tx_hash}`);
148+
return this.resolveAxiosData(res);
149+
}
150+
119151
/**
120152
* Retrieves account balance.
121153
* @returns A promise that resolves to the account balance response.
@@ -184,6 +216,18 @@ export class Accounts extends Api {
184216
return this.resolveAxiosData(res);
185217
}
186218

219+
/**
220+
* Builds a transferal request transaction.
221+
* @param data - The build transferal transaction request data.
222+
* @returns A promise that resolves to the build transferal transaction response.
223+
*/
224+
public buildTransferalRequestTransaction(
225+
data: BuildTransferalRequestTransactionRequest,
226+
): Promise<BuildTransferalRequestTransactionResponse> {
227+
const res = this.axiosInstance.post('/accounts/request-transferal/build', data);
228+
return this.resolveAxiosData(res);
229+
}
230+
187231
/**
188232
* Submits a deposit transaction.
189233
* @param data - The submit deposit transaction request data.
@@ -213,10 +257,22 @@ export class Accounts extends Api {
213257
* @param data - The submit transferal transaction request data.
214258
* @returns A promise that resolves to the submit transferal transaction response.
215259
*/
216-
public submittransferalTransaction(
260+
public submitTransferalTransaction(
217261
data: SubmitTransferalTransactionRequest,
218262
): Promise<SubmitTransferalTransactionResponse> {
219263
const res = this.axiosInstance.post('/accounts/transferal/submit', data);
220264
return this.resolveAxiosData(res);
221265
}
266+
267+
/**
268+
* Submits a transferal requesttransaction.
269+
* @param data - The submit transferal transaction request data.
270+
* @returns A promise that resolves to the submit transferal transaction response.
271+
*/
272+
public submitTransferalRequestTransaction(
273+
data: SubmitTransferalRequestTransactionRequest,
274+
): Promise<SubmitTransferalRequestTransactionResponse> {
275+
const res = this.axiosInstance.post('/accounts/request-transferal/submit', data);
276+
return this.resolveAxiosData(res);
277+
}
222278
}

src/types/models/account.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Asset } from '../requests';
2+
13
export type AccountBalance = {
24
asset: string;
35
asset_unit: string;
@@ -15,3 +17,17 @@ export type AccountBalanceStream = {
1517
sub_type: 'balance';
1618
balance: AccountBalance[];
1719
};
20+
21+
export type TransferStatus = 'pending' | 'confirmed';
22+
23+
export type TransferalType = 'normal' | 'deposit' | `withdrawal`;
24+
25+
export type TransferDirection = 'incoming' | 'outgoing';
26+
27+
export type TransferalRecord = {
28+
created_at: string;
29+
status: TransferStatus;
30+
assets: Asset[];
31+
tx_hash: string;
32+
direction: TransferDirection;
33+
};

src/types/requests/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UTxO } from '@meshsdk/core';
22
import { TradingSymbol, OrderSide, OrderType } from '../models/order';
3+
import { TransferStatus } from '../models/account';
34

45
// SignInRequest to be refactored
56
export type SignInRequest = {
@@ -46,6 +47,15 @@ export type SubmitTransferalTransactionRequest = {
4647
signed_tx: string;
4748
};
4849

50+
export type BuildTransferalRequestTransactionRequest = {
51+
transferal_amount: Asset[];
52+
from_address: string;
53+
};
54+
55+
export type SubmitTransferalRequestTransactionRequest = {
56+
signed_tx: string;
57+
};
58+
4959
// export type GetMarketDepthRequest = {
5060
// symbol: TradingSymbol;
5161
// };
@@ -91,3 +101,13 @@ export type GetOrderRecordRequest = {
91101
limit?: number; // default number is 10 while number must be between 1 and 250
92102
page?: number; // default number is 1 while number must be between 1 and 1000
93103
};
104+
105+
export type GetTransferalRecordsRequest = {
106+
status: TransferStatus; // Must be either 'pending' | 'confirmed'
107+
limit?: number; // default number is 10 while number must be between 1 and 250
108+
page?: number; // default number is 1 while number must be between 1 and 1000
109+
};
110+
111+
export type GetTransferalRecordByTxHashRequest = {
112+
tx_hash: string;
113+
};

src/types/responses/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OrderJSON, AccountBalance, OrderFillingRecordJSON } from '../models';
1+
import { OrderJSON, AccountBalance, OrderFillingRecordJSON, TransferalRecord } from '../models';
22

33
export type SignInResponse = {
44
token: string;
@@ -86,6 +86,10 @@ export type BuildTransferalTransactionResponse = {
8686
tx_hex: string;
8787
};
8888

89+
export type BuildTransferalRequestTransactionResponse = {
90+
tx_hex: string;
91+
};
92+
8993
export type SubmitDepositTransactionResponse = {
9094
tx_hash: string;
9195
};
@@ -98,6 +102,10 @@ export type SubmitTransferalTransactionResponse = {
98102
tx_hash: string;
99103
};
100104

105+
export type SubmitTransferalRequestTransactionResponse = {
106+
tx_hash: string;
107+
};
108+
101109
export type MarketDepth = {
102110
price: number;
103111
quantity: number;
@@ -143,3 +151,12 @@ export type GetAPIKeyResponse = {
143151
api_key: string;
144152
created_at: string;
145153
};
154+
155+
export type GetTransferalRecordsResponse = {
156+
in: TransferalRecord[];
157+
out: TransferalRecord[];
158+
};
159+
160+
export type GetTransferalRecordByTxHashResponse = {
161+
transferal_record: TransferalRecord;
162+
};

tests/markets.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@
22
/* eslint-disable import/no-extraneous-dependencies */
33
import dotenv from 'dotenv';
44
import { ApiClient } from '../src';
5-
import { MarketDepth } from '../src/types';
5+
// import { MarketDepth } from '../src/types';
66

77
dotenv.config();
88

99
const skipApiTests = process.env.SKIP_API_TESTS === 'true';
1010
const apiKey = process.env.API_KEY || '';
1111

12-
describe('GetDepthResponse', () => {
13-
test('should have correct structure and non-negative values', async () => {
14-
if (skipApiTests) return;
15-
const api = new ApiClient({ apiKey, network: 'preprod' });
16-
const res = await api.markets.getDepth({ symbol: 'ADAUSDM' });
12+
// describe('GetDepthResponse', () => {
13+
// test('should have correct structure and non-negative values', async () => {
14+
// if (skipApiTests) return;
15+
// const api = new ApiClient({ apiKey, network: 'preprod' });
16+
// const res = await api.markets.getDepth({ symbol: 'ADAUSDM' });
1717

18-
console.log('response', res);
18+
// console.log('response', res);
1919

20-
// Check that bids and asks are arrays
21-
expect(Array.isArray(res.bids)).toBe(true);
22-
expect(Array.isArray(res.asks)).toBe(true);
20+
// // Check that bids and asks are arrays
21+
// expect(Array.isArray(res.bids)).toBe(true);
22+
// expect(Array.isArray(res.asks)).toBe(true);
2323

24-
// Check that each bid and ask is a MarketDepth object
25-
res.bids.forEach((bid: MarketDepth) => {
26-
expect(typeof bid.price).toBe('number');
27-
expect(bid.price).toBeGreaterThanOrEqual(0);
28-
expect(typeof bid.quantity).toBe('number');
29-
expect(bid.quantity).toBeGreaterThanOrEqual(0);
30-
});
31-
res.asks.forEach((ask: MarketDepth) => {
32-
expect(typeof ask.price).toBe('number');
33-
expect(ask.price).toBeGreaterThanOrEqual(0);
34-
expect(typeof ask.quantity).toBe('number');
35-
expect(ask.quantity).toBeGreaterThanOrEqual(0);
36-
});
37-
});
38-
});
24+
// // Check that each bid and ask is a MarketDepth object
25+
// res.bids.forEach((bid: MarketDepth) => {
26+
// expect(typeof bid.price).toBe('number');
27+
// expect(bid.price).toBeGreaterThanOrEqual(0);
28+
// expect(typeof bid.quantity).toBe('number');
29+
// expect(bid.quantity).toBeGreaterThanOrEqual(0);
30+
// });
31+
// res.asks.forEach((ask: MarketDepth) => {
32+
// expect(typeof ask.price).toBe('number');
33+
// expect(ask.price).toBeGreaterThanOrEqual(0);
34+
// expect(typeof ask.quantity).toBe('number');
35+
// expect(ask.quantity).toBeGreaterThanOrEqual(0);
36+
// });
37+
// });
38+
// });
3939

4040
describe('GetMarketPriceRequest', () => {
4141
test('Buying price should have correct data format and non-negative vaule', async () => {

0 commit comments

Comments
 (0)