@chainflip/sdk 1.4.0-alpha.1 → 1.4.0-alpha.3
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-QU4VVLJN.mjs +79 -0
- package/dist/{chunk-LQGUI52U.mjs → chunk-EEVRQLUS.mjs} +65 -236
- package/dist/{chunk-4HLERQ4Y.mjs → chunk-GCBDMMEA.mjs} +22 -161
- package/dist/chunk-GL7BY5NM.mjs +235 -0
- package/dist/{contracts-ZLesmWHT.d.mts → contracts-49zdGryt.d.mts} +9 -1
- package/dist/{contracts-ZLesmWHT.d.ts → contracts-49zdGryt.d.ts} +9 -1
- package/dist/funding.d.mts +1 -1
- package/dist/funding.d.ts +1 -1
- package/dist/funding.js +107 -4831
- package/dist/funding.mjs +2 -2
- package/dist/swap.d.mts +12 -4
- package/dist/swap.d.ts +12 -4
- package/dist/swap.js +94 -284
- package/dist/swap.mjs +5 -5
- package/package.json +3 -2
- package/dist/broker-XWF7RRDY.mjs +0 -124
- package/dist/chunk-KHC24Z3O.mjs +0 -65
package/dist/broker-XWF7RRDY.mjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { ccmMetadataSchema, affiliateBroker } from './chunk-KHC24Z3O.mjs';
|
|
2
|
-
import { z, __name, Chains, uncheckedAssetAndChain, numericString, hexString, btcAddress, hexStringFromNumber, dotAddress, ethereumAddress, unsignedInteger, u128 } from './chunk-LQGUI52U.mjs';
|
|
3
|
-
import { bytesToHex } from '@chainflip/utils/bytes';
|
|
4
|
-
import * as ss58 from '@chainflip/utils/ss58';
|
|
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
|
-
|
|
10
|
-
// ../shared/src/broker.ts
|
|
11
|
-
var transformObjToSnakeCase = /* @__PURE__ */ __name((obj) => {
|
|
12
|
-
if (!obj)
|
|
13
|
-
return void 0;
|
|
14
|
-
const newObj = {};
|
|
15
|
-
for (const key in obj) {
|
|
16
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
17
|
-
newObj[camelToSnakeCase(key)] = obj[key];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return newObj;
|
|
21
|
-
}, "transformObjToSnakeCase");
|
|
22
|
-
var submitAddress = /* @__PURE__ */ __name((chain, address) => {
|
|
23
|
-
if (chain === Chains.Polkadot) {
|
|
24
|
-
return address.startsWith("0x") ? z.string().length(66).parse(address) : bytesToHex(ss58.decode(address).data);
|
|
25
|
-
}
|
|
26
|
-
return address;
|
|
27
|
-
}, "submitAddress");
|
|
28
|
-
var rpcResult = z.union([
|
|
29
|
-
z.object({
|
|
30
|
-
error: z.object({
|
|
31
|
-
code: z.number().optional(),
|
|
32
|
-
message: z.string().optional(),
|
|
33
|
-
data: z.unknown().optional()
|
|
34
|
-
})
|
|
35
|
-
}),
|
|
36
|
-
z.object({
|
|
37
|
-
result: z.unknown()
|
|
38
|
-
})
|
|
39
|
-
]);
|
|
40
|
-
var requestValidators = /* @__PURE__ */ __name((network) => ({
|
|
41
|
-
requestSwapDepositAddress: z.tuple([
|
|
42
|
-
uncheckedAssetAndChain,
|
|
43
|
-
uncheckedAssetAndChain,
|
|
44
|
-
z.union([
|
|
45
|
-
numericString,
|
|
46
|
-
hexString,
|
|
47
|
-
btcAddress(network)
|
|
48
|
-
]),
|
|
49
|
-
z.number(),
|
|
50
|
-
ccmMetadataSchema.merge(z.object({
|
|
51
|
-
gasBudget: hexStringFromNumber,
|
|
52
|
-
cfParameters: z.union([
|
|
53
|
-
hexString,
|
|
54
|
-
z.string()
|
|
55
|
-
]).optional()
|
|
56
|
-
})).optional(),
|
|
57
|
-
z.number().optional(),
|
|
58
|
-
z.array(affiliateBroker).optional()
|
|
59
|
-
]).transform(([a, b, c, d, e, f, g]) => g ? [
|
|
60
|
-
a,
|
|
61
|
-
b,
|
|
62
|
-
c,
|
|
63
|
-
d,
|
|
64
|
-
transformObjToSnakeCase(e),
|
|
65
|
-
f,
|
|
66
|
-
g
|
|
67
|
-
] : [
|
|
68
|
-
a,
|
|
69
|
-
b,
|
|
70
|
-
c,
|
|
71
|
-
d,
|
|
72
|
-
transformObjToSnakeCase(e),
|
|
73
|
-
f
|
|
74
|
-
])
|
|
75
|
-
}), "requestValidators");
|
|
76
|
-
var responseValidators = /* @__PURE__ */ __name((network) => ({
|
|
77
|
-
requestSwapDepositAddress: z.object({
|
|
78
|
-
address: z.union([
|
|
79
|
-
dotAddress,
|
|
80
|
-
ethereumAddress,
|
|
81
|
-
btcAddress(network)
|
|
82
|
-
]),
|
|
83
|
-
issued_block: z.number(),
|
|
84
|
-
channel_id: z.number(),
|
|
85
|
-
expiry_block: z.number().int().safe().positive().optional(),
|
|
86
|
-
source_chain_expiry_block: unsignedInteger.optional(),
|
|
87
|
-
channel_opening_fee: u128.optional().default(0)
|
|
88
|
-
}).transform(({ address, issued_block, channel_id, source_chain_expiry_block, channel_opening_fee }) => ({
|
|
89
|
-
address,
|
|
90
|
-
issuedBlock: issued_block,
|
|
91
|
-
channelId: BigInt(channel_id),
|
|
92
|
-
sourceChainExpiryBlock: source_chain_expiry_block,
|
|
93
|
-
channelOpeningFee: channel_opening_fee
|
|
94
|
-
}))
|
|
95
|
-
}), "responseValidators");
|
|
96
|
-
var makeRpcRequest = /* @__PURE__ */ __name(async (network, url, method, ...params) => {
|
|
97
|
-
const res = await axios.post(url.toString(), {
|
|
98
|
-
jsonrpc: "2.0",
|
|
99
|
-
id: 1,
|
|
100
|
-
method: `broker_${method}`,
|
|
101
|
-
params: requestValidators(network)[method].parse(params)
|
|
102
|
-
});
|
|
103
|
-
const result = rpcResult.parse(res.data);
|
|
104
|
-
if ("error" in result) {
|
|
105
|
-
throw new Error(`Broker responded with error code ${result.error.code}: ${result.error.message}`);
|
|
106
|
-
}
|
|
107
|
-
return responseValidators(network)[method].parse(result.result);
|
|
108
|
-
}, "makeRpcRequest");
|
|
109
|
-
async function requestSwapDepositAddress(swapRequest, opts, chainflipNetwork) {
|
|
110
|
-
const { srcAsset, srcChain, destAsset, destChain, destAddress, maxBoostFeeBps } = swapRequest;
|
|
111
|
-
return makeRpcRequest(chainflipNetwork, opts.url, "requestSwapDepositAddress", {
|
|
112
|
-
asset: srcAsset,
|
|
113
|
-
chain: srcChain
|
|
114
|
-
}, {
|
|
115
|
-
asset: destAsset,
|
|
116
|
-
chain: destChain
|
|
117
|
-
}, submitAddress(destChain, destAddress), opts.commissionBps, swapRequest.ccmMetadata && {
|
|
118
|
-
...swapRequest.ccmMetadata,
|
|
119
|
-
cfParameters: void 0
|
|
120
|
-
}, maxBoostFeeBps, opts.affiliates);
|
|
121
|
-
}
|
|
122
|
-
__name(requestSwapDepositAddress, "requestSwapDepositAddress");
|
|
123
|
-
|
|
124
|
-
export { requestSwapDepositAddress };
|
package/dist/chunk-KHC24Z3O.mjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { z, chain, asset, numericString, numericOrEmptyString, getInternalAssets, hexStringWithMaxByteSize, chainflipAddress, number } from './chunk-LQGUI52U.mjs';
|
|
2
|
-
|
|
3
|
-
// ../shared/src/schemas.ts
|
|
4
|
-
z.object({
|
|
5
|
-
srcChain: chain,
|
|
6
|
-
srcAsset: asset,
|
|
7
|
-
destChain: chain,
|
|
8
|
-
destAsset: asset,
|
|
9
|
-
amount: numericString.transform((n) => BigInt(n)),
|
|
10
|
-
brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional()
|
|
11
|
-
}).transform((args, ctx) => {
|
|
12
|
-
const { srcAsset, destAsset } = getInternalAssets(args, false);
|
|
13
|
-
if (srcAsset === null) {
|
|
14
|
-
ctx.addIssue({
|
|
15
|
-
message: `invalid asset and chain combination: ${JSON.stringify({
|
|
16
|
-
asset: args.srcAsset,
|
|
17
|
-
chain: args.srcChain
|
|
18
|
-
})}`,
|
|
19
|
-
code: z.ZodIssueCode.custom
|
|
20
|
-
});
|
|
21
|
-
return z.NEVER;
|
|
22
|
-
}
|
|
23
|
-
if (destAsset === null) {
|
|
24
|
-
ctx.addIssue({
|
|
25
|
-
message: `invalid asset and chain combination: ${JSON.stringify({
|
|
26
|
-
asset: args.destAsset,
|
|
27
|
-
chain: args.destChain
|
|
28
|
-
})}`,
|
|
29
|
-
code: z.ZodIssueCode.custom
|
|
30
|
-
});
|
|
31
|
-
return z.NEVER;
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
srcAsset,
|
|
35
|
-
destAsset,
|
|
36
|
-
amount: args.amount,
|
|
37
|
-
brokerCommissionBps: args.brokerCommissionBps
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
var ccmMetadataSchema = z.object({
|
|
41
|
-
gasBudget: numericString,
|
|
42
|
-
message: hexStringWithMaxByteSize(1024 * 10)
|
|
43
|
-
});
|
|
44
|
-
var affiliateBroker = z.object({
|
|
45
|
-
account: chainflipAddress,
|
|
46
|
-
commissionBps: number
|
|
47
|
-
}).transform(({ account, commissionBps: bps }) => ({
|
|
48
|
-
account,
|
|
49
|
-
bps
|
|
50
|
-
}));
|
|
51
|
-
z.object({
|
|
52
|
-
srcAsset: asset,
|
|
53
|
-
destAsset: asset,
|
|
54
|
-
srcChain: chain,
|
|
55
|
-
destChain: chain,
|
|
56
|
-
destAddress: z.string(),
|
|
57
|
-
amount: numericString,
|
|
58
|
-
ccmMetadata: ccmMetadataSchema.optional(),
|
|
59
|
-
maxBoostFeeBps: z.number().optional()
|
|
60
|
-
}).transform(({ amount, ...rest }) => ({
|
|
61
|
-
...rest,
|
|
62
|
-
expectedDepositAmount: amount
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
export { affiliateBroker, ccmMetadataSchema };
|