@chainflip/sdk 0.2.8 → 0.2.10
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/broker-FONIQXKG.mjs +90 -0
- package/dist/chunk-DGDQYRRV.mjs +4176 -0
- package/dist/{chunk-MGNNXMB7.mjs → chunk-LNM2TOMZ.mjs} +2 -89
- package/dist/chunk-NX4K76K7.mjs +91 -0
- package/dist/funding.mjs +2 -1
- package/dist/swap.js +6317 -6151
- package/dist/swap.mjs +28 -4196
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z, chainflipAsset, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-DGDQYRRV.mjs';
|
|
2
|
+
import { isNotNullish, __name, Assets } from './chunk-NX4K76K7.mjs';
|
|
3
|
+
import { u8aToHex } from '@polkadot/util';
|
|
4
|
+
import { decodeAddress } from '@polkadot/util-crypto';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
|
|
7
|
+
// ../shared/src/strings.ts
|
|
8
|
+
var camelToSnakeCase = /* @__PURE__ */ __name((str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), "camelToSnakeCase");
|
|
9
|
+
var transformAsset = /* @__PURE__ */ __name((asset) => asset[0] + asset.slice(1).toLowerCase(), "transformAsset");
|
|
10
|
+
|
|
11
|
+
// ../shared/src/broker.ts
|
|
12
|
+
var transformObjToSnakeCase = /* @__PURE__ */ __name((obj) => {
|
|
13
|
+
if (!obj)
|
|
14
|
+
return void 0;
|
|
15
|
+
const newObj = {};
|
|
16
|
+
for (const key in obj) {
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
18
|
+
newObj[camelToSnakeCase(key)] = obj[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return newObj;
|
|
22
|
+
}, "transformObjToSnakeCase");
|
|
23
|
+
var submitAddress = /* @__PURE__ */ __name((asset, address) => {
|
|
24
|
+
if (asset === Assets.DOT) {
|
|
25
|
+
return address.startsWith("0x") ? z.string().length(66).parse(address) : u8aToHex(decodeAddress(address));
|
|
26
|
+
}
|
|
27
|
+
return address;
|
|
28
|
+
}, "submitAddress");
|
|
29
|
+
var requestValidators = {
|
|
30
|
+
requestSwapDepositAddress: z.tuple([
|
|
31
|
+
chainflipAsset.transform(transformAsset),
|
|
32
|
+
chainflipAsset.transform(transformAsset),
|
|
33
|
+
z.union([
|
|
34
|
+
numericString,
|
|
35
|
+
hexString,
|
|
36
|
+
btcAddress()
|
|
37
|
+
]),
|
|
38
|
+
z.number(),
|
|
39
|
+
ccmMetadataSchema.merge(z.object({
|
|
40
|
+
gasBudget: hexStringFromNumber,
|
|
41
|
+
cfParameters: z.union([
|
|
42
|
+
hexString,
|
|
43
|
+
z.string()
|
|
44
|
+
]).optional()
|
|
45
|
+
})).optional()
|
|
46
|
+
]).transform(([a, b, c, d, e]) => [
|
|
47
|
+
a,
|
|
48
|
+
b,
|
|
49
|
+
c,
|
|
50
|
+
d,
|
|
51
|
+
transformObjToSnakeCase(e)
|
|
52
|
+
].filter(isNotNullish))
|
|
53
|
+
};
|
|
54
|
+
var responseValidators = {
|
|
55
|
+
requestSwapDepositAddress: z.object({
|
|
56
|
+
address: z.union([
|
|
57
|
+
dotAddress,
|
|
58
|
+
hexString,
|
|
59
|
+
btcAddress()
|
|
60
|
+
]),
|
|
61
|
+
issued_block: z.number(),
|
|
62
|
+
channel_id: z.number(),
|
|
63
|
+
expiry_block: z.number().int().safe().positive().optional(),
|
|
64
|
+
source_chain_expiry_block: unsignedInteger.optional()
|
|
65
|
+
}).transform(({ address, issued_block, channel_id, source_chain_expiry_block }) => ({
|
|
66
|
+
address,
|
|
67
|
+
issuedBlock: issued_block,
|
|
68
|
+
channelId: BigInt(channel_id),
|
|
69
|
+
sourceChainExpiryBlock: source_chain_expiry_block
|
|
70
|
+
}))
|
|
71
|
+
};
|
|
72
|
+
var makeRpcRequest = /* @__PURE__ */ __name(async (url, method, ...params) => {
|
|
73
|
+
const res = await axios.post(url.toString(), {
|
|
74
|
+
jsonrpc: "2.0",
|
|
75
|
+
id: 1,
|
|
76
|
+
method: `broker_${method}`,
|
|
77
|
+
params: requestValidators[method].parse(params)
|
|
78
|
+
});
|
|
79
|
+
return responseValidators[method].parse(res.data.result);
|
|
80
|
+
}, "makeRpcRequest");
|
|
81
|
+
async function requestSwapDepositAddress(swapRequest, opts) {
|
|
82
|
+
const { srcAsset, destAsset, destAddress } = swapRequest;
|
|
83
|
+
return makeRpcRequest(opts.url, "requestSwapDepositAddress", srcAsset, destAsset, submitAddress(destAsset, destAddress), opts.commissionBps, swapRequest.ccmMetadata && {
|
|
84
|
+
...swapRequest.ccmMetadata,
|
|
85
|
+
cfParameters: void 0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
__name(requestSwapDepositAddress, "requestSwapDepositAddress");
|
|
89
|
+
|
|
90
|
+
export { requestSwapDepositAddress };
|