@chainflip/bitcoin 1.2.5 → 1.2.7

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/dist/index.cjs CHANGED
@@ -185,10 +185,16 @@ var makeRequest = async (rpcUrl, method, params) => {
185
185
  params
186
186
  })
187
187
  });
188
- if (res.status !== 200) {
189
- throw new Error(`HTTP error [${res.status}]: ${await res.text() || res.statusText}`);
188
+ const text = await res.text();
189
+ let json;
190
+ try {
191
+ json = JSON.parse(text);
192
+ } catch {
193
+ if (res.status !== 200) {
194
+ throw new Error(`HTTP error [${res.status}]: ${text || res.statusText}`);
195
+ }
196
+ throw new Error(`Invalid JSON response: ${text}`);
190
197
  }
191
- const json = await res.json();
192
198
  const result = rpcResponse.parse(json);
193
199
  if (result.error) {
194
200
  if (result.error.code === -5) return null;
@@ -209,7 +215,7 @@ var addressByteLengths = {
209
215
  Polkadot: 32,
210
216
  Assethub: 32
211
217
  };
212
- var createSwapDataCodec = (asset) => scaleTs.Struct({
218
+ var createSwapDataCodecV0 = (asset) => scaleTs.Struct({
213
219
  version: scaleTs.u8,
214
220
  destinationAsset: scaleTs.u8,
215
221
  destinationAddress: scaleTs.Bytes(addressByteLengths[chainflip.assetConstants[asset].chain]),
@@ -223,6 +229,21 @@ var createSwapDataCodec = (asset) => scaleTs.Struct({
223
229
  affiliates: scaleTs.Vector(scaleTs.Struct({ accountIndex: scaleTs.u8, commissionBps: scaleTs.u8 }))
224
230
  })
225
231
  });
232
+ var createSwapDataCodecV1 = (asset) => scaleTs.Struct({
233
+ version: scaleTs.u8,
234
+ destinationAsset: scaleTs.u8,
235
+ destinationAddress: scaleTs.Bytes(addressByteLengths[chainflip.assetConstants[asset].chain]),
236
+ parameters: scaleTs.Struct({
237
+ retryDuration: scaleTs.u16,
238
+ minOutputAmount: scaleTs.u128,
239
+ maxOraclePriceSlippage: scaleTs.u8,
240
+ numberOfChunks: scaleTs.u16,
241
+ chunkInterval: scaleTs.u16,
242
+ boostFee: scaleTs.u8,
243
+ brokerFee: scaleTs.u8,
244
+ affiliates: scaleTs.Vector(scaleTs.Struct({ accountIndex: scaleTs.u8, commissionBps: scaleTs.u8 }))
245
+ })
246
+ });
226
247
 
227
248
  // src/deposit.ts
228
249
  var encodeChainAddress = (data, asset) => {
@@ -244,11 +265,18 @@ var contractIdToInternalAsset = Object.fromEntries(
244
265
  );
245
266
  var parseVaultSwapData = (data) => {
246
267
  const version = data[0];
247
- assertion.assert(version === 0, "unsupported version");
248
268
  const contractId = data[1];
249
269
  const outputAsset = contractIdToInternalAsset[contractId];
270
+ let destinationAddress;
271
+ let parameters;
272
+ if (version === 1) {
273
+ ({ destinationAddress, parameters } = createSwapDataCodecV1(outputAsset).dec(data));
274
+ } else if (version === 0) {
275
+ ({ destinationAddress, parameters } = createSwapDataCodecV0(outputAsset).dec(data));
276
+ } else {
277
+ throw new Error("unsupported version");
278
+ }
250
279
  assertion.assert(outputAsset, "unknown asset contract id");
251
- const { destinationAddress, parameters } = createSwapDataCodec(outputAsset).dec(data);
252
280
  return {
253
281
  ...parameters,
254
282
  outputAsset,
@@ -271,7 +299,8 @@ var findVaultSwapData = async (url, txId) => {
271
299
  refundParams: {
272
300
  refundAddress: tx.vout[2].scriptPubKey.address,
273
301
  retryDuration: data.retryDuration,
274
- minPrice: getX128PriceFromAmounts(amount, data.minOutputAmount)
302
+ minPrice: getX128PriceFromAmounts(amount, data.minOutputAmount),
303
+ maxOraclePriceSlippage: "maxOraclePriceSlippage" in data ? data.maxOraclePriceSlippage : null
275
304
  },
276
305
  destinationAddress: data.destinationAddress,
277
306
  outputAsset: data.outputAsset,
package/dist/index.js CHANGED
@@ -158,10 +158,16 @@ var makeRequest = async (rpcUrl, method, params) => {
158
158
  params
159
159
  })
160
160
  });
161
- if (res.status !== 200) {
162
- throw new Error(`HTTP error [${res.status}]: ${await res.text() || res.statusText}`);
161
+ const text = await res.text();
162
+ let json;
163
+ try {
164
+ json = JSON.parse(text);
165
+ } catch {
166
+ if (res.status !== 200) {
167
+ throw new Error(`HTTP error [${res.status}]: ${text || res.statusText}`);
168
+ }
169
+ throw new Error(`Invalid JSON response: ${text}`);
163
170
  }
164
- const json = await res.json();
165
171
  const result = rpcResponse.parse(json);
166
172
  if (result.error) {
167
173
  if (result.error.code === -5) return null;
@@ -182,7 +188,7 @@ var addressByteLengths = {
182
188
  Polkadot: 32,
183
189
  Assethub: 32
184
190
  };
185
- var createSwapDataCodec = (asset) => Struct({
191
+ var createSwapDataCodecV0 = (asset) => Struct({
186
192
  version: u8,
187
193
  destinationAsset: u8,
188
194
  destinationAddress: Bytes(addressByteLengths[assetConstants[asset].chain]),
@@ -196,6 +202,21 @@ var createSwapDataCodec = (asset) => Struct({
196
202
  affiliates: Vector(Struct({ accountIndex: u8, commissionBps: u8 }))
197
203
  })
198
204
  });
205
+ var createSwapDataCodecV1 = (asset) => Struct({
206
+ version: u8,
207
+ destinationAsset: u8,
208
+ destinationAddress: Bytes(addressByteLengths[assetConstants[asset].chain]),
209
+ parameters: Struct({
210
+ retryDuration: u16,
211
+ minOutputAmount: u128,
212
+ maxOraclePriceSlippage: u8,
213
+ numberOfChunks: u16,
214
+ chunkInterval: u16,
215
+ boostFee: u8,
216
+ brokerFee: u8,
217
+ affiliates: Vector(Struct({ accountIndex: u8, commissionBps: u8 }))
218
+ })
219
+ });
199
220
 
200
221
  // src/deposit.ts
201
222
  var encodeChainAddress = (data, asset) => {
@@ -217,11 +238,18 @@ var contractIdToInternalAsset = Object.fromEntries(
217
238
  );
218
239
  var parseVaultSwapData = (data) => {
219
240
  const version = data[0];
220
- assert(version === 0, "unsupported version");
221
241
  const contractId = data[1];
222
242
  const outputAsset = contractIdToInternalAsset[contractId];
243
+ let destinationAddress;
244
+ let parameters;
245
+ if (version === 1) {
246
+ ({ destinationAddress, parameters } = createSwapDataCodecV1(outputAsset).dec(data));
247
+ } else if (version === 0) {
248
+ ({ destinationAddress, parameters } = createSwapDataCodecV0(outputAsset).dec(data));
249
+ } else {
250
+ throw new Error("unsupported version");
251
+ }
223
252
  assert(outputAsset, "unknown asset contract id");
224
- const { destinationAddress, parameters } = createSwapDataCodec(outputAsset).dec(data);
225
253
  return {
226
254
  ...parameters,
227
255
  outputAsset,
@@ -244,7 +272,8 @@ var findVaultSwapData = async (url, txId) => {
244
272
  refundParams: {
245
273
  refundAddress: tx.vout[2].scriptPubKey.address,
246
274
  retryDuration: data.retryDuration,
247
- minPrice: getX128PriceFromAmounts(amount, data.minOutputAmount)
275
+ minPrice: getX128PriceFromAmounts(amount, data.minOutputAmount),
276
+ maxOraclePriceSlippage: "maxOraclePriceSlippage" in data ? data.maxOraclePriceSlippage : null
248
277
  },
249
278
  destinationAddress: data.destinationAddress,
250
279
  outputAsset: data.outputAsset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/bitcoin",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
6
6
  "publishConfig": {
@@ -11,14 +11,24 @@
11
11
  "dist",
12
12
  "README.md"
13
13
  ],
14
- "main": "dist/index.cjs",
15
- "module": "dist/index.js",
14
+ "exports": {
15
+ ".": {
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ },
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ }
25
+ },
16
26
  "dependencies": {
17
- "@chainflip/utils": "0.8.3",
18
- "bignumber.js": "^9.2.0",
27
+ "@chainflip/utils": "0.8.18",
28
+ "bignumber.js": "^9.3.1",
19
29
  "bitcoinjs-lib": "7.0.0-rc.0",
20
30
  "scale-ts": "^1.6.1",
21
- "zod": "^3.24.2"
31
+ "zod": "^3.25.75"
22
32
  },
23
33
  "scripts": {
24
34
  "eslint:check": "pnpm eslint --max-warnings 0 './**/*.ts'",