@orbs-network/spot-ui 2.1.0 → 2.1.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/README.md +68 -69
- package/dist/spot-ui.js +1612 -2260
- package/dist/spot-ui.umd.cjs +8 -8
- package/dist/src/index.d.ts +11 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/lib/analytics.d.ts +10 -12
- package/dist/src/lib/analytics.d.ts.map +1 -1
- package/dist/src/lib/api-config.d.ts +11 -0
- package/dist/src/lib/api-config.d.ts.map +1 -0
- package/dist/src/lib/build-repermit-order-data.d.ts +1 -2
- package/dist/src/lib/build-repermit-order-data.d.ts.map +1 -1
- package/dist/src/lib/client.d.ts +2 -2
- package/dist/src/lib/client.d.ts.map +1 -1
- package/dist/src/lib/evm-constants.d.ts +3 -0
- package/dist/src/lib/evm-constants.d.ts.map +1 -0
- package/dist/src/lib/order-form/amounts.d.ts +13 -0
- package/dist/src/lib/order-form/amounts.d.ts.map +1 -0
- package/dist/src/lib/order-form/calculate-order-form.d.ts +3 -0
- package/dist/src/lib/order-form/calculate-order-form.d.ts.map +1 -0
- package/dist/src/lib/order-form/constants.d.ts +10 -0
- package/dist/src/lib/order-form/constants.d.ts.map +1 -0
- package/dist/src/lib/order-form/prices.d.ts +8 -0
- package/dist/src/lib/order-form/prices.d.ts.map +1 -0
- package/dist/src/lib/order-form/schedule.d.ts +27 -0
- package/dist/src/lib/order-form/schedule.d.ts.map +1 -0
- package/dist/src/lib/order-form/types.d.ts +209 -0
- package/dist/src/lib/order-form/types.d.ts.map +1 -0
- package/dist/src/lib/order-form/validation.d.ts +7 -0
- package/dist/src/lib/order-form/validation.d.ts.map +1 -0
- package/dist/src/lib/order-form/values.d.ts +3 -0
- package/dist/src/lib/order-form/values.d.ts.map +1 -0
- package/dist/src/lib/orders/legacy-twap-config.d.ts +22 -0
- package/dist/src/lib/orders/legacy-twap-config.d.ts.map +1 -0
- package/dist/src/lib/partners.d.ts +3 -0
- package/dist/src/lib/partners.d.ts.map +1 -0
- package/dist/src/lib/public-links.d.ts +6 -0
- package/dist/src/lib/public-links.d.ts.map +1 -0
- package/dist/src/lib/types.d.ts +3 -13
- package/dist/src/lib/types.d.ts.map +1 -1
- package/dist/src/lib/utils.d.ts +1 -28
- package/dist/src/lib/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/src/lib/calculations.d.ts +0 -123
- package/dist/src/lib/calculations.d.ts.map +0 -1
- package/dist/src/lib/consts.d.ts +0 -92
- package/dist/src/lib/consts.d.ts.map +0 -1
- package/dist/src/lib/lib.d.ts +0 -66
- package/dist/src/lib/lib.d.ts.map +0 -1
- package/dist/src/lib/networks.d.ts +0 -571
- package/dist/src/lib/networks.d.ts.map +0 -1
- package/dist/src/lib/order-form.d.ts +0 -95
- package/dist/src/lib/order-form.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
Angular, Svelte, React, vanilla JavaScript, or a server-side TypeScript
|
|
5
5
|
application. It has no React dependency.
|
|
6
6
|
|
|
7
|
+
For the complete framework-neutral TypeScript workflow, see the
|
|
8
|
+
[`spot-integration` skill](https://github.com/orbs-network/spot-ui/tree/master/skills/spot-integration).
|
|
9
|
+
|
|
7
10
|
## Complete form calculation
|
|
8
11
|
|
|
9
12
|
Use `calculateOrderForm` as the primary calculation API. Pass the DEX-owned
|
|
@@ -14,37 +17,36 @@ display and order execution.
|
|
|
14
17
|
import {
|
|
15
18
|
calculateOrderForm,
|
|
16
19
|
Module,
|
|
17
|
-
toAmountWei,
|
|
18
20
|
} from "@orbs-network/spot-ui";
|
|
19
21
|
|
|
20
22
|
const form = calculateOrderForm({
|
|
21
23
|
module: Module.TWAP,
|
|
22
|
-
isMarketOrder: true,
|
|
23
|
-
|
|
24
|
-
// Raw input-token amount.
|
|
25
|
-
inputAmountWei: toAmountWei(typedInputAmount, inputToken.decimals),
|
|
26
24
|
inputTokenDecimals: inputToken.decimals,
|
|
27
25
|
outputTokenDecimals: outputToken.decimals,
|
|
28
26
|
|
|
29
27
|
// Raw output-token amount quoted for the complete input amount.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
quotedOutputAmountRaw,
|
|
29
|
+
inputTokenUsdPrice,
|
|
30
|
+
outputTokenUsdPrice,
|
|
33
31
|
minTradeSizeUsd,
|
|
34
|
-
|
|
35
|
-
// Optional user overrides. Omit them to use SDK defaults.
|
|
36
|
-
trades,
|
|
37
|
-
fillDelay,
|
|
38
|
-
duration,
|
|
39
|
-
limitPrice,
|
|
40
|
-
limitPricePercent,
|
|
41
|
-
triggerPrice,
|
|
42
|
-
triggerPricePercent,
|
|
43
|
-
isInverted,
|
|
44
|
-
|
|
45
|
-
priceProtection: 3, // 3%
|
|
32
|
+
priceProtectionPercent: 3,
|
|
46
33
|
displayFeePercent,
|
|
47
|
-
|
|
34
|
+
inputBalanceRaw,
|
|
35
|
+
|
|
36
|
+
userInput: {
|
|
37
|
+
inputAmountUi,
|
|
38
|
+
isMarketOrder: true,
|
|
39
|
+
|
|
40
|
+
// Optional user overrides. Omit them to use SDK defaults.
|
|
41
|
+
tradeCount,
|
|
42
|
+
tradeInterval,
|
|
43
|
+
orderDuration,
|
|
44
|
+
limitPriceUi,
|
|
45
|
+
limitPricePercent,
|
|
46
|
+
triggerPriceUi,
|
|
47
|
+
triggerPricePercent,
|
|
48
|
+
isPriceInverted,
|
|
49
|
+
},
|
|
48
50
|
});
|
|
49
51
|
```
|
|
50
52
|
|
|
@@ -78,20 +80,13 @@ protocol response models such as `Order`.
|
|
|
78
80
|
|
|
79
81
|
This calculation is synchronous and does not fetch configuration. Optional
|
|
80
82
|
fields can be passed while the user edits the form; the result always contains
|
|
81
|
-
the currently derivable values.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- `marketPrice` is the raw output-token amount for exactly one whole input
|
|
89
|
-
token (for example, a 2 USDC rate with 6 output decimals is `"2000000"`);
|
|
90
|
-
- `quotedOutputAmount` is the raw output-token amount quoted for the complete
|
|
91
|
-
`inputAmountWei`.
|
|
92
|
-
|
|
93
|
-
Pass one or the other. When `quotedOutputAmount` is supplied, the SDK derives
|
|
94
|
-
the per-token rate using `inputAmountWei` and `inputTokenDecimals`.
|
|
83
|
+
the currently derivable values. Editable fields live under `userInput`, while
|
|
84
|
+
token, quote, balance, and configuration data stay at the top level.
|
|
85
|
+
`userInput.inputAmountUi` is the single input amount. The SDK derives its raw
|
|
86
|
+
and USD representations from the token decimals and USD price.
|
|
87
|
+
`quotedOutputAmountRaw` is the raw output-token amount quoted for that complete
|
|
88
|
+
input amount; the SDK derives the per-token market rate from the two values.
|
|
89
|
+
Omit a stale quote while a replacement quote is loading.
|
|
95
90
|
|
|
96
91
|
`calculateOrderForm` is time-independent. Recalculate only when its form or
|
|
97
92
|
market inputs change. `prepareOrder` stamps the current start and deadline from
|
|
@@ -104,10 +99,10 @@ uses the same defaults, validation, and derived-value rules.
|
|
|
104
99
|
|
|
105
100
|
`minTradeSizeUsd` is a positive USD threshold owned by the integrating DEX.
|
|
106
101
|
Use the minimum approved for that partner/product; the SDK deliberately does
|
|
107
|
-
not guess protocol policy. `
|
|
108
|
-
(300 basis points), not 3 bps. `displayFeePercent` is also a
|
|
109
|
-
only calculates `form.fees` for display. It does not collect
|
|
110
|
-
collection must be configured by the partner/backend.
|
|
102
|
+
not guess protocol policy. `priceProtectionPercent` uses percentage units, so
|
|
103
|
+
`3` means 3% (300 basis points), not 3 bps. `displayFeePercent` is also a
|
|
104
|
+
percentage, but it only calculates `form.fees` for display. It does not collect
|
|
105
|
+
or subtract a fee; collection must be configured by the partner/backend.
|
|
111
106
|
|
|
112
107
|
## Client and order submission
|
|
113
108
|
|
|
@@ -129,44 +124,48 @@ validated form and client configuration.
|
|
|
129
124
|
import {
|
|
130
125
|
calculateOrderForm,
|
|
131
126
|
createClient,
|
|
132
|
-
ensureWrappedToken,
|
|
133
|
-
getExplorerUrl,
|
|
134
127
|
isNativeAddress,
|
|
135
128
|
isTxRejected,
|
|
136
129
|
Module,
|
|
137
130
|
Partners,
|
|
138
|
-
toAmountWei,
|
|
139
131
|
} from "@orbs-network/spot-ui";
|
|
140
132
|
|
|
141
133
|
const client = await createClient(Partners.Quick, 137);
|
|
142
134
|
|
|
143
135
|
const form = calculateOrderForm({
|
|
144
136
|
module: Module.TWAP,
|
|
145
|
-
isMarketOrder: true,
|
|
146
|
-
inputAmountWei: toAmountWei(typedInputAmount, inputToken.decimals),
|
|
147
137
|
inputTokenDecimals: inputToken.decimals,
|
|
148
138
|
outputTokenDecimals: outputToken.decimals,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
quotedOutputAmountRaw,
|
|
140
|
+
inputTokenUsdPrice,
|
|
141
|
+
outputTokenUsdPrice,
|
|
152
142
|
minTradeSizeUsd,
|
|
153
|
-
|
|
154
|
-
fillDelay,
|
|
155
|
-
duration,
|
|
156
|
-
limitPrice,
|
|
157
|
-
limitPricePercent,
|
|
158
|
-
triggerPrice,
|
|
159
|
-
triggerPricePercent,
|
|
160
|
-
isInverted,
|
|
161
|
-
priceProtection: 3,
|
|
143
|
+
priceProtectionPercent: 3,
|
|
162
144
|
displayFeePercent,
|
|
163
|
-
|
|
145
|
+
inputBalanceRaw,
|
|
146
|
+
userInput: {
|
|
147
|
+
inputAmountUi,
|
|
148
|
+
isMarketOrder: true,
|
|
149
|
+
tradeCount,
|
|
150
|
+
tradeInterval,
|
|
151
|
+
orderDuration,
|
|
152
|
+
limitPriceUi,
|
|
153
|
+
limitPricePercent,
|
|
154
|
+
triggerPriceUi,
|
|
155
|
+
triggerPricePercent,
|
|
156
|
+
isPriceInverted,
|
|
157
|
+
},
|
|
164
158
|
});
|
|
165
159
|
|
|
166
160
|
const amount = form.inputAmount.raw;
|
|
167
|
-
const
|
|
161
|
+
const orderInputToken = isNativeAddress(inputToken.address)
|
|
162
|
+
? wrappedNativeToken
|
|
163
|
+
: inputToken;
|
|
164
|
+
if (!orderInputToken) {
|
|
165
|
+
throw new Error("The host must provide the chain's wrapped native token");
|
|
166
|
+
}
|
|
168
167
|
const approvalRequest = {
|
|
169
|
-
tokenAddress:
|
|
168
|
+
tokenAddress: orderInputToken.address,
|
|
170
169
|
amount,
|
|
171
170
|
spenderAddress: client.spenderAddress,
|
|
172
171
|
};
|
|
@@ -195,7 +194,7 @@ try {
|
|
|
195
194
|
|
|
196
195
|
const preparedOrder = client.prepareOrder({
|
|
197
196
|
form,
|
|
198
|
-
inputTokenAddress:
|
|
197
|
+
inputTokenAddress: orderInputToken.address,
|
|
199
198
|
outputTokenAddress: outputToken.address,
|
|
200
199
|
swapperAddress: account,
|
|
201
200
|
});
|
|
@@ -205,7 +204,7 @@ try {
|
|
|
205
204
|
wallet.signTypedData(typedData, signerAddress),
|
|
206
205
|
);
|
|
207
206
|
const order = await client.submitOrder(preparedOrder, signature);
|
|
208
|
-
console.info("Order submitted", order
|
|
207
|
+
console.info("Order submitted", order);
|
|
209
208
|
} catch (error) {
|
|
210
209
|
if (isTxRejected(error)) console.info("The wallet request was rejected");
|
|
211
210
|
else throw error;
|
|
@@ -276,21 +275,21 @@ the host's polling schedule and find it by `historyKey`. Supplying a page and
|
|
|
276
275
|
limit avoids fetching every history page when only a recent status window is
|
|
277
276
|
needed.
|
|
278
277
|
|
|
279
|
-
Use `client.spenderAddress` for allowance reads and approvals.
|
|
280
|
-
native
|
|
278
|
+
Use `client.spenderAddress` for allowance reads and approvals. When the input
|
|
279
|
+
is native, the host must pass its chain's wrapped native token address to
|
|
280
|
+
`prepareOrder`; approve `form.inputAmount.raw` against that same token.
|
|
281
281
|
The `approvalRequest` returned by `prepareOrder` records the same normalized
|
|
282
282
|
token, spender, and exact amount used by the signed order.
|
|
283
283
|
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
`spot-ui` deliberately has no network registry and does not infer wrapped-token
|
|
285
|
+
or explorer metadata. The host DEX owns that chain data. Protocol configuration
|
|
286
|
+
fetching, RePermit order
|
|
286
287
|
construction, submission, cancellation request construction, and configured
|
|
287
288
|
history access are intentionally exposed only through `SpotClient`. This keeps
|
|
288
289
|
partner- and chain-derived values on one authoritative path.
|
|
289
290
|
|
|
290
|
-
Framework-neutral helpers `
|
|
291
|
-
|
|
292
|
-
`spot-ui`; Vue, Angular, Svelte, and server integrations do not need to copy
|
|
293
|
-
React-specific utility code.
|
|
291
|
+
Framework-neutral helpers such as `isNativeAddress` and `isTxRejected` remain
|
|
292
|
+
available to Vue, Angular, Svelte, vanilla JavaScript, and server integrations.
|
|
294
293
|
|
|
295
294
|
Every `createClient` call performs a new configuration request. Cache the
|
|
296
295
|
returned promise or client in the host application's normal data layer when it
|