@chainflip/bitcoin 1.2.3 → 1.2.5

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
@@ -7,7 +7,7 @@ var base58 = require('@chainflip/utils/base58');
7
7
  var chainflip = require('@chainflip/utils/chainflip');
8
8
  var consts = require('@chainflip/utils/consts');
9
9
  var ss58 = require('@chainflip/utils/ss58');
10
- var BigNumber = require('bignumber.js');
10
+ var BigNumber2 = require('bignumber.js');
11
11
  var url = require('@chainflip/utils/url');
12
12
  var zod = require('zod');
13
13
  var scaleTs = require('scale-ts');
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
35
35
  var bitcoin__namespace = /*#__PURE__*/_interopNamespace(bitcoin);
36
36
  var base58__namespace = /*#__PURE__*/_interopNamespace(base58);
37
37
  var ss58__namespace = /*#__PURE__*/_interopNamespace(ss58);
38
- var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber);
38
+ var BigNumber2__default = /*#__PURE__*/_interopDefault(BigNumber2);
39
39
 
40
40
  // src/address.ts
41
41
 
@@ -133,7 +133,7 @@ var isValidAddressForNetwork = (address2, cfOrBtcNetwork) => {
133
133
  };
134
134
  var hexString = zod.z.string().regex(/^([0-9a-f]{2})+$/, { message: "expected hex string" });
135
135
  var vout = zod.z.object({
136
- value: zod.z.number().transform((n) => BigInt(new BigNumber__default.default(n).shiftedBy(8).toFixed(0))),
136
+ value: zod.z.number().transform((n) => BigInt(new BigNumber2__default.default(n).shiftedBy(8).toFixed(0))),
137
137
  n: zod.z.number()
138
138
  });
139
139
  var nulldataVout = zod.z.object({
@@ -185,6 +185,9 @@ 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}`);
190
+ }
188
191
  const json = await res.json();
189
192
  const result = rpcResponse.parse(json);
190
193
  if (result.error) {
@@ -203,7 +206,8 @@ var addressByteLengths = {
203
206
  Arbitrum: 20,
204
207
  Ethereum: 20,
205
208
  Solana: 32,
206
- Polkadot: 32
209
+ Polkadot: 32,
210
+ Assethub: 32
207
211
  };
208
212
  var createSwapDataCodec = (asset) => scaleTs.Struct({
209
213
  version: scaleTs.u8,
@@ -225,6 +229,7 @@ var encodeChainAddress = (data, asset) => {
225
229
  switch (chainflip.assetConstants[asset].chain) {
226
230
  case "Solana":
227
231
  return base58__namespace.encode(data);
232
+ case "Assethub":
228
233
  case "Polkadot":
229
234
  return ss58__namespace.encode({ data, ss58Format: consts.POLKADOT_SS58_PREFIX });
230
235
  case "Ethereum":
@@ -251,7 +256,7 @@ var parseVaultSwapData = (data) => {
251
256
  };
252
257
  };
253
258
  var getX128PriceFromAmounts = (depositAmount, minOutputAmount) => BigInt(
254
- new BigNumber.BigNumber(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber.BigNumber(2).pow(128)).toFixed(0, BigNumber.BigNumber.ROUND_FLOOR)
259
+ new BigNumber2__default.default(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber2__default.default(2).pow(128)).toFixed(0, BigNumber2__default.default.ROUND_FLOOR)
255
260
  );
256
261
  var findVaultSwapData = async (url, txId) => {
257
262
  const tx = await makeRequest(url, "getrawtransaction", [txId, true]);
@@ -274,10 +279,7 @@ var findVaultSwapData = async (url, txId) => {
274
279
  affiliateFees: data.affiliates,
275
280
  ccmDepositMetadata: null,
276
281
  maxBoostFee: data.boostFee,
277
- dcaParams: data.numberOfChunks > 0 && data.chunkInterval > 0 ? {
278
- chunkInterval: data.chunkInterval,
279
- numberOfChunks: data.numberOfChunks
280
- } : null,
282
+ dcaParams: data.numberOfChunks === 1 && data.chunkInterval === 2 ? null : { chunkInterval: data.chunkInterval, numberOfChunks: data.numberOfChunks },
281
283
  depositChainBlockHeight: block && block.height
282
284
  };
283
285
  };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- import { ChainflipNetwork as ChainflipNetwork$1 } from '@chainflip/utils/chainflip';
1
+ import { ChainflipNetwork } from '@chainflip/utils/chainflip';
2
2
  import { VaultSwapData } from '@chainflip/utils/types';
3
3
 
4
- type ChainflipNetwork = 'mainnet' | 'perseverance' | 'sisyphos' | 'backspin';
5
4
  type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest';
6
5
 
7
6
  type Bytelike = Uint8Array | number[] | `0x${string}`;
@@ -24,13 +23,13 @@ type DecodedSegwitAddress = {
24
23
  version: number;
25
24
  };
26
25
  type SegwitAddressType = 'P2WPKH' | 'P2WSH' | 'Taproot';
27
- declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork$1) => string;
28
- declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => DecodedBase58Address | DecodedSegwitAddress;
29
- declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => boolean;
26
+ declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork) => string;
27
+ declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => DecodedBase58Address | DecodedSegwitAddress;
28
+ declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => boolean;
30
29
 
31
30
  type BitcoinVaultSwapData = VaultSwapData<null> & {
32
31
  depositAddress: string;
33
32
  };
34
33
  declare const findVaultSwapData: (url: string, txId: string) => Promise<BitcoinVaultSwapData | null>;
35
34
 
36
- export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type ChainflipNetwork, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
35
+ export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { ChainflipNetwork as ChainflipNetwork$1 } from '@chainflip/utils/chainflip';
1
+ import { ChainflipNetwork } from '@chainflip/utils/chainflip';
2
2
  import { VaultSwapData } from '@chainflip/utils/types';
3
3
 
4
- type ChainflipNetwork = 'mainnet' | 'perseverance' | 'sisyphos' | 'backspin';
5
4
  type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest';
6
5
 
7
6
  type Bytelike = Uint8Array | number[] | `0x${string}`;
@@ -24,13 +23,13 @@ type DecodedSegwitAddress = {
24
23
  version: number;
25
24
  };
26
25
  type SegwitAddressType = 'P2WPKH' | 'P2WSH' | 'Taproot';
27
- declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork$1) => string;
28
- declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => DecodedBase58Address | DecodedSegwitAddress;
29
- declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => boolean;
26
+ declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork) => string;
27
+ declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => DecodedBase58Address | DecodedSegwitAddress;
28
+ declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => boolean;
30
29
 
31
30
  type BitcoinVaultSwapData = VaultSwapData<null> & {
32
31
  depositAddress: string;
33
32
  };
34
33
  declare const findVaultSwapData: (url: string, txId: string) => Promise<BitcoinVaultSwapData | null>;
35
34
 
36
- export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type ChainflipNetwork, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
35
+ export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import * as base58 from '@chainflip/utils/base58';
5
5
  import { assetContractId, assetConstants } from '@chainflip/utils/chainflip';
6
6
  import { POLKADOT_SS58_PREFIX } from '@chainflip/utils/consts';
7
7
  import * as ss58 from '@chainflip/utils/ss58';
8
- import BigNumber, { BigNumber as BigNumber$1 } from 'bignumber.js';
8
+ import BigNumber2 from 'bignumber.js';
9
9
  import { parseUrlWithBasicAuth } from '@chainflip/utils/url';
10
10
  import { z } from 'zod';
11
11
  import { Struct, Bytes, u8, Vector, u16, u128 } from 'scale-ts';
@@ -106,7 +106,7 @@ var isValidAddressForNetwork = (address2, cfOrBtcNetwork) => {
106
106
  };
107
107
  var hexString = z.string().regex(/^([0-9a-f]{2})+$/, { message: "expected hex string" });
108
108
  var vout = z.object({
109
- value: z.number().transform((n) => BigInt(new BigNumber(n).shiftedBy(8).toFixed(0))),
109
+ value: z.number().transform((n) => BigInt(new BigNumber2(n).shiftedBy(8).toFixed(0))),
110
110
  n: z.number()
111
111
  });
112
112
  var nulldataVout = z.object({
@@ -158,6 +158,9 @@ 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}`);
163
+ }
161
164
  const json = await res.json();
162
165
  const result = rpcResponse.parse(json);
163
166
  if (result.error) {
@@ -176,7 +179,8 @@ var addressByteLengths = {
176
179
  Arbitrum: 20,
177
180
  Ethereum: 20,
178
181
  Solana: 32,
179
- Polkadot: 32
182
+ Polkadot: 32,
183
+ Assethub: 32
180
184
  };
181
185
  var createSwapDataCodec = (asset) => Struct({
182
186
  version: u8,
@@ -198,6 +202,7 @@ var encodeChainAddress = (data, asset) => {
198
202
  switch (assetConstants[asset].chain) {
199
203
  case "Solana":
200
204
  return base58.encode(data);
205
+ case "Assethub":
201
206
  case "Polkadot":
202
207
  return ss58.encode({ data, ss58Format: POLKADOT_SS58_PREFIX });
203
208
  case "Ethereum":
@@ -224,7 +229,7 @@ var parseVaultSwapData = (data) => {
224
229
  };
225
230
  };
226
231
  var getX128PriceFromAmounts = (depositAmount, minOutputAmount) => BigInt(
227
- new BigNumber$1(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber$1(2).pow(128)).toFixed(0, BigNumber$1.ROUND_FLOOR)
232
+ new BigNumber2(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber2(2).pow(128)).toFixed(0, BigNumber2.ROUND_FLOOR)
228
233
  );
229
234
  var findVaultSwapData = async (url, txId) => {
230
235
  const tx = await makeRequest(url, "getrawtransaction", [txId, true]);
@@ -247,10 +252,7 @@ var findVaultSwapData = async (url, txId) => {
247
252
  affiliateFees: data.affiliates,
248
253
  ccmDepositMetadata: null,
249
254
  maxBoostFee: data.boostFee,
250
- dcaParams: data.numberOfChunks > 0 && data.chunkInterval > 0 ? {
251
- chunkInterval: data.chunkInterval,
252
- numberOfChunks: data.numberOfChunks
253
- } : null,
255
+ dcaParams: data.numberOfChunks === 1 && data.chunkInterval === 2 ? null : { chunkInterval: data.chunkInterval, numberOfChunks: data.numberOfChunks },
254
256
  depositChainBlockHeight: block && block.height
255
257
  };
256
258
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/bitcoin",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
6
6
  "publishConfig": {
@@ -14,9 +14,9 @@
14
14
  "main": "dist/index.cjs",
15
15
  "module": "dist/index.js",
16
16
  "dependencies": {
17
- "@chainflip/utils": "0.7.2",
18
- "bignumber.js": "^9.1.2",
19
- "bitcoinjs-lib": "^7.0.0-rc.0",
17
+ "@chainflip/utils": "0.8.3",
18
+ "bignumber.js": "^9.2.0",
19
+ "bitcoinjs-lib": "7.0.0-rc.0",
20
20
  "scale-ts": "^1.6.1",
21
21
  "zod": "^3.24.2"
22
22
  },