@gmx-io/sdk 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/src/abis/TransitStation.js +2222 -0
- package/build/cjs/src/abis/index.js +2 -0
- package/build/cjs/src/clients/v2/index.js +54 -27
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +272 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +60 -0
- package/build/cjs/src/configs/markets.js +28 -0
- package/build/cjs/src/configs/tokens.js +9 -0
- package/build/cjs/src/utils/paxos/__tests__/api.spec.js +128 -0
- package/build/cjs/src/utils/paxos/api.js +129 -0
- package/build/cjs/src/utils/paxos/types.js +2 -0
- package/build/cjs/src/utils/usdgBoostApr/api.js +7 -0
- package/build/cjs/src/utils/usdgBoostApr/types.js +2 -0
- package/build/cjs/src/utils/whitelists/api.js +9 -0
- package/build/cjs/src/utils/whitelists/types.js +2 -0
- package/build/esm/src/abis/TransitStation.js +2220 -0
- package/build/esm/src/abis/index.js +2 -0
- package/build/esm/src/clients/v2/index.js +27 -0
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +272 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +60 -0
- package/build/esm/src/configs/markets.js +28 -0
- package/build/esm/src/configs/tokens.js +9 -0
- package/build/esm/src/utils/paxos/__tests__/api.spec.js +126 -0
- package/build/esm/src/utils/paxos/api.js +120 -0
- package/build/esm/src/utils/paxos/types.js +1 -0
- package/build/esm/src/utils/usdgBoostApr/api.js +3 -0
- package/build/esm/src/utils/usdgBoostApr/types.js +1 -0
- package/build/esm/src/utils/whitelists/api.js +5 -0
- package/build/esm/src/utils/whitelists/types.js +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/abis/TransitStation.d.ts +1710 -0
- package/build/types/src/abis/index.d.ts +1709 -0
- package/build/types/src/clients/v2/index.d.ts +20 -0
- package/build/types/src/codegen/prebuilt/index.d.ts +364 -0
- package/build/types/src/utils/paxos/__tests__/api.spec.d.ts +1 -0
- package/build/types/src/utils/paxos/api.d.ts +24 -0
- package/build/types/src/utils/paxos/types.d.ts +139 -0
- package/build/types/src/utils/trade/types.d.ts +2 -0
- package/build/types/src/utils/usdgBoostApr/api.d.ts +5 -0
- package/build/types/src/utils/usdgBoostApr/types.d.ts +19 -0
- package/build/types/src/utils/whitelists/api.d.ts +7 -0
- package/build/types/src/utils/whitelists/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { fetchApiTransitFeeTier, fetchApiTransitOrder, fetchApiTransitOrders, fetchApiTransitQuote, fetchApiTransitRoutes, } from "../api";
|
|
3
|
+
const API_URL = "https://example.test";
|
|
4
|
+
const USER = "0x1111111111111111111111111111111111111111";
|
|
5
|
+
const USDC = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831";
|
|
6
|
+
const USDG = "0x004B506865409877C9fA29bfb1ebA929984B9bbC";
|
|
7
|
+
const ORDER_ID = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
8
|
+
function createApi(calls, response = {}) {
|
|
9
|
+
return {
|
|
10
|
+
url: API_URL,
|
|
11
|
+
fetchJson: async (path, opts) => {
|
|
12
|
+
calls.push({ path, query: opts?.query });
|
|
13
|
+
return response;
|
|
14
|
+
},
|
|
15
|
+
postJson: async () => {
|
|
16
|
+
throw new Error("Unexpected POST request");
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const RAW_ORDER = {
|
|
21
|
+
id: ORDER_ID,
|
|
22
|
+
offerAsset: USDC,
|
|
23
|
+
wantAsset: USDG,
|
|
24
|
+
amountDue: "50000000",
|
|
25
|
+
remainingAmountDue: "0",
|
|
26
|
+
offerAmount: "50000000",
|
|
27
|
+
receiver: USER,
|
|
28
|
+
distributorCode: "0x",
|
|
29
|
+
destinationChainId: 42161,
|
|
30
|
+
sourceChainId: 42161,
|
|
31
|
+
receiveTime: 1234567890,
|
|
32
|
+
status: "PROCESSED",
|
|
33
|
+
user: USER,
|
|
34
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
35
|
+
updatedAt: "2026-01-01T00:05:00Z",
|
|
36
|
+
orderExecuteds: [
|
|
37
|
+
{ id: "0xab", amount: "50000000", remaining: "0", timestamp: 1234567890, txHash: "0xcd", chainId: 42161 },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
describe("paxos transit api", () => {
|
|
41
|
+
it("parses routes", async () => {
|
|
42
|
+
const calls = [];
|
|
43
|
+
const api = createApi(calls, {
|
|
44
|
+
routes: [
|
|
45
|
+
{
|
|
46
|
+
sourceChainId: 42161,
|
|
47
|
+
destinationChainId: 42161,
|
|
48
|
+
destinationChainEID: 30110,
|
|
49
|
+
offerAsset: USDC,
|
|
50
|
+
wantAsset: USDG,
|
|
51
|
+
minOrderSize: "10000000",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
const routes = await fetchApiTransitRoutes({ api });
|
|
56
|
+
expect(calls).toEqual([{ path: "/v1/paxos/transit/routes", query: { filter: undefined } }]);
|
|
57
|
+
expect(routes).toEqual([
|
|
58
|
+
{
|
|
59
|
+
sourceChainId: 42161,
|
|
60
|
+
destinationChainId: 42161,
|
|
61
|
+
destinationChainEID: 30110,
|
|
62
|
+
offerAsset: USDC,
|
|
63
|
+
wantAsset: USDG,
|
|
64
|
+
minOrderSize: 10000000n,
|
|
65
|
+
tokenMetadataMap: {},
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
it("asks for the routes of a fee tier", async () => {
|
|
70
|
+
const calls = [];
|
|
71
|
+
const api = createApi(calls, { routes: [] });
|
|
72
|
+
await fetchApiTransitRoutes({ api }, { feeTier: "zeroFee" });
|
|
73
|
+
expect(calls).toEqual([{ path: "/v1/paxos/transit/routes", query: { filter: undefined, feeTier: "zeroFee" } }]);
|
|
74
|
+
});
|
|
75
|
+
it("parses fee tier capacity as bigint", async () => {
|
|
76
|
+
const calls = [];
|
|
77
|
+
const api = createApi(calls, { feeTier: "zeroFee", zeroFeeCapacity: "250000000000" });
|
|
78
|
+
const result = await fetchApiTransitFeeTier({ api }, { userAddress: USER });
|
|
79
|
+
expect(calls).toEqual([{ path: "/v1/paxos/transit/fee-tier", query: { userAddress: USER } }]);
|
|
80
|
+
expect(result).toEqual({ feeTier: "zeroFee", zeroFeeCapacity: 250000000000n });
|
|
81
|
+
});
|
|
82
|
+
it("sends quote amounts as strings and parses fees", async () => {
|
|
83
|
+
const calls = [];
|
|
84
|
+
const api = createApi(calls, {
|
|
85
|
+
transaction: { to: "0x22", data: "0x33", value: "1500", functionName: "submitOrder" },
|
|
86
|
+
amountOut: "49990000",
|
|
87
|
+
protocolFee: "10000",
|
|
88
|
+
fillCostFee: "5000",
|
|
89
|
+
conversionRateFee: "5000",
|
|
90
|
+
conversionRateHundredthsBps: 100,
|
|
91
|
+
integratorFee: "0",
|
|
92
|
+
totalFees: "10000",
|
|
93
|
+
});
|
|
94
|
+
const quote = await fetchApiTransitQuote({ api }, {
|
|
95
|
+
userAddress: USER,
|
|
96
|
+
offerAsset: USDC,
|
|
97
|
+
wantAsset: USDG,
|
|
98
|
+
offerAmount: 50000000n,
|
|
99
|
+
sourceChainId: 42161,
|
|
100
|
+
destinationChainId: 42161,
|
|
101
|
+
feeTier: "standardFee",
|
|
102
|
+
});
|
|
103
|
+
expect(calls[0].path).toBe("/v1/paxos/transit/orders/quote");
|
|
104
|
+
expect(calls[0].query).toMatchObject({ offerAmount: "50000000", feeTier: "standardFee" });
|
|
105
|
+
expect(quote.transaction.value).toBe(1500n);
|
|
106
|
+
expect(quote.amountOut).toBe(49990000n);
|
|
107
|
+
expect(quote.totalFees).toBe(10000n);
|
|
108
|
+
expect(quote.estimatedLatencyMs).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
it("parses a single order", async () => {
|
|
111
|
+
const calls = [];
|
|
112
|
+
const api = createApi(calls, { order: RAW_ORDER });
|
|
113
|
+
const order = await fetchApiTransitOrder({ api }, { orderId: ORDER_ID });
|
|
114
|
+
expect(calls).toEqual([{ path: `/v1/paxos/transit/orders/${ORDER_ID}`, query: undefined }]);
|
|
115
|
+
expect(order.status).toBe("PROCESSED");
|
|
116
|
+
expect(order.offerAmount).toBe(50000000n);
|
|
117
|
+
expect(order.tokenMetadata).toEqual({});
|
|
118
|
+
expect(order.orderExecuteds[0].amount).toBe(50000000n);
|
|
119
|
+
});
|
|
120
|
+
it("drops an empty next page token", async () => {
|
|
121
|
+
const api = createApi([], { orders: [RAW_ORDER], nextPageToken: "" });
|
|
122
|
+
const result = await fetchApiTransitOrders({ api }, { userAddress: USER });
|
|
123
|
+
expect(result.orders).toHaveLength(1);
|
|
124
|
+
expect(result.nextPageToken).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export async function fetchApiTransitRoutes(ctx, params) {
|
|
2
|
+
const raw = await ctx.api.fetchJson("/v1/paxos/transit/routes", {
|
|
3
|
+
query: { filter: params?.filter, feeTier: params?.feeTier },
|
|
4
|
+
});
|
|
5
|
+
return (raw.routes ?? []).map(parseRoute);
|
|
6
|
+
}
|
|
7
|
+
export async function fetchApiTransitFeeTier(ctx, params) {
|
|
8
|
+
const raw = await ctx.api.fetchJson("/v1/paxos/transit/fee-tier", {
|
|
9
|
+
query: { userAddress: params.userAddress },
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
feeTier: raw.feeTier,
|
|
13
|
+
zeroFeeCapacity: BigInt(raw.zeroFeeCapacity),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export async function fetchApiTransitAuthorization(ctx, params) {
|
|
17
|
+
return ctx.api.fetchJson("/v1/paxos/transit/authorization", {
|
|
18
|
+
query: {
|
|
19
|
+
userAddress: params.userAddress,
|
|
20
|
+
tokenAddress: params.tokenAddress,
|
|
21
|
+
spenderAddress: params.spenderAddress,
|
|
22
|
+
amount: params.amount.toString(),
|
|
23
|
+
chainId: params.chainId,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export async function fetchApiTransitQuote(ctx, params) {
|
|
28
|
+
const raw = await ctx.api.fetchJson("/v1/paxos/transit/orders/quote", {
|
|
29
|
+
query: {
|
|
30
|
+
userAddress: params.userAddress,
|
|
31
|
+
offerAsset: params.offerAsset,
|
|
32
|
+
wantAsset: params.wantAsset,
|
|
33
|
+
offerAmount: params.offerAmount.toString(),
|
|
34
|
+
sourceChainId: params.sourceChainId,
|
|
35
|
+
destinationChainId: params.destinationChainId,
|
|
36
|
+
permitSignature: params.permitSignature,
|
|
37
|
+
permitDeadline: params.permitDeadline,
|
|
38
|
+
responseFormat: params.responseFormat,
|
|
39
|
+
feeTier: params.feeTier,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return parseQuote(raw);
|
|
43
|
+
}
|
|
44
|
+
export async function fetchApiTransitOrder(ctx, params) {
|
|
45
|
+
const raw = await ctx.api.fetchJson(`/v1/paxos/transit/orders/${encodeURIComponent(params.orderId)}`);
|
|
46
|
+
return parseOrder(raw.order);
|
|
47
|
+
}
|
|
48
|
+
export async function fetchApiTransitOrders(ctx, params) {
|
|
49
|
+
const raw = await ctx.api.fetchJson("/v1/paxos/transit/orders", {
|
|
50
|
+
query: {
|
|
51
|
+
userAddress: params.userAddress,
|
|
52
|
+
pageSize: params.pageSize,
|
|
53
|
+
pageToken: params.pageToken,
|
|
54
|
+
filter: params.filter,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
orders: (raw.orders ?? []).map(parseOrder),
|
|
59
|
+
nextPageToken: raw.nextPageToken || undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function parseRoute(raw) {
|
|
63
|
+
return {
|
|
64
|
+
sourceChainId: Number(raw.sourceChainId),
|
|
65
|
+
destinationChainId: Number(raw.destinationChainId),
|
|
66
|
+
destinationChainEID: Number(raw.destinationChainEID),
|
|
67
|
+
offerAsset: raw.offerAsset,
|
|
68
|
+
wantAsset: raw.wantAsset,
|
|
69
|
+
minOrderSize: BigInt(raw.minOrderSize),
|
|
70
|
+
tokenMetadataMap: raw.tokenMetadataMap ?? {},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function parseQuote(raw) {
|
|
74
|
+
return {
|
|
75
|
+
transaction: {
|
|
76
|
+
to: raw.transaction.to,
|
|
77
|
+
data: raw.transaction.data,
|
|
78
|
+
value: BigInt(raw.transaction.value ?? 0),
|
|
79
|
+
abi: raw.transaction.abi,
|
|
80
|
+
functionName: raw.transaction.functionName,
|
|
81
|
+
args: raw.transaction.args,
|
|
82
|
+
},
|
|
83
|
+
amountOut: BigInt(raw.amountOut),
|
|
84
|
+
protocolFee: BigInt(raw.protocolFee),
|
|
85
|
+
fillCostFee: BigInt(raw.fillCostFee),
|
|
86
|
+
conversionRateFee: BigInt(raw.conversionRateFee),
|
|
87
|
+
conversionRateHundredthsBps: Number(raw.conversionRateHundredthsBps),
|
|
88
|
+
integratorFee: BigInt(raw.integratorFee ?? 0),
|
|
89
|
+
totalFees: BigInt(raw.totalFees),
|
|
90
|
+
estimatedLatencyMs: raw.estimatedLatencyMs === undefined ? undefined : Number(raw.estimatedLatencyMs),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function parseOrder(raw) {
|
|
94
|
+
return {
|
|
95
|
+
id: raw.id,
|
|
96
|
+
offerAsset: raw.offerAsset,
|
|
97
|
+
wantAsset: raw.wantAsset,
|
|
98
|
+
amountDue: BigInt(raw.amountDue),
|
|
99
|
+
remainingAmountDue: BigInt(raw.remainingAmountDue),
|
|
100
|
+
offerAmount: BigInt(raw.offerAmount),
|
|
101
|
+
receiver: raw.receiver,
|
|
102
|
+
distributorCode: raw.distributorCode,
|
|
103
|
+
destinationChainId: Number(raw.destinationChainId),
|
|
104
|
+
sourceChainId: Number(raw.sourceChainId),
|
|
105
|
+
receiveTime: Number(raw.receiveTime),
|
|
106
|
+
status: raw.status,
|
|
107
|
+
user: raw.user,
|
|
108
|
+
createdAt: raw.createdAt,
|
|
109
|
+
updatedAt: raw.updatedAt,
|
|
110
|
+
tokenMetadata: raw.tokenMetadata ?? {},
|
|
111
|
+
orderExecuteds: (raw.orderExecuteds ?? []).map((execution) => ({
|
|
112
|
+
id: execution.id,
|
|
113
|
+
amount: BigInt(execution.amount),
|
|
114
|
+
remaining: BigInt(execution.remaining),
|
|
115
|
+
timestamp: Number(execution.timestamp),
|
|
116
|
+
txHash: execution.txHash,
|
|
117
|
+
chainId: Number(execution.chainId),
|
|
118
|
+
})),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|