@orbs-network/spot 2.2.4 → 2.3.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/config.json CHANGED
@@ -51,17 +51,21 @@
51
51
  },
52
52
  "thena": {
53
53
  "type": "default:odos-v2",
54
- "adapter": "0xB75218ba5A99bF57Fd02556B70F05A4A0f1Dbe67",
54
+ "router": "0x89b8AA89FDd0507a99d334CBe3C808fAFC7d850E",
55
+ "adapter": "0x9E61dEabe996236814c28eC69ab2A7405cB6f03E",
55
56
  "fee": "0x15eBc8b5b3877512FFF23650188694A9a8891FAc"
56
57
  },
57
58
  "pancake": {
58
59
  "type": "p2:pancakeswap-v2",
59
- "adapter": "0x654272F7e6e6E912D38650f783eFd44452fD6ee5",
60
+ "router": "0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB",
61
+ "permit2": "0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768",
62
+ "adapter": "0x52Ed96B1AEd25818B6A284b063b055488E012b73",
60
63
  "fee": "0x37A957f10F458e0d7fDECBE2917971b57F15c927"
61
64
  },
62
65
  "newera": {
63
66
  "type": "default:odos-v2",
64
- "adapter": "0x845f459271D800f6Ab32D78400b8Aa18414E80b0",
67
+ "router": "0x89b8AA89FDd0507a99d334CBe3C808fAFC7d850E",
68
+ "adapter": "0x6236a466CE5c368DC6686d69cAcf5561196B76ef",
65
69
  "fee": "0x4E7454909eB6D539111D56b50d68897E933D2d11"
66
70
  }
67
71
  }
@@ -76,17 +80,20 @@
76
80
  },
77
81
  "spooky": {
78
82
  "type": "default:magpie-v3",
79
- "adapter": "0xdCee7FDdB932104329d528144Cd17A408722B7e2",
83
+ "router": "0xc325856e5585823aaC0D1Fd46c35c608D95E65A9",
84
+ "adapter": "0x56083Eb47d4d7d520F4d2b4a0DC98BE56bb98068",
80
85
  "fee": "0x840Df4684B35BC68BcdA3F6707A3c82A0D662f8b"
81
86
  },
82
87
  "swapx": {
83
88
  "type": "default:openocean-v2",
84
- "adapter": "0xecc733D6F6f2DEa341832D650E30822118884FEb",
89
+ "router": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
90
+ "adapter": "0xa7AE3ABf86C81cCEFEd6bE77045F2a32660c1B1c",
85
91
  "fee": "0x6E03f7BC0f141894612AA017796096399623895F"
86
92
  },
87
93
  "shadow": {
88
94
  "type": "default:magpie-v3",
89
- "adapter": "0x5f3E5F6ACCfc65243A01Da3E93b5A700285592C3",
95
+ "router": "0xc325856e5585823aaC0D1Fd46c35c608D95E65A9",
96
+ "adapter": "0x1adEE94aBa11F19981130F77a1B2620b67e4409A",
90
97
  "fee": "0xb9e3751fAF3187E1bC468E56a707a8A91754460e"
91
98
  }
92
99
  }
@@ -101,12 +108,14 @@
101
108
  },
102
109
  "quick": {
103
110
  "type": "paraswap:paraswap-v5",
104
- "adapter": "0x023fD6848234f2655818705237F77F02215FEfe5",
111
+ "router": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57",
112
+ "adapter": "0x727e1CbA41Ff1ff11C32fa43DAb499b4317A1b65",
105
113
  "fee": "0xd207DC6a6dA88f27c8DB78201F974161b1d84b1f"
106
114
  },
107
115
  "teafi": {
108
116
  "type": "paraswap:paraswap-v5",
109
- "adapter": "0xe95db7a60164B112C64cE67bA8587b1d4a0E0D29",
117
+ "router": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57",
118
+ "adapter": "0xF710D67C783D2C14671EC1c61B0683DCb996F5c3",
110
119
  "fee": "0x04Ff96e2c4D62b5771795d307AD679a25b3D2D50"
111
120
  }
112
121
  }
@@ -121,7 +130,8 @@
121
130
  },
122
131
  "quick": {
123
132
  "type": "default:kyber-v2",
124
- "adapter": "0xc73F03c929A123Ee2f3A98EC18BB240f03980AE5",
133
+ "router": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
134
+ "adapter": "0x0438644898F69bfF1018Cb01a81877D14d3e6493",
125
135
  "fee": "0xd207DC6a6dA88f27c8DB78201F974161b1d84b1f"
126
136
  },
127
137
  "sushiswap": {
@@ -142,7 +152,8 @@
142
152
  },
143
153
  "lynex": {
144
154
  "type": "default:openocean",
145
- "adapter": "0x4FF6A97A67fe395212f168f011D71fE79E4396f2",
155
+ "router": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
156
+ "adapter": "0xd8bC1FF79a642e8D7Fbd0711374F287202fBb3AA",
146
157
  "fee": "0xcb36ed1B1BfAD8F7FC9651f52d21f04A68677423"
147
158
  }
148
159
  }
@@ -157,22 +168,26 @@
157
168
  },
158
169
  "arbidex": {
159
170
  "type": "default:odos-v2",
160
- "adapter": "0xa734b32151108139e48dCA06eE721538d90A9Ef6",
171
+ "router": "0xa669e7A0d4b3e4Fa48af2dE86BD4CD7126Be4e13",
172
+ "adapter": "0xaA66173674F4331e7e672899B3E6aB1190450898",
161
173
  "fee": "0xa0c11852f8A44e32F9EC10AD25986A53842f72Ca"
162
174
  },
163
175
  "ramses": {
164
176
  "type": "paraswap:paraswap-v5",
165
- "adapter": "0x023fD6848234f2655818705237F77F02215FEfe5",
177
+ "router": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57",
178
+ "adapter": "0xf075352f43cd15bA51B0957A4465223EDf6b4Cd8",
166
179
  "fee": "0xB5BaCB60ECDa0bEF809B2A26eC9B4B926835D7af"
167
180
  },
168
181
  "omni": {
169
182
  "type": "paraswap:paraswap-v5",
170
- "adapter": "0xa1baE146161223cd9dCa7137F68eb385934130BE",
183
+ "router": "0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57",
184
+ "adapter": "0x41c925E8E4fC65136BDf5322824E0D8c20c4824e",
171
185
  "fee": "0xba5291526c30B097E9F1Fd1Be301E2ab6E0782aa"
172
186
  },
173
187
  "chronos": {
174
188
  "type": "default:odos-v2",
175
- "adapter": "0x4Ff90F32aceD08b3e3257B018EA495Fd1Bfe4455",
189
+ "router": "0x19cEeAd7105607Cd444F5ad10dd51356436095a1",
190
+ "adapter": "0x6a6b8975d1b131EFd0a9b536766EE7E5d4a16CF2",
176
191
  "fee": "0x5729af83240EFecAa18eafaAE82961c2DD045Dbe"
177
192
  },
178
193
  "sushiswap": {
@@ -193,12 +208,14 @@
193
208
  },
194
209
  "blackhole": {
195
210
  "type": "default:kyber-v2",
196
- "adapter": "0x426ec4bc0d58B80959CDE77576a1942dd40592Fa",
211
+ "router": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
212
+ "adapter": "0xccdF1D6ce95FeC0F842197470CE8969A678B0A04",
197
213
  "fee": "0x7f8B62520D9B5DA0ED517cc36e8dcb2a356f1928"
198
214
  },
199
215
  "pangolin": {
200
216
  "type": "default:kyber-v2",
201
- "adapter": "0xd7D9CAA2910f49F37AC3447f5cAd27153944354A",
217
+ "router": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
218
+ "adapter": "0xf42106eBf985bF49b39eba0114F57FA05e7B52eD",
202
219
  "fee": "0xde92da99D188Ceb54A11ec711EF52D808A6260B5"
203
220
  }
204
221
  }
@@ -217,7 +234,8 @@
217
234
  "dex": {
218
235
  "kodiak": {
219
236
  "type": "default:kodiak",
220
- "adapter": "0xBbaa527Aac00b1Ee9A3909D4D8c4447630E29B1F",
237
+ "router": "0x43Dac637c4383f91B4368041E7A8687da3806Cae",
238
+ "adapter": "0xcB16237c88A859d46Ae850B97d7D1bdECF482C06",
221
239
  "fee": "0xBA47Ec15aFbCF6e7e9F52900632049530bB6bAe4"
222
240
  }
223
241
  }
@@ -226,12 +244,14 @@
226
244
  "dex": {
227
245
  "dragon": {
228
246
  "type": "default:dragon",
229
- "adapter": "0x02d9d5882129241b67ec21Ebc2C86e1BE9BC9890",
247
+ "router": "0x11DA6463D6Cb5a03411Dbf5ab6f6bc3997Ac7428",
248
+ "adapter": "0x1e84A9f30607959d2d8b1a04171ef7D9522Ef502",
230
249
  "fee": "0x0dc1E0525202b32e89bA78ed55b1e5cEdB751334"
231
250
  },
232
251
  "nami": {
233
252
  "type": "default:openocean-v2",
234
- "adapter": "0x2D4A1237A98f8cb03C3C85960e859aA44036a306",
253
+ "router": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
254
+ "adapter": "0xba56F9A7865d430c8293851D576b5728Ca711ff5",
235
255
  "fee": "0xeB58450e23632003f013568703F54446070E2E80"
236
256
  }
237
257
  }
@@ -240,7 +260,8 @@
240
260
  "dex": {
241
261
  "spark": {
242
262
  "type": "default:spark",
243
- "adapter": "0xB18c633B6584A33E45a8840a759f56dF17117b1D",
263
+ "router": "0x0f3D8a38D4c74afBebc2c42695642f0e3acb15D3",
264
+ "adapter": "0x00c7617C471Ef69124464CEc318a3b8CC90aE9A7",
244
265
  "fee": "0xaeA8C3e1a129A77686E115b1a46D9aD8405F7D2b"
245
266
  }
246
267
  }
@@ -249,12 +270,14 @@
249
270
  "dex": {
250
271
  "yowie": {
251
272
  "type": "default:openocean-v2",
252
- "adapter": "0x18bc9533c3539073B9A9acF12b0AbF7cB73e0F1f",
273
+ "router": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
274
+ "adapter": "0xCA84Ab5a5A5bf2cff6AC0C835eF049365D13c6cB",
253
275
  "fee": "0x6AF3eE77A3A3257777F5649aFa611b4C7Fd975Ef"
254
276
  },
255
277
  "pangolin": {
256
278
  "type": "default:kyber-v2",
257
- "adapter": "0xd7D9CAA2910f49F37AC3447f5cAd27153944354A",
279
+ "router": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
280
+ "adapter": "0xf42106eBf985bF49b39eba0114F57FA05e7B52eD",
258
281
  "fee": "0xde92da99D188Ceb54A11ec711EF52D808A6260B5"
259
282
  }
260
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/spot",
3
- "version": "2.2.4",
3
+ "version": "2.3.1",
4
4
  "mcpName": "io.github.orbs-network/spot",
5
5
  "description": "**A DeFi protocol for noncustodial advanced order types on EVM chains.**",
6
6
  "homepage": "https://github.com/orbs-network/spot#readme",
package/server.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "url": "https://github.com/orbs-network/spot",
8
8
  "source": "github"
9
9
  },
10
- "version": "2.2.4",
10
+ "version": "2.3.1",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "@orbs-network/spot",
15
- "version": "2.2.4",
15
+ "version": "2.3.1",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  }
@@ -4,6 +4,18 @@
4
4
  import Web3 from "web3";
5
5
 
6
6
  const DEPOSIT_DATA = "0xd0e30db0";
7
+ const ERC20_ABI = [
8
+ {
9
+ constant: true,
10
+ inputs: [
11
+ { name: "owner", type: "address" },
12
+ { name: "spender", type: "address" },
13
+ ],
14
+ name: "allowance",
15
+ outputs: [{ name: "", type: "uint256" }],
16
+ type: "function",
17
+ },
18
+ ];
7
19
 
8
20
  export async function approveSignAndSubmitOrder({
9
21
  prepared,
@@ -11,7 +23,7 @@ export async function approveSignAndSubmitOrder({
11
23
  provider = window.ethereum,
12
24
  wrappedNative,
13
25
  nativeInputAmount,
14
- sendApproval = false,
26
+ sendApproval = true,
15
27
  }) {
16
28
  const web3 = new Web3(provider);
17
29
  const normalizedAccount = account.toLowerCase();
@@ -43,16 +55,24 @@ export async function approveSignAndSubmitOrder({
43
55
  });
44
56
  }
45
57
 
46
- // Approval is optional.
47
- // Only send this transaction when the current ERC-20 allowance is lower than
48
- // prepared.approval.amount, or when you know approval is still needed.
49
- if (sendApproval) {
50
- await web3.eth.sendTransaction({
51
- from: account,
52
- to: prepared.approval.tx.to,
53
- data: prepared.approval.tx.data,
54
- value: prepared.approval.tx.value,
55
- });
58
+ if (prepared.approval && sendApproval) {
59
+ // The skill helper is RPC-agnostic, so the caller should use its own
60
+ // provider access to avoid resending the same infinite approval.
61
+ const token = new web3.eth.Contract(ERC20_ABI, prepared.approval.tx.to);
62
+ const allowance = BigInt(
63
+ await token.methods
64
+ .allowance(account, prepared.approval.spender)
65
+ .call()
66
+ );
67
+
68
+ if (allowance < BigInt(prepared.approval.amount)) {
69
+ await web3.eth.sendTransaction({
70
+ from: account,
71
+ to: prepared.approval.tx.to,
72
+ data: prepared.approval.tx.data,
73
+ value: prepared.approval.tx.value,
74
+ });
75
+ }
56
76
  }
57
77
 
58
78
  // This example uses eth_signTypedData_v4, but any equivalent EIP-712 signer works.
@@ -3,8 +3,8 @@
3
3
  1. Required fields: `chainId`, `swapper`, `input.token`, `input.amount`, `output.token`.
4
4
  2. Choose the intended order shape before preparing: market, limit, stop-loss, take-profit, delayed-start, or chunked/TWAP.
5
5
  3. Prepare the order with the helper.
6
- 4. If approval is needed, send `prepared.approval.tx`.
7
- 5. Prefer infinite approval to `RePermit` to save future approval gas costs; no approval reset is needed.
6
+ 4. If approval is needed, send `prepared.approval.tx` to approve `RePermit`.
7
+ 5. The skill helper does not read allowance onchain. The calling agent or app should use its own RPC or provider access to compare the current ERC-20 allowance against `prepared.approval.amount`, send that infinite approval only when allowance is lower, and then leave the infinite approval in place with no reset.
8
8
  6. Sign `prepared.typedData` as the `swapper`.
9
9
  7. Submit the signed order.
10
10
  8. Query the order by `swapper` or `hash`.
@@ -4,7 +4,7 @@ Use this file for field semantics, defaults, units, and validation.
4
4
 
5
5
  1. Required: `chainId`, `swapper`, `input.token`, `input.amount`, `output.token`.
6
6
  2. Optional: `input.maxAmount`, `nonce`, `start`, `deadline`, `epoch`, `slippage`, `output.limit`, `output.triggerLower`, `output.triggerUpper`, `output.recipient`.
7
- 3. `input.amount` is the fixed per-chunk size. `input.maxAmount` is total size and approval amount. If omitted, it defaults to `input.amount`. If it is not divisible by `input.amount`, the helper rounds it down to a whole number of chunks.
7
+ 3. `input.amount` is the fixed per-chunk size. `input.maxAmount` is the total requested size. If omitted, it defaults to `input.amount`. If it is not divisible by `input.amount`, the helper rounds it down to a whole number of chunks.
8
8
  4. `output.limit`, `output.triggerLower`, and `output.triggerUpper` are output-token amounts per chunk, encoded in the output token's decimals.
9
9
  5. Future `start` delays the first fill. `epoch` is the delay between chunks, but it is not exact: each chunk can fill anywhere inside its epoch window, only once. Large `epoch` is not a delayed order by itself.
10
10
  6. Chunked orders should use `epoch > 0`; with `epoch = 0`, only the first chunk can fill.
@@ -2,7 +2,7 @@
2
2
 
3
3
  1. Market swap: `input.amount = input.maxAmount`, `output.limit = 0`.
4
4
  2. Limit order: `input.amount = input.maxAmount`, `output.limit > 0`.
5
- 3. Stop-loss or take-profit: set `output.triggerLower` and/or `output.triggerUpper`.
5
+ 3. Stop-loss or take-profit: set `output.triggerLower` for stop-loss and/or `output.triggerUpper` for take-profit.
6
6
  4. Delayed order: set future `start`.
7
7
  5. Chunked or TWAP-style: set `input.amount < input.maxAmount`.
8
8
  6. Time-spaced chunked order: set `epoch > 0`. For example, `epoch = 60` means one chunk can fill once anywhere inside each 60-second epoch window.
@@ -12,6 +12,8 @@ const REF_SHARE = 0;
12
12
  const FRESHNESS = 30;
13
13
  const TTL = 300n;
14
14
  const U32_MAX = 4294967295n;
15
+ const MIN_NON_ZERO_EPOCH = 31n;
16
+ const MAX_APPROVAL = (1n << 256n) - 1n;
15
17
  const DEF_WATCH_INTERVAL = 5;
16
18
  const DEF_WATCH_TIMEOUT = 0;
17
19
  const TERMINAL_ORDER_STATUSES = new Set(['filled', 'completed', 'cancelled', 'canceled', 'expired', 'failed', 'rejected']);
@@ -445,7 +447,7 @@ function usage() {
445
447
  '',
446
448
  'Prepare',
447
449
  ' Builds a prepared order JSON with:',
448
- ' - approval calldata for the input ERC-20',
450
+ ' - infinite approval calldata for the input ERC-20',
449
451
  ' - populated EIP-712 typed data',
450
452
  ' - submit payload template',
451
453
  ' - query URL',
@@ -698,6 +700,9 @@ function prepare(args) {
698
700
  if (gt(slippage, MAX_SLIPPAGE.toString(10))) {
699
701
  die(`slippage cannot exceed ${MAX_SLIPPAGE.toString(10)}`);
700
702
  }
703
+ if (!eq(epoch, '0') && compare(epoch, MIN_NON_ZERO_EPOCH.toString()) === -1) {
704
+ die(`non-zero epoch must be >= ${MIN_NON_ZERO_EPOCH.toString()} because helper freshness is ${String(FRESHNESS)}`);
705
+ }
701
706
  if (!eq(epoch, '0') && compare(String(FRESHNESS), epoch) !== -1) {
702
707
  die('freshness must be < epoch when epoch != 0');
703
708
  }
@@ -715,7 +720,7 @@ function prepare(args) {
715
720
  }
716
721
 
717
722
  if (!eq(inputAmount, inputMaxAmount) && eq(epoch, '0')) {
718
- die('chunked orders require epoch > 0');
723
+ die(`chunked orders require epoch >= ${MIN_NON_ZERO_EPOCH.toString()}`);
719
724
  }
720
725
 
721
726
  const kind = eq(inputAmount, inputMaxAmount) ? 'single' : 'chunked';
@@ -744,7 +749,8 @@ function prepare(args) {
744
749
  warn(WARN_RECIPIENT);
745
750
  }
746
751
 
747
- const approvalData = requireHex(approveCalldata(REPERMIT, inputMaxAmount), 'approval.tx.data');
752
+ const approvalAmount = MAX_APPROVAL.toString(10);
753
+ const approvalData = requireHex(approveCalldata(REPERMIT, approvalAmount), 'approval.tx.data');
748
754
  const typedData = buildTypedData(
749
755
  chainId,
750
756
  swapper,
@@ -780,7 +786,7 @@ function prepare(args) {
780
786
  approval: {
781
787
  token: inputToken,
782
788
  spender: REPERMIT,
783
- amount: inputMaxAmount,
789
+ amount: approvalAmount,
784
790
  tx: {
785
791
  to: inputToken,
786
792
  data: approvalData,
@@ -875,6 +881,46 @@ function responseOrders(response) {
875
881
  return isPlainObject(response) && Array.isArray(response.orders) ? response.orders : [];
876
882
  }
877
883
 
884
+ function responseOrderHash(response) {
885
+ if (!isPlainObject(response)) {
886
+ return '';
887
+ }
888
+
889
+ const direct = trim(response.orderHash);
890
+ if (/^0x[0-9a-fA-F]{64}$/.test(direct)) {
891
+ return direct;
892
+ }
893
+
894
+ const signedOrder = objectOrEmpty(response.signedOrder);
895
+ const nested = trim(signedOrder.hash);
896
+ if (/^0x[0-9a-fA-F]{64}$/.test(nested)) {
897
+ return nested;
898
+ }
899
+
900
+ return '';
901
+ }
902
+
903
+ function submitOutput(result, request) {
904
+ const orderHash = result.ok ? responseOrderHash(result.response) : '';
905
+ const watch = orderHash
906
+ ? {
907
+ hash: orderHash,
908
+ command: `node skill/scripts/order.js watch --hash ${orderHash}`,
909
+ url: `${QUERY_URL}?hash=${encodeURIComponent(orderHash)}`,
910
+ }
911
+ : null;
912
+
913
+ return {
914
+ ok: result.ok,
915
+ status: result.status,
916
+ url: request.url,
917
+ request,
918
+ response: result.response,
919
+ orderHash,
920
+ watch,
921
+ };
922
+ }
923
+
878
924
  function watchSnapshot(response, { hash }) {
879
925
  const orders = responseOrders(response);
880
926
  if (!hash && orders.length > 1) {
@@ -984,16 +1030,7 @@ async function submit(args) {
984
1030
  body: JSON.stringify(request.body),
985
1031
  });
986
1032
 
987
- writeOutput(
988
- {
989
- ok: result.ok,
990
- status: result.status,
991
- url: request.url,
992
- request,
993
- response: result.response,
994
- },
995
- outFile,
996
- );
1033
+ writeOutput(submitOutput(result, request), outFile);
997
1034
 
998
1035
  return result.ok ? 0 : 1;
999
1036
  }