@chainflip/sdk 1.5.1 → 1.5.2

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.
@@ -1,7 +1,224 @@
1
- import { getInternalAsset, __name, __publicField, ChainflipNetworks, Chains, InternalAssets } from './chunk-3V7QJANN.mjs';
2
1
  import { constants, HttpClient } from '@chainflip/rpc';
3
2
  import { Interface, Contract } from 'ethers';
4
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+
9
+ // ../shared/src/enums.ts
10
+ var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
11
+ key,
12
+ key
13
+ ])), "arrayToMap");
14
+ var InternalAssets = arrayToMap([
15
+ "Flip",
16
+ "Usdc",
17
+ "Dot",
18
+ "Eth",
19
+ "Btc",
20
+ "Usdt",
21
+ "ArbUsdc",
22
+ "ArbEth"
23
+ ]);
24
+ var Chains = arrayToMap([
25
+ "Bitcoin",
26
+ "Ethereum",
27
+ "Polkadot",
28
+ "Arbitrum"
29
+ ]);
30
+ var Assets = arrayToMap([
31
+ "FLIP",
32
+ "USDC",
33
+ "DOT",
34
+ "ETH",
35
+ "BTC",
36
+ "USDT"
37
+ ]);
38
+ var ChainflipNetworks = arrayToMap([
39
+ "backspin",
40
+ "sisyphos",
41
+ "perseverance",
42
+ "mainnet"
43
+ ]);
44
+ var isTestnet = /* @__PURE__ */ __name((network) => network !== ChainflipNetworks.mainnet, "isTestnet");
45
+ var assetConstants = {
46
+ [InternalAssets.Eth]: {
47
+ chain: Chains.Ethereum,
48
+ asset: Assets.ETH,
49
+ name: "Ether",
50
+ decimals: 18,
51
+ contractId: 1
52
+ },
53
+ [InternalAssets.Flip]: {
54
+ chain: Chains.Ethereum,
55
+ asset: Assets.FLIP,
56
+ name: "FLIP",
57
+ decimals: 18,
58
+ contractId: 2
59
+ },
60
+ [InternalAssets.Usdc]: {
61
+ chain: Chains.Ethereum,
62
+ asset: Assets.USDC,
63
+ name: "USDC",
64
+ decimals: 6,
65
+ contractId: 3
66
+ },
67
+ [InternalAssets.Usdt]: {
68
+ chain: Chains.Ethereum,
69
+ asset: Assets.USDT,
70
+ name: "USDT",
71
+ decimals: 6,
72
+ contractId: 8
73
+ },
74
+ [InternalAssets.Dot]: {
75
+ chain: Chains.Polkadot,
76
+ asset: Assets.DOT,
77
+ name: "Polkadot",
78
+ decimals: 10,
79
+ contractId: 4
80
+ },
81
+ [InternalAssets.Btc]: {
82
+ chain: Chains.Bitcoin,
83
+ asset: Assets.BTC,
84
+ name: "Bitcoin",
85
+ decimals: 8,
86
+ contractId: 5
87
+ },
88
+ [InternalAssets.ArbEth]: {
89
+ chain: Chains.Arbitrum,
90
+ asset: Assets.ETH,
91
+ name: "Arbitrum Ether",
92
+ decimals: 18,
93
+ contractId: 6
94
+ },
95
+ [InternalAssets.ArbUsdc]: {
96
+ chain: Chains.Arbitrum,
97
+ asset: Assets.USDC,
98
+ name: "Arbitrum USDC",
99
+ decimals: 6,
100
+ contractId: 7
101
+ }
102
+ };
103
+ var chainConstants = {
104
+ [Chains.Ethereum]: {
105
+ assets: [
106
+ Assets.ETH,
107
+ Assets.FLIP,
108
+ Assets.USDC,
109
+ Assets.USDT
110
+ ],
111
+ gasAsset: Assets.ETH,
112
+ contractId: 1,
113
+ blockTimeSeconds: 12
114
+ },
115
+ [Chains.Polkadot]: {
116
+ assets: [
117
+ Assets.DOT
118
+ ],
119
+ gasAsset: Assets.DOT,
120
+ contractId: 2,
121
+ blockTimeSeconds: 6
122
+ },
123
+ [Chains.Bitcoin]: {
124
+ assets: [
125
+ Assets.BTC
126
+ ],
127
+ gasAsset: Assets.BTC,
128
+ contractId: 3,
129
+ blockTimeSeconds: 10 * 60
130
+ },
131
+ [Chains.Arbitrum]: {
132
+ assets: [
133
+ Assets.ETH,
134
+ Assets.USDC
135
+ ],
136
+ gasAsset: Assets.ETH,
137
+ contractId: 4,
138
+ blockTimeSeconds: 0.26
139
+ }
140
+ };
141
+ function isValidAssetAndChain(assetAndChain) {
142
+ const { asset, chain } = assetAndChain;
143
+ if (!(chain in Chains)) return false;
144
+ const validAssets = chainConstants[chain].assets;
145
+ return validAssets.includes(asset);
146
+ }
147
+ __name(isValidAssetAndChain, "isValidAssetAndChain");
148
+ var readChainAssetValue = /* @__PURE__ */ __name((map, asset) => {
149
+ const { chain, asset: symbol } = assetConstants[asset];
150
+ const chainValues = map[chain];
151
+ return chainValues[symbol];
152
+ }, "readChainAssetValue");
153
+ function getInternalAsset(asset, assert2 = true) {
154
+ if (!isValidAssetAndChain(asset)) {
155
+ if (assert2) {
156
+ throw new Error(`invalid asset and chain combination: ${JSON.stringify(asset)}`);
157
+ }
158
+ return null;
159
+ }
160
+ const map = {
161
+ [Chains.Ethereum]: {
162
+ [Assets.USDC]: InternalAssets.Usdc,
163
+ [Assets.FLIP]: InternalAssets.Flip,
164
+ [Assets.ETH]: InternalAssets.Eth,
165
+ [Assets.USDT]: InternalAssets.Usdt
166
+ },
167
+ [Chains.Bitcoin]: {
168
+ [Assets.BTC]: InternalAssets.Btc
169
+ },
170
+ [Chains.Polkadot]: {
171
+ [Assets.DOT]: InternalAssets.Dot
172
+ },
173
+ [Chains.Arbitrum]: {
174
+ [Assets.USDC]: InternalAssets.ArbUsdc,
175
+ [Assets.ETH]: InternalAssets.ArbEth
176
+ }
177
+ };
178
+ const chain = map[asset.chain];
179
+ return chain[asset.asset];
180
+ }
181
+ __name(getInternalAsset, "getInternalAsset");
182
+ function getInternalAssets({ srcAsset, srcChain, destAsset, destChain }, assert2 = true) {
183
+ return {
184
+ srcAsset: getInternalAsset({
185
+ asset: srcAsset,
186
+ chain: srcChain
187
+ }, assert2),
188
+ destAsset: getInternalAsset({
189
+ asset: destAsset,
190
+ chain: destChain
191
+ }, assert2)
192
+ };
193
+ }
194
+ __name(getInternalAssets, "getInternalAssets");
195
+ function getAssetAndChain(internalAsset, prefix) {
196
+ const { chain, asset } = assetConstants[internalAsset];
197
+ if (prefix) {
198
+ return {
199
+ [`${prefix}Asset`]: asset,
200
+ [`${prefix}Chain`]: chain
201
+ };
202
+ }
203
+ return {
204
+ chain,
205
+ asset
206
+ };
207
+ }
208
+ __name(getAssetAndChain, "getAssetAndChain");
209
+
210
+ // ../shared/src/guards.ts
211
+ var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
212
+ var isNotNullish = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isNotNullish");
213
+ function assert(condition, message) {
214
+ if (condition) return;
215
+ const error = new Error(message);
216
+ if (error.stack) {
217
+ error.stack = error.stack.replace(/\n.+/, "\n");
218
+ }
219
+ throw error;
220
+ }
221
+ __name(assert, "assert");
5
222
  var camelCase = /* @__PURE__ */ __name((str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), "camelCase");
6
223
  var camelCaseKeys = /* @__PURE__ */ __name((obj) => {
7
224
  if (typeof obj !== "object" || obj === null) return obj;
@@ -2121,4 +2338,4 @@ var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
2121
2338
  return flip.balanceOf(await signer.getAddress());
2122
2339
  }, "getFlipBalance");
2123
2340
 
2124
- export { StateChainGateway__factory, Vault__factory, approve, checkAllowance, extractOverrides, getAllBoostPoolsDepth, getEnvironment, getEvmChainId, getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, getSupportedAssets, getTokenContractAddress, getVaultContractAddress };
2341
+ export { Assets, ChainflipNetworks, Chains, InternalAssets, StateChainGateway__factory, Vault__factory, __name, __publicField, approve, assert, assetConstants, chainConstants, checkAllowance, extractOverrides, getAllBoostPoolsDepth, getAssetAndChain, getEnvironment, getEvmChainId, getFlipBalance, getFundingEnvironment, getInternalAsset, getInternalAssets, getStateChainGatewayContractAddress, getSupportedAssets, getTokenContractAddress, getVaultContractAddress, isNotNullish, isString, isTestnet, isValidAssetAndChain, readChainAssetValue };
package/dist/funding.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-M32JHS3U.mjs';
2
- import { __name, __publicField, ChainflipNetworks, InternalAssets, assert } from './chunk-3V7QJANN.mjs';
1
+ import { __name, __publicField, ChainflipNetworks, getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, InternalAssets, checkAllowance, assert, extractOverrides, StateChainGateway__factory } from './chunk-URS5YVDJ.mjs';
3
2
 
4
3
  // ../shared/src/stateChainGateway/utils.ts
5
4
  var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {