@coinlist-co/react 0.12.2-rc.818bed6 → 0.12.2-rc.8a65e9d
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/README.md +10 -0
- package/dist/{chunk-YMDYLYL3.js → chunk-2FZAXGVH.js} +996 -1225
- package/dist/chunk-2FZAXGVH.js.map +1 -0
- package/dist/{chunk-OUFI3D3Q.js → chunk-EAPBF7T2.js} +152 -240
- package/dist/chunk-EAPBF7T2.js.map +1 -0
- package/dist/chunk-IWQ6A52U.js +24 -0
- package/dist/chunk-IWQ6A52U.js.map +1 -0
- package/dist/{chunk-2HCSM3FB.js → chunk-OQ2ANYUF.js} +334 -27
- package/dist/chunk-OQ2ANYUF.js.map +1 -0
- package/dist/client/index.d.ts +3269 -5861
- package/dist/client/index.js +10650 -10797
- package/dist/client/index.js.map +1 -1
- package/dist/client-credentials-BwcmPcn-.d.ts +13 -0
- package/dist/server/index.d.ts +54 -135
- package/dist/server/index.js +211 -171
- package/dist/server/index.js.map +1 -1
- package/dist/{time-DJU6E8KK.d.cts → time-ChSGmKZe.d.ts} +2177 -3470
- package/dist/{token-registry-snapshot-DGG5N27C.d.ts → token-registry-snapshot-DMubXr2c.d.ts} +22 -58
- package/dist/universal/index.d.ts +94 -1082
- package/dist/universal/index.js +25 -51
- package/package.json +18 -14
- package/dist/chunk-2HCSM3FB.js.map +0 -1
- package/dist/chunk-OUFI3D3Q.js.map +0 -1
- package/dist/chunk-YMDYLYL3.js.map +0 -1
- package/dist/client/index.cjs +0 -20774
- package/dist/client/index.cjs.map +0 -1
- package/dist/client/index.d.cts +0 -8328
- package/dist/server/index.cjs +0 -4580
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -385
- package/dist/time-DJU6E8KK.d.ts +0 -4052
- package/dist/token-registry-snapshot-B0xCp3GD.d.cts +0 -245
- package/dist/universal/index.cjs +0 -4625
- package/dist/universal/index.cjs.map +0 -1
- package/dist/universal/index.d.cts +0 -1376
|
@@ -1,93 +1,4 @@
|
|
|
1
|
-
// src/universal/
|
|
2
|
-
var SentWith = {
|
|
3
|
-
userToken: (token) => ({
|
|
4
|
-
type: "user-token",
|
|
5
|
-
token
|
|
6
|
-
}),
|
|
7
|
-
noUserToken: { type: "no-user-token" }
|
|
8
|
-
};
|
|
9
|
-
var TokenTrigger = {
|
|
10
|
-
beforeRequest: { type: "before-request" },
|
|
11
|
-
after401: (rejected) => ({
|
|
12
|
-
type: "after-401",
|
|
13
|
-
rejected
|
|
14
|
-
})
|
|
15
|
-
};
|
|
16
|
-
function isRejectedToken(token, rejected) {
|
|
17
|
-
switch (rejected.type) {
|
|
18
|
-
case "user-token":
|
|
19
|
-
return rejected.token.value === token.value;
|
|
20
|
-
case "no-user-token":
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/universal/api/http-attributes.ts
|
|
26
|
-
var empty = {};
|
|
27
|
-
var concat = (left, right) => ({
|
|
28
|
-
...left,
|
|
29
|
-
...right
|
|
30
|
-
});
|
|
31
|
-
var concatAll = (...items) => {
|
|
32
|
-
let result = empty;
|
|
33
|
-
for (const item of items) {
|
|
34
|
-
result = concat(result, item);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
var protectedRequest = () => ({ protected: true });
|
|
39
|
-
var userAgent = () => ({ userAgent: true });
|
|
40
|
-
var idempotencyKey = () => ({
|
|
41
|
-
idempotencyKey: true
|
|
42
|
-
});
|
|
43
|
-
var clientCredentials = (credentials) => ({
|
|
44
|
-
clientCredentials: credentials
|
|
45
|
-
});
|
|
46
|
-
var retryAttempt = (attempt) => ({
|
|
47
|
-
retryAttempt: attempt
|
|
48
|
-
});
|
|
49
|
-
var renewAttempted = (value) => ({
|
|
50
|
-
renewAttempted: value
|
|
51
|
-
});
|
|
52
|
-
var notRetryable = () => ({ retryable: false });
|
|
53
|
-
var sentWith = (token) => ({
|
|
54
|
-
sentWith: token
|
|
55
|
-
});
|
|
56
|
-
var requestId = (id) => ({ requestId: id });
|
|
57
|
-
var getRequestId = (attrs) => attrs?.requestId ?? null;
|
|
58
|
-
var isProtected = (attrs) => attrs?.protected === true;
|
|
59
|
-
var needUserAgent = (attrs) => attrs?.userAgent === true;
|
|
60
|
-
var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
|
|
61
|
-
var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
|
|
62
|
-
var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
|
|
63
|
-
var isRetryable = (attrs) => attrs?.retryable !== false;
|
|
64
|
-
var getSentWith = (attrs) => attrs?.sentWith === void 0 ? SentWith.noUserToken : SentWith.userToken(attrs.sentWith);
|
|
65
|
-
var getClientCredentials = (attrs) => attrs?.clientCredentials;
|
|
66
|
-
var Attributes = {
|
|
67
|
-
empty,
|
|
68
|
-
concat,
|
|
69
|
-
concatAll,
|
|
70
|
-
protected: protectedRequest,
|
|
71
|
-
isProtected,
|
|
72
|
-
userAgent,
|
|
73
|
-
needUserAgent,
|
|
74
|
-
idempotencyKey,
|
|
75
|
-
isIdempotent,
|
|
76
|
-
retryAttempt,
|
|
77
|
-
getRetryAttempt,
|
|
78
|
-
renewAttempted,
|
|
79
|
-
wasRenewAttempted,
|
|
80
|
-
notRetryable,
|
|
81
|
-
isRetryable,
|
|
82
|
-
sentWith,
|
|
83
|
-
getSentWith,
|
|
84
|
-
clientCredentials,
|
|
85
|
-
getClientCredentials,
|
|
86
|
-
requestId,
|
|
87
|
-
getRequestId
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/universal/api/http.ts
|
|
1
|
+
// src/universal/types/http.ts
|
|
91
2
|
var HttpError = class extends Error {
|
|
92
3
|
constructor(response) {
|
|
93
4
|
super(`Request failed with ${response.status} status`);
|
|
@@ -112,104 +23,6 @@ function apiErrorCode(error) {
|
|
|
112
23
|
const code = body.code;
|
|
113
24
|
return typeof code === "string" ? code : null;
|
|
114
25
|
}
|
|
115
|
-
async function makeRequest(request) {
|
|
116
|
-
const headers = {
|
|
117
|
-
Accept: "application/json",
|
|
118
|
-
...request.method === "POST" && request.body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
119
|
-
...request.headers ?? {}
|
|
120
|
-
};
|
|
121
|
-
const init = {
|
|
122
|
-
method: request.method,
|
|
123
|
-
headers,
|
|
124
|
-
...request.redirect !== void 0 ? { redirect: request.redirect } : {}
|
|
125
|
-
};
|
|
126
|
-
if (request.method === "POST" && request.body !== void 0) {
|
|
127
|
-
init.body = JSON.stringify(request.body);
|
|
128
|
-
}
|
|
129
|
-
const response = await fetch(
|
|
130
|
-
buildUrlWithQueryParams(request.url, request.queryParams),
|
|
131
|
-
init
|
|
132
|
-
);
|
|
133
|
-
const responseHeaders = headersToRecord(response.headers);
|
|
134
|
-
if (response.status === 204 || response.status === 205) {
|
|
135
|
-
return {
|
|
136
|
-
status: response.status,
|
|
137
|
-
body: null,
|
|
138
|
-
headers: responseHeaders
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
if (response.status >= 300 && response.status < 400) {
|
|
142
|
-
await response.text();
|
|
143
|
-
return {
|
|
144
|
-
status: response.status,
|
|
145
|
-
body: null,
|
|
146
|
-
headers: responseHeaders
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const text = await response.text();
|
|
150
|
-
let body;
|
|
151
|
-
try {
|
|
152
|
-
body = text ? JSON.parse(text) : null;
|
|
153
|
-
} catch (_) {
|
|
154
|
-
throw new HttpError({
|
|
155
|
-
status: response.status,
|
|
156
|
-
headers: responseHeaders,
|
|
157
|
-
body: text
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
status: response.status,
|
|
162
|
-
body,
|
|
163
|
-
headers: responseHeaders
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function buildUrlWithQueryParams(url, queryParams) {
|
|
167
|
-
if (!queryParams) {
|
|
168
|
-
return url;
|
|
169
|
-
}
|
|
170
|
-
const searchParams = new URLSearchParams();
|
|
171
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
172
|
-
if (value === void 0 || value === null) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if (Array.isArray(value)) {
|
|
176
|
-
for (const item of value) {
|
|
177
|
-
if (item === void 0 || item === null) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
searchParams.append(key, String(item));
|
|
181
|
-
}
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
searchParams.append(key, String(value));
|
|
185
|
-
}
|
|
186
|
-
const queryString = searchParams.toString();
|
|
187
|
-
if (!queryString) {
|
|
188
|
-
return url;
|
|
189
|
-
}
|
|
190
|
-
return url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
191
|
-
}
|
|
192
|
-
function headersToRecord(headers) {
|
|
193
|
-
const record = {};
|
|
194
|
-
headers.forEach((value, key) => {
|
|
195
|
-
record[key.toLowerCase()] = value;
|
|
196
|
-
});
|
|
197
|
-
return record;
|
|
198
|
-
}
|
|
199
|
-
function concatAttributes(request, attrs) {
|
|
200
|
-
const nextAttributes = Attributes.concat(
|
|
201
|
-
request.attributes ?? Attributes.empty,
|
|
202
|
-
attrs
|
|
203
|
-
);
|
|
204
|
-
const nextRequest = {
|
|
205
|
-
...request,
|
|
206
|
-
attributes: nextAttributes
|
|
207
|
-
};
|
|
208
|
-
return nextRequest;
|
|
209
|
-
}
|
|
210
|
-
var Request = {
|
|
211
|
-
concatAttributes
|
|
212
|
-
};
|
|
213
26
|
|
|
214
27
|
// src/universal/types/errors.ts
|
|
215
28
|
var NotImplementedError = class extends Error {
|
|
@@ -291,105 +104,74 @@ function isExpired({
|
|
|
291
104
|
return now >= expiresAt - buffer;
|
|
292
105
|
}
|
|
293
106
|
|
|
294
|
-
// src/universal/
|
|
295
|
-
var
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
stateMutability: "view"
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
type: "function",
|
|
325
|
-
name: "decimals",
|
|
326
|
-
inputs: [],
|
|
327
|
-
outputs: [{ name: "", type: "uint8" }],
|
|
328
|
-
stateMutability: "view"
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
type: "function",
|
|
332
|
-
name: "name",
|
|
333
|
-
inputs: [],
|
|
334
|
-
outputs: [{ name: "", type: "string" }],
|
|
335
|
-
stateMutability: "view"
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
type: "function",
|
|
339
|
-
name: "symbol",
|
|
340
|
-
inputs: [],
|
|
341
|
-
outputs: [{ name: "", type: "string" }],
|
|
342
|
-
stateMutability: "view"
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
type: "function",
|
|
346
|
-
name: "totalSupply",
|
|
347
|
-
inputs: [],
|
|
348
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
349
|
-
stateMutability: "view"
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
type: "function",
|
|
353
|
-
name: "transfer",
|
|
354
|
-
inputs: [
|
|
355
|
-
{ name: "recipient", type: "address" },
|
|
356
|
-
{ name: "amount", type: "uint256" }
|
|
357
|
-
],
|
|
358
|
-
outputs: [{ name: "", type: "bool" }],
|
|
359
|
-
stateMutability: "nonpayable"
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
type: "function",
|
|
363
|
-
name: "transferFrom",
|
|
364
|
-
inputs: [
|
|
365
|
-
{ name: "sender", type: "address" },
|
|
366
|
-
{ name: "recipient", type: "address" },
|
|
367
|
-
{ name: "amount", type: "uint256" }
|
|
368
|
-
],
|
|
369
|
-
outputs: [{ name: "", type: "bool" }],
|
|
370
|
-
stateMutability: "nonpayable"
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
type: "event",
|
|
374
|
-
name: "Approval",
|
|
375
|
-
inputs: [
|
|
376
|
-
{ name: "owner", type: "address", indexed: true },
|
|
377
|
-
{ name: "spender", type: "address", indexed: true },
|
|
378
|
-
{ name: "value", type: "uint256", indexed: false }
|
|
379
|
-
],
|
|
380
|
-
anonymous: false
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
type: "event",
|
|
384
|
-
name: "Transfer",
|
|
385
|
-
inputs: [
|
|
386
|
-
{ name: "from", type: "address", indexed: true },
|
|
387
|
-
{ name: "to", type: "address", indexed: true },
|
|
388
|
-
{ name: "value", type: "uint256", indexed: false }
|
|
389
|
-
],
|
|
390
|
-
anonymous: false
|
|
107
|
+
// src/universal/types/blockchain/ui.ts
|
|
108
|
+
var FormattedAmountUi = (value) => value;
|
|
109
|
+
var FormattedPercentUi = (value) => value;
|
|
110
|
+
var TxExplorerUrl = (value) => value;
|
|
111
|
+
var ShortenedWalletAddress = (value) => value;
|
|
112
|
+
var FormattedAmountAssetUi = (value) => value;
|
|
113
|
+
var AssetIconUrl = (value) => value;
|
|
114
|
+
|
|
115
|
+
// src/universal/core/shared/blockchain/chain.ts
|
|
116
|
+
import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
|
|
117
|
+
var VIEM_CHAINS = {
|
|
118
|
+
ethereum_mainnet: mainnet,
|
|
119
|
+
ethereum_sepolia: sepolia,
|
|
120
|
+
base_mainnet: base,
|
|
121
|
+
base_sepolia: baseSepolia
|
|
122
|
+
};
|
|
123
|
+
function viemChain(chain) {
|
|
124
|
+
return VIEM_CHAINS[chain];
|
|
125
|
+
}
|
|
126
|
+
function getChainId(chain) {
|
|
127
|
+
return VIEM_CHAINS[chain].id;
|
|
128
|
+
}
|
|
129
|
+
function chainFromId(chainId) {
|
|
130
|
+
const chains = Object.keys(VIEM_CHAINS);
|
|
131
|
+
const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
|
|
132
|
+
if (!chain) {
|
|
133
|
+
throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
|
|
391
134
|
}
|
|
392
|
-
|
|
135
|
+
return chain;
|
|
136
|
+
}
|
|
137
|
+
function contractOn(contracts, chain) {
|
|
138
|
+
return contracts.find((contract) => contract.chain === chain)?.address ?? null;
|
|
139
|
+
}
|
|
140
|
+
function getNetworkName(chain) {
|
|
141
|
+
switch (chain) {
|
|
142
|
+
case "ethereum_mainnet":
|
|
143
|
+
return "Ethereum";
|
|
144
|
+
case "ethereum_sepolia":
|
|
145
|
+
return "Ethereum Sepolia";
|
|
146
|
+
case "base_mainnet":
|
|
147
|
+
return "Base";
|
|
148
|
+
case "base_sepolia":
|
|
149
|
+
return "Base Sepolia";
|
|
150
|
+
default: {
|
|
151
|
+
const _exhaustive = chain;
|
|
152
|
+
return _exhaustive;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function txExplorerUrl(chain, txHash) {
|
|
157
|
+
return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
|
|
158
|
+
}
|
|
159
|
+
function explorerBaseUrl(chain) {
|
|
160
|
+
switch (chain) {
|
|
161
|
+
case "ethereum_mainnet":
|
|
162
|
+
return "https://etherscan.io";
|
|
163
|
+
case "ethereum_sepolia":
|
|
164
|
+
return "https://sepolia.etherscan.io";
|
|
165
|
+
case "base_mainnet":
|
|
166
|
+
return "https://basescan.org";
|
|
167
|
+
case "base_sepolia":
|
|
168
|
+
return "https://sepolia-explorer.base.org";
|
|
169
|
+
default: {
|
|
170
|
+
const _exhaustive = chain;
|
|
171
|
+
return _exhaustive;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
393
175
|
|
|
394
176
|
// src/universal/types/blockchain/core.ts
|
|
395
177
|
var ETHEREUM_CHAINS = {
|
|
@@ -453,8 +235,18 @@ var BlockchainAmount = Object.assign(
|
|
|
453
235
|
{
|
|
454
236
|
add: (a, b) => combineAmounts(a, b, (x, y) => x + y),
|
|
455
237
|
sub: (a, b) => combineAmounts(a, b, (x, y) => x - y),
|
|
456
|
-
|
|
457
|
-
|
|
238
|
+
/**
|
|
239
|
+
* `a * b`, in `a`'s decimals - a price times a quantity. Multiplies before
|
|
240
|
+
* it rescales, then truncates towards zero. The exact inverse of `div`.
|
|
241
|
+
*/
|
|
242
|
+
mul: (a, b) => multiplyAmounts(a, b),
|
|
243
|
+
/**
|
|
244
|
+
* `a / b`, in `a`'s decimals - a price, a ratio. Rescales before it
|
|
245
|
+
* divides, then truncates towards zero.
|
|
246
|
+
*
|
|
247
|
+
* @throws MathError when `b` is zero.
|
|
248
|
+
*/
|
|
249
|
+
div: (a, b) => divideAmounts(a, b)
|
|
458
250
|
}
|
|
459
251
|
);
|
|
460
252
|
function multiplyAmounts(a, b) {
|
|
@@ -511,6 +303,36 @@ function blockchainAmountFromRawOrThrow({
|
|
|
511
303
|
throw new ValidationError(`${label}: out of uint256 bounds (${value})`);
|
|
512
304
|
}
|
|
513
305
|
}
|
|
306
|
+
function positiveAmountFromRawOrThrow({
|
|
307
|
+
label,
|
|
308
|
+
raw,
|
|
309
|
+
decimals,
|
|
310
|
+
reason
|
|
311
|
+
}) {
|
|
312
|
+
const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
|
|
313
|
+
if (amount.raw === 0n) {
|
|
314
|
+
throw new ValidationError(
|
|
315
|
+
`${label}: must be greater than zero ("${raw}") - ${reason}`
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
return amount;
|
|
319
|
+
}
|
|
320
|
+
function pricePerShare({
|
|
321
|
+
usd,
|
|
322
|
+
shares
|
|
323
|
+
}) {
|
|
324
|
+
const price = BlockchainAmount.div(usd, shares);
|
|
325
|
+
return BlockchainAmount({
|
|
326
|
+
raw: assertPriceFits(price.raw),
|
|
327
|
+
decimals: price.decimals
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function assertPriceFits(raw) {
|
|
331
|
+
if (raw > MAX_UINT_256) {
|
|
332
|
+
throw new MathError(`Price per share: out of uint256 bounds (${raw})`);
|
|
333
|
+
}
|
|
334
|
+
return raw;
|
|
335
|
+
}
|
|
514
336
|
function parseBlockchainAmount(amount, decimals) {
|
|
515
337
|
const trimmed = amount.trim();
|
|
516
338
|
if (trimmed === "") return { valid: false, reason: { type: "empty" } };
|
|
@@ -624,10 +446,13 @@ function requiredDate(value, field) {
|
|
|
624
446
|
return date;
|
|
625
447
|
}
|
|
626
448
|
function dateOrNull(value, field) {
|
|
627
|
-
return value
|
|
449
|
+
return mapNullish(value, (date) => requiredDate(date, field));
|
|
628
450
|
}
|
|
629
451
|
function decimalOrNull(value) {
|
|
630
|
-
return value
|
|
452
|
+
return mapNullish(value, DecimalString);
|
|
453
|
+
}
|
|
454
|
+
function mapNullish(value, parse) {
|
|
455
|
+
return value === null || value === void 0 ? null : parse(value);
|
|
631
456
|
}
|
|
632
457
|
function requiredArray(value, field) {
|
|
633
458
|
if (!Array.isArray(value)) {
|
|
@@ -637,39 +462,14 @@ function requiredArray(value, field) {
|
|
|
637
462
|
}
|
|
638
463
|
return value;
|
|
639
464
|
}
|
|
465
|
+
function txFromWire(wire) {
|
|
466
|
+
return {
|
|
467
|
+
to: EvmContractAddress(wire.to),
|
|
468
|
+
data: HexEncodedTransactionData(wire.data)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
640
471
|
|
|
641
472
|
// src/universal/types/providers/centrifuge/centrifuge.ts
|
|
642
|
-
var CentrifugeVaultQuote = {
|
|
643
|
-
fromDto: (dto) => {
|
|
644
|
-
const spendDecimals = AssetDecimals(dto.spend_input_decimals);
|
|
645
|
-
const shareDecimals = AssetDecimals(dto.share_decimals);
|
|
646
|
-
return {
|
|
647
|
-
chain: EthereumChain(dto.chain),
|
|
648
|
-
symbol: AssetSymbol(dto.symbol),
|
|
649
|
-
spendInputAmount: blockchainAmountFromRawOrThrow({
|
|
650
|
-
label: "spend_input_amount",
|
|
651
|
-
raw: dto.spend_input_amount,
|
|
652
|
-
decimals: spendDecimals
|
|
653
|
-
}),
|
|
654
|
-
estimatedShares: blockchainAmountFromRawOrThrow({
|
|
655
|
-
label: "estimated_shares",
|
|
656
|
-
raw: dto.estimated_shares,
|
|
657
|
-
decimals: shareDecimals
|
|
658
|
-
}),
|
|
659
|
-
indicativePrice: decimalOrNull(dto.indicative_price),
|
|
660
|
-
minimumInputAmount: dto.minimum_input_amount === null ? null : blockchainAmountFromRawOrThrow({
|
|
661
|
-
label: "minimum_input_amount",
|
|
662
|
-
raw: dto.minimum_input_amount,
|
|
663
|
-
decimals: spendDecimals
|
|
664
|
-
}),
|
|
665
|
-
orderability: parseOrderability(
|
|
666
|
-
dto.can_order,
|
|
667
|
-
dto.reasons,
|
|
668
|
-
"CentrifugeVaultQuote"
|
|
669
|
-
)
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
473
|
var CentrifugeVaultStatus = {
|
|
674
474
|
fromDto: (dto) => ({
|
|
675
475
|
chain: EthereumChain(dto.chain),
|
|
@@ -696,23 +496,15 @@ var CentrifugeVaultStatus = {
|
|
|
696
496
|
};
|
|
697
497
|
var CentrifugeVaultBuyTransaction = {
|
|
698
498
|
fromDto: (dto) => {
|
|
699
|
-
const spendInputAmount = blockchainAmountFromRawOrThrow({
|
|
700
|
-
label: "spend_input_amount",
|
|
701
|
-
raw: dto.spend_input_amount,
|
|
702
|
-
decimals: AssetDecimals(dto.spend_input_decimals)
|
|
703
|
-
});
|
|
704
|
-
if (spendInputAmount.raw <= 0n) {
|
|
705
|
-
throw new ValidationError(
|
|
706
|
-
`spend_input_amount: must be greater than zero ("${dto.spend_input_amount}") - a deposit of nothing is not a request`
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
499
|
return {
|
|
710
500
|
...parseTransactionCore(dto, "CentrifugeVaultBuyTransaction"),
|
|
711
|
-
spendInputAmount
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
501
|
+
spendInputAmount: positiveAmountFromRawOrThrow({
|
|
502
|
+
label: "spend_input_amount",
|
|
503
|
+
raw: dto.spend_input_amount,
|
|
504
|
+
decimals: AssetDecimals(dto.spend_input_decimals),
|
|
505
|
+
// Frontline refuses an `amount` of zero, so a zero here is a changed
|
|
506
|
+
// encoding, not a small deposit - and not calldata worth signing.
|
|
507
|
+
reason: "a deposit of nothing is not a request"
|
|
716
508
|
})
|
|
717
509
|
};
|
|
718
510
|
}
|
|
@@ -727,72 +519,41 @@ var CentrifugeVaultClaimTransaction = {
|
|
|
727
519
|
})
|
|
728
520
|
})
|
|
729
521
|
};
|
|
730
|
-
var
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
const shares = (label, raw) => blockchainAmountFromRawOrThrow({ label, raw, decimals: shareDecimals });
|
|
522
|
+
var CentrifugeAssets = (amount) => amount;
|
|
523
|
+
var CentrifugeShares = (amount) => amount;
|
|
524
|
+
var CentrifugeDepositPosition = {
|
|
525
|
+
fromContract: (raw, context) => {
|
|
526
|
+
const assets = (label, value) => CentrifugeAssets(contractAmount(label, value, context.assetDecimals));
|
|
736
527
|
return {
|
|
737
|
-
chain:
|
|
738
|
-
|
|
739
|
-
walletAddress:
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
pending: asset("pending", dto.pending),
|
|
743
|
-
filledAssets: asset("filled_assets", dto.filled_assets),
|
|
744
|
-
earnedShares: shares("earned_shares", dto.earned_shares),
|
|
745
|
-
claimedShares: shares("claimed_shares", dto.claimed_shares),
|
|
746
|
-
claimableShares: shares("claimable_shares", dto.claimable_shares),
|
|
747
|
-
shareBalance: shares("share_balance", dto.share_balance),
|
|
748
|
-
averagePrice: decimalOrNull(dto.average_price),
|
|
749
|
-
frozen: dto.frozen,
|
|
750
|
-
asOf: requiredDate(dto.as_of, "CentrifugeVaultPosition.as_of")
|
|
528
|
+
chain: context.chain,
|
|
529
|
+
proxy: context.proxy,
|
|
530
|
+
walletAddress: context.walletAddress,
|
|
531
|
+
pending: assets("pendingDepositRequest", raw.pendingDepositRequest),
|
|
532
|
+
claimable: assets("claimableDepositRequest", raw.claimableDepositRequest)
|
|
751
533
|
};
|
|
752
534
|
}
|
|
753
535
|
};
|
|
754
|
-
var
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
claimableAssets: blockchainAmountFromRawOrThrow({
|
|
766
|
-
label: "claimable_assets",
|
|
767
|
-
raw: dto.claimable_assets,
|
|
768
|
-
decimals: AssetDecimals(dto.asset_decimals)
|
|
769
|
-
}),
|
|
770
|
-
frozen: dto.frozen,
|
|
771
|
-
asOf: requiredDate(dto.as_of, "CentrifugeVaultRedeemPosition.as_of")
|
|
772
|
-
})
|
|
536
|
+
var CentrifugeRedeemPosition = {
|
|
537
|
+
fromContract: (raw, context) => {
|
|
538
|
+
const shares = (label, value) => CentrifugeShares(contractAmount(label, value, context.shareDecimals));
|
|
539
|
+
return {
|
|
540
|
+
chain: context.chain,
|
|
541
|
+
proxy: context.proxy,
|
|
542
|
+
walletAddress: context.walletAddress,
|
|
543
|
+
pending: shares("pendingRedeemRequest", raw.pendingRedeemRequest),
|
|
544
|
+
claimable: shares("claimableRedeemRequest", raw.claimableRedeemRequest)
|
|
545
|
+
};
|
|
546
|
+
}
|
|
773
547
|
};
|
|
774
548
|
var CentrifugeVaultLeg = {
|
|
775
|
-
/**
|
|
776
|
-
* What a claim on the leg would collect: shares for `invest`, the funding
|
|
777
|
-
* token for `redeem`.
|
|
778
|
-
*/
|
|
779
|
-
claimable: (leg) => {
|
|
780
|
-
switch (leg.direction) {
|
|
781
|
-
case "invest":
|
|
782
|
-
return leg.position.claimableShares;
|
|
783
|
-
case "redeem":
|
|
784
|
-
return leg.position.claimableAssets;
|
|
785
|
-
default: {
|
|
786
|
-
const exhaustive = leg;
|
|
787
|
-
return exhaustive;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
},
|
|
791
549
|
/** Whether the leg has anything queued or anything ready to claim. */
|
|
792
|
-
isActive: (leg) => leg.position.pending.raw > 0n ||
|
|
550
|
+
isActive: (leg) => leg.position.pending.raw > 0n || leg.position.claimable.raw > 0n
|
|
793
551
|
};
|
|
552
|
+
function contractAmount(label, value, decimals) {
|
|
553
|
+
return BlockchainAmount({ raw: parseUint256(value, label), decimals });
|
|
554
|
+
}
|
|
794
555
|
var CentrifugeVaultLegId = {
|
|
795
|
-
/** Addresses compare case-insensitively:
|
|
556
|
+
/** Addresses compare case-insensitively: a host may pass either case. */
|
|
796
557
|
of: (leg) => [
|
|
797
558
|
leg.direction,
|
|
798
559
|
leg.position.chain,
|
|
@@ -824,32 +585,119 @@ function parseOrderability(canOrder, reasons, model) {
|
|
|
824
585
|
`${model}.reasons: expected at least one when can_order is false`
|
|
825
586
|
);
|
|
826
587
|
}
|
|
827
|
-
return { type: "blocked", reasons: [first, ...rest] };
|
|
828
|
-
}
|
|
829
|
-
function parseTransactionCore(dto, model) {
|
|
830
|
-
return {
|
|
831
|
-
tx:
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
588
|
+
return { type: "blocked", reasons: [first, ...rest] };
|
|
589
|
+
}
|
|
590
|
+
function parseTransactionCore(dto, model) {
|
|
591
|
+
return {
|
|
592
|
+
tx: txFromWire(dto),
|
|
593
|
+
expiresAt: dateOrNull(dto.expires_at, `${model}.expires_at`)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// src/universal/api/frontline/providers/shared/spend-scale.ts
|
|
598
|
+
function assertSpendScaleAgrees({
|
|
599
|
+
published,
|
|
600
|
+
sized,
|
|
601
|
+
trade,
|
|
602
|
+
note
|
|
603
|
+
}) {
|
|
604
|
+
if (published === sized.decimals) return;
|
|
605
|
+
const because = note === void 0 ? "" : ` - ${note}`;
|
|
606
|
+
throw new ValidationError(
|
|
607
|
+
`spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/universal/types/access-token-source.ts
|
|
612
|
+
var SentWith = {
|
|
613
|
+
userToken: (token) => ({
|
|
614
|
+
type: "user-token",
|
|
615
|
+
token
|
|
616
|
+
}),
|
|
617
|
+
noUserToken: { type: "no-user-token" }
|
|
618
|
+
};
|
|
619
|
+
var TokenTrigger = {
|
|
620
|
+
beforeRequest: { type: "before-request" },
|
|
621
|
+
after401: (rejected) => ({
|
|
622
|
+
type: "after-401",
|
|
623
|
+
rejected
|
|
624
|
+
})
|
|
625
|
+
};
|
|
626
|
+
function isRejectedToken(token, rejected) {
|
|
627
|
+
switch (rejected.type) {
|
|
628
|
+
case "user-token":
|
|
629
|
+
return rejected.token.value === token.value;
|
|
630
|
+
case "no-user-token":
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
837
633
|
}
|
|
838
634
|
|
|
635
|
+
// src/universal/api/http-attributes.ts
|
|
636
|
+
var empty = {};
|
|
637
|
+
var concat = (left, right) => ({
|
|
638
|
+
...left,
|
|
639
|
+
...right
|
|
640
|
+
});
|
|
641
|
+
var concatAll = (...items) => {
|
|
642
|
+
let result = empty;
|
|
643
|
+
for (const item of items) {
|
|
644
|
+
result = concat(result, item);
|
|
645
|
+
}
|
|
646
|
+
return result;
|
|
647
|
+
};
|
|
648
|
+
var protectedRequest = () => ({ protected: true });
|
|
649
|
+
var userAgent = () => ({ userAgent: true });
|
|
650
|
+
var idempotencyKey = () => ({
|
|
651
|
+
idempotencyKey: true
|
|
652
|
+
});
|
|
653
|
+
var clientCredentials = (credentials) => ({
|
|
654
|
+
clientCredentials: credentials
|
|
655
|
+
});
|
|
656
|
+
var retryAttempt = (attempt) => ({
|
|
657
|
+
retryAttempt: attempt
|
|
658
|
+
});
|
|
659
|
+
var renewAttempted = (value) => ({
|
|
660
|
+
renewAttempted: value
|
|
661
|
+
});
|
|
662
|
+
var notRetryable = () => ({ retryable: false });
|
|
663
|
+
var sentWith = (token) => ({
|
|
664
|
+
sentWith: token
|
|
665
|
+
});
|
|
666
|
+
var requestId = (id) => ({ requestId: id });
|
|
667
|
+
var getRequestId = (attrs) => attrs?.requestId ?? null;
|
|
668
|
+
var isProtected = (attrs) => attrs?.protected === true;
|
|
669
|
+
var needUserAgent = (attrs) => attrs?.userAgent === true;
|
|
670
|
+
var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
|
|
671
|
+
var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
|
|
672
|
+
var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
|
|
673
|
+
var isRetryable = (attrs) => attrs?.retryable !== false;
|
|
674
|
+
var getSentWith = (attrs) => attrs?.sentWith === void 0 ? SentWith.noUserToken : SentWith.userToken(attrs.sentWith);
|
|
675
|
+
var getClientCredentials = (attrs) => attrs?.clientCredentials;
|
|
676
|
+
var Attributes = {
|
|
677
|
+
empty,
|
|
678
|
+
concat,
|
|
679
|
+
concatAll,
|
|
680
|
+
protected: protectedRequest,
|
|
681
|
+
isProtected,
|
|
682
|
+
userAgent,
|
|
683
|
+
needUserAgent,
|
|
684
|
+
idempotencyKey,
|
|
685
|
+
isIdempotent,
|
|
686
|
+
retryAttempt,
|
|
687
|
+
getRetryAttempt,
|
|
688
|
+
renewAttempted,
|
|
689
|
+
wasRenewAttempted,
|
|
690
|
+
notRetryable,
|
|
691
|
+
isRetryable,
|
|
692
|
+
sentWith,
|
|
693
|
+
getSentWith,
|
|
694
|
+
clientCredentials,
|
|
695
|
+
getClientCredentials,
|
|
696
|
+
requestId,
|
|
697
|
+
getRequestId
|
|
698
|
+
};
|
|
699
|
+
|
|
839
700
|
// src/universal/api/frontline/providers/centrifuge/centrifuge.ts
|
|
840
|
-
async function getCentrifugeVaultQuote(api, params) {
|
|
841
|
-
const dto = await api.send({
|
|
842
|
-
method: "GET",
|
|
843
|
-
url: "/v1/centrifuge/vault/quote",
|
|
844
|
-
queryParams: {
|
|
845
|
-
symbol: params.symbol,
|
|
846
|
-
chain: params.chain,
|
|
847
|
-
amount: params.amount.raw.toString()
|
|
848
|
-
},
|
|
849
|
-
attributes: Attributes.protected()
|
|
850
|
-
});
|
|
851
|
-
return CentrifugeVaultQuote.fromDto(dto);
|
|
852
|
-
}
|
|
853
701
|
async function getCentrifugeVaultStatus(api, params) {
|
|
854
702
|
const dto = await api.send({
|
|
855
703
|
method: "GET",
|
|
@@ -872,30 +720,12 @@ async function buildCentrifugeVaultBuy(api, params) {
|
|
|
872
720
|
},
|
|
873
721
|
attributes: Attributes.protected()
|
|
874
722
|
});
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
}
|
|
880
|
-
return CentrifugeVaultBuyTransaction.fromDto(dto);
|
|
881
|
-
}
|
|
882
|
-
async function getCentrifugeVaultPosition(api, params) {
|
|
883
|
-
const dto = await api.send({
|
|
884
|
-
method: "GET",
|
|
885
|
-
url: "/v1/centrifuge/vault/position",
|
|
886
|
-
queryParams: walletFields(params),
|
|
887
|
-
attributes: Attributes.protected()
|
|
888
|
-
});
|
|
889
|
-
return CentrifugeVaultPosition.fromDto(dto);
|
|
890
|
-
}
|
|
891
|
-
async function getCentrifugeVaultRedeemPosition(api, params) {
|
|
892
|
-
const dto = await api.send({
|
|
893
|
-
method: "GET",
|
|
894
|
-
url: "/v1/centrifuge/vault/redeem-position",
|
|
895
|
-
queryParams: walletFields(params),
|
|
896
|
-
attributes: Attributes.protected()
|
|
723
|
+
assertSpendScaleAgrees({
|
|
724
|
+
published: dto.spend_input_decimals,
|
|
725
|
+
sized: params.amount,
|
|
726
|
+
trade: "deposit"
|
|
897
727
|
});
|
|
898
|
-
return
|
|
728
|
+
return CentrifugeVaultBuyTransaction.fromDto(dto);
|
|
899
729
|
}
|
|
900
730
|
async function createCentrifugeVaultClaim(api, params) {
|
|
901
731
|
const dto = await api.send({
|
|
@@ -923,6 +753,86 @@ function walletFields(params) {
|
|
|
923
753
|
};
|
|
924
754
|
}
|
|
925
755
|
|
|
756
|
+
// src/universal/core/providers/centrifuge/blockchain/abi.ts
|
|
757
|
+
var CENTRIFUGE_PROXY_ABI = [
|
|
758
|
+
{
|
|
759
|
+
type: "function",
|
|
760
|
+
name: "pendingDepositRequest",
|
|
761
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
762
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
763
|
+
stateMutability: "view"
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
type: "function",
|
|
767
|
+
name: "claimableDepositRequest",
|
|
768
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
769
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
770
|
+
stateMutability: "view"
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
type: "function",
|
|
774
|
+
name: "pendingRedeemRequest",
|
|
775
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
776
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
777
|
+
stateMutability: "view"
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
type: "function",
|
|
781
|
+
name: "claimableRedeemRequest",
|
|
782
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
783
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
784
|
+
stateMutability: "view"
|
|
785
|
+
}
|
|
786
|
+
];
|
|
787
|
+
|
|
788
|
+
// src/universal/api/rpc/providers/centrifuge/position.ts
|
|
789
|
+
async function readCentrifugeDepositPosition(clients, params) {
|
|
790
|
+
const client = clients(params.vault.chain);
|
|
791
|
+
const proxy = proxyOf(params);
|
|
792
|
+
const wallet = params.walletAddress;
|
|
793
|
+
const [pendingDepositRequest, claimableDepositRequest] = await client.multicall({
|
|
794
|
+
allowFailure: false,
|
|
795
|
+
contracts: [
|
|
796
|
+
{ ...proxy, functionName: "pendingDepositRequest", args: [wallet] },
|
|
797
|
+
{ ...proxy, functionName: "claimableDepositRequest", args: [wallet] }
|
|
798
|
+
]
|
|
799
|
+
});
|
|
800
|
+
return CentrifugeDepositPosition.fromContract(
|
|
801
|
+
{ pendingDepositRequest, claimableDepositRequest },
|
|
802
|
+
contextOf(params)
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
async function readCentrifugeRedeemPosition(clients, params) {
|
|
806
|
+
const client = clients(params.vault.chain);
|
|
807
|
+
const proxy = proxyOf(params);
|
|
808
|
+
const wallet = params.walletAddress;
|
|
809
|
+
const [pendingRedeemRequest, claimableRedeemRequest] = await client.multicall(
|
|
810
|
+
{
|
|
811
|
+
allowFailure: false,
|
|
812
|
+
contracts: [
|
|
813
|
+
{ ...proxy, functionName: "pendingRedeemRequest", args: [wallet] },
|
|
814
|
+
{ ...proxy, functionName: "claimableRedeemRequest", args: [wallet] }
|
|
815
|
+
]
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
return CentrifugeRedeemPosition.fromContract(
|
|
819
|
+
{ pendingRedeemRequest, claimableRedeemRequest },
|
|
820
|
+
contextOf(params)
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
function proxyOf(params) {
|
|
824
|
+
return { address: params.vault.proxy, abi: CENTRIFUGE_PROXY_ABI };
|
|
825
|
+
}
|
|
826
|
+
function contextOf(params) {
|
|
827
|
+
return {
|
|
828
|
+
chain: params.vault.chain,
|
|
829
|
+
proxy: params.vault.proxy,
|
|
830
|
+
walletAddress: params.walletAddress,
|
|
831
|
+
assetDecimals: params.vault.funding.decimals,
|
|
832
|
+
shareDecimals: params.vault.share.decimals
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
926
836
|
// src/universal/core/shared/observability/log-cause.ts
|
|
927
837
|
import {
|
|
928
838
|
BaseError,
|
|
@@ -1106,35 +1016,31 @@ var noopInternalLogger = {
|
|
|
1106
1016
|
wrap: (_op, _params, run) => run()
|
|
1107
1017
|
};
|
|
1108
1018
|
|
|
1109
|
-
// src/universal/core/
|
|
1019
|
+
// src/universal/core/providers/centrifuge/centrifuge-namespace.ts
|
|
1110
1020
|
var CentrifugeNamespaceImpl = class {
|
|
1111
1021
|
constructor(ctx) {
|
|
1112
1022
|
this.ctx = ctx;
|
|
1113
1023
|
this.log = internalLogger(ctx.logger, "CENTRIFUGE");
|
|
1114
1024
|
}
|
|
1115
|
-
async getQuote(params) {
|
|
1116
|
-
return this.log.wrap("getQuote", params, async () => {
|
|
1117
|
-
await this.ctx.ensureUserAuthenticated();
|
|
1118
|
-
return getCentrifugeVaultQuote(this.ctx.api, params);
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
1025
|
async getVaultStatus(params) {
|
|
1122
1026
|
return this.log.wrap("getVaultStatus", params, async () => {
|
|
1123
1027
|
await this.ctx.ensureUserAuthenticated();
|
|
1124
1028
|
return getCentrifugeVaultStatus(this.ctx.api, params);
|
|
1125
1029
|
});
|
|
1126
1030
|
}
|
|
1127
|
-
async
|
|
1128
|
-
return this.log.wrap(
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1031
|
+
async readDepositPosition(params) {
|
|
1032
|
+
return this.log.wrap(
|
|
1033
|
+
"readDepositPosition",
|
|
1034
|
+
params,
|
|
1035
|
+
() => readCentrifugeDepositPosition(this.ctx.rpc, params)
|
|
1036
|
+
);
|
|
1132
1037
|
}
|
|
1133
|
-
async
|
|
1134
|
-
return this.log.wrap(
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1038
|
+
async readRedeemPosition(params) {
|
|
1039
|
+
return this.log.wrap(
|
|
1040
|
+
"readRedeemPosition",
|
|
1041
|
+
params,
|
|
1042
|
+
() => readCentrifugeRedeemPosition(this.ctx.rpc, params)
|
|
1043
|
+
);
|
|
1138
1044
|
}
|
|
1139
1045
|
async createClaim(params) {
|
|
1140
1046
|
return this.log.wrap("createClaim", params, async () => {
|
|
@@ -1156,20 +1062,112 @@ var CentrifugeNamespaceImpl = class {
|
|
|
1156
1062
|
}
|
|
1157
1063
|
};
|
|
1158
1064
|
|
|
1159
|
-
// src/universal/
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1065
|
+
// src/universal/core/shared/blockchain/formatters.ts
|
|
1066
|
+
import { formatUnits } from "viem";
|
|
1067
|
+
function shortenAddress(address) {
|
|
1068
|
+
const short = address.length > 10 ? `${address.slice(0, 6)}\u2026${address.slice(-4)}` : address;
|
|
1069
|
+
return ShortenedWalletAddress(short);
|
|
1070
|
+
}
|
|
1071
|
+
function formatAmount(amount, locale, options) {
|
|
1072
|
+
const decimal = formatRawAmount(amount);
|
|
1073
|
+
let [integerPart, fractionPart = ""] = decimal.split(".");
|
|
1074
|
+
const maxFractionDigits = options?.maxFractionDigits;
|
|
1075
|
+
const minFractionDigits = Math.min(
|
|
1076
|
+
options?.minFractionDigits ?? (maxFractionDigits !== void 0 ? maxFractionDigits : 2),
|
|
1077
|
+
maxFractionDigits ?? amount.decimals,
|
|
1078
|
+
amount.decimals
|
|
1079
|
+
);
|
|
1080
|
+
if (maxFractionDigits !== void 0 && fractionPart.length > maxFractionDigits) {
|
|
1081
|
+
({ integerPart, fractionPart } = roundFractionHalfUp(
|
|
1082
|
+
integerPart,
|
|
1083
|
+
fractionPart,
|
|
1084
|
+
maxFractionDigits
|
|
1085
|
+
));
|
|
1086
|
+
}
|
|
1087
|
+
const trimmed = fractionPart.replace(/0+$/, "");
|
|
1088
|
+
const fraction = trimmed.padEnd(minFractionDigits, "0");
|
|
1089
|
+
const integerFormatted = BigInt(integerPart).toLocaleString(locale);
|
|
1090
|
+
if (minFractionDigits === 0 && fraction === "") {
|
|
1091
|
+
return FormattedAmountUi(integerFormatted);
|
|
1092
|
+
}
|
|
1093
|
+
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
1094
|
+
return FormattedAmountUi(`${integerFormatted}${decimalSeparator}${fraction}`);
|
|
1095
|
+
}
|
|
1096
|
+
function roundFractionHalfUp(integerPart, fractionPart, maxFractionDigits) {
|
|
1097
|
+
if (fractionPart.length <= maxFractionDigits) {
|
|
1098
|
+
return { integerPart, fractionPart };
|
|
1099
|
+
}
|
|
1100
|
+
if (maxFractionDigits === 0) {
|
|
1101
|
+
const roundUp = fractionPart[0] >= "5";
|
|
1102
|
+
const integer = BigInt(integerPart) + (roundUp ? 1n : 0n);
|
|
1103
|
+
return { integerPart: integer.toString(), fractionPart: "" };
|
|
1104
|
+
}
|
|
1105
|
+
const trimmed = fractionPart.slice(0, maxFractionDigits);
|
|
1106
|
+
if (fractionPart[maxFractionDigits] < "5") {
|
|
1107
|
+
return { integerPart, fractionPart: trimmed };
|
|
1108
|
+
}
|
|
1109
|
+
const digits = trimmed.split("").map((digit) => Number.parseInt(digit, 10));
|
|
1110
|
+
let carry = 1;
|
|
1111
|
+
for (let i = digits.length - 1; i >= 0 && carry > 0; i -= 1) {
|
|
1112
|
+
const sum = digits[i] + carry;
|
|
1113
|
+
if (sum === 10) {
|
|
1114
|
+
digits[i] = 0;
|
|
1115
|
+
carry = 1;
|
|
1116
|
+
} else {
|
|
1117
|
+
digits[i] = sum;
|
|
1118
|
+
carry = 0;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return {
|
|
1122
|
+
integerPart: carry > 0 ? (BigInt(integerPart) + 1n).toString() : integerPart,
|
|
1123
|
+
fractionPart: digits.join("")
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function formatRawAmount(amount) {
|
|
1127
|
+
return formatUnits(amount.raw, amount.decimals);
|
|
1128
|
+
}
|
|
1129
|
+
function formatCompactAmount(amount, locale) {
|
|
1130
|
+
const value = Number(formatRawAmount(amount));
|
|
1131
|
+
const formatted = new Intl.NumberFormat(locale, {
|
|
1132
|
+
notation: "compact",
|
|
1133
|
+
maximumFractionDigits: 2
|
|
1134
|
+
}).format(value);
|
|
1135
|
+
return FormattedAmountUi(formatted);
|
|
1136
|
+
}
|
|
1137
|
+
function formatBpsAsPercent(bps, locale) {
|
|
1138
|
+
const whole = bps / 100n;
|
|
1139
|
+
const fraction = bps % 100n;
|
|
1140
|
+
const wholeFormatted = whole.toLocaleString(locale);
|
|
1141
|
+
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
1142
|
+
if (fraction === 0n) {
|
|
1143
|
+
return FormattedPercentUi(`${wholeFormatted}%`);
|
|
1144
|
+
}
|
|
1145
|
+
const fractionFormatted = fraction.toString().padStart(2, "0").replace(/0+$/, "");
|
|
1146
|
+
return FormattedPercentUi(
|
|
1147
|
+
`${wholeFormatted}${decimalSeparator}${fractionFormatted}%`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
function usdAmount(amount) {
|
|
1151
|
+
return FormattedAmountAssetUi(`$${amount}`);
|
|
1152
|
+
}
|
|
1153
|
+
function assetAmount(amount, symbol) {
|
|
1154
|
+
return FormattedAmountAssetUi(`${amount} ${symbol}`);
|
|
1155
|
+
}
|
|
1156
|
+
var NA_AMOUNT_ASSET_UI = FormattedAmountAssetUi("-");
|
|
1157
|
+
var SHARE_MAX_FRACTION_DIGITS = AssetDecimals(6);
|
|
1158
|
+
var SHARE_MIN_FRACTION_DIGITS = AssetDecimals(2);
|
|
1159
|
+
function formatShareAmount(amount, locale) {
|
|
1160
|
+
return formatAmount(amount, locale, {
|
|
1161
|
+
maxFractionDigits: SHARE_MAX_FRACTION_DIGITS,
|
|
1162
|
+
minFractionDigits: SHARE_MIN_FRACTION_DIGITS
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
var USD_FRACTION_DIGITS = AssetDecimals(2);
|
|
1166
|
+
function formattedUsdPrice(amount, locale) {
|
|
1167
|
+
if (!amount) return NA_AMOUNT_ASSET_UI;
|
|
1168
|
+
return usdAmount(
|
|
1169
|
+
formatAmount(amount, locale, { maxFractionDigits: USD_FRACTION_DIGITS })
|
|
1170
|
+
);
|
|
1173
1171
|
}
|
|
1174
1172
|
|
|
1175
1173
|
// src/universal/types/pagination.ts
|
|
@@ -1313,7 +1311,7 @@ var Isin = (value) => value;
|
|
|
1313
1311
|
var AsyncOfferDetail = {
|
|
1314
1312
|
/**
|
|
1315
1313
|
* Narrows an offer fetched generically, e.g. on an offer page, to one with
|
|
1316
|
-
*
|
|
1314
|
+
* a second leg to show.
|
|
1317
1315
|
*
|
|
1318
1316
|
* An exhaustive `switch` rather than a list of async types, so a new offer
|
|
1319
1317
|
* type is a compile error here until someone decides whether it settles
|
|
@@ -1322,10 +1320,10 @@ var AsyncOfferDetail = {
|
|
|
1322
1320
|
is: (offer) => {
|
|
1323
1321
|
switch (offer.type) {
|
|
1324
1322
|
case "centrifuge::vault":
|
|
1323
|
+
case "coinlist::token_sale":
|
|
1325
1324
|
return true;
|
|
1326
1325
|
case "ondo::swap":
|
|
1327
1326
|
case "superstate::swap":
|
|
1328
|
-
case "coinlist::token_sale":
|
|
1329
1327
|
return false;
|
|
1330
1328
|
default: {
|
|
1331
1329
|
const exhaustive = offer;
|
|
@@ -1355,6 +1353,17 @@ var OfferVaultContract = {
|
|
|
1355
1353
|
*/
|
|
1356
1354
|
listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferVaultContract.fromDto)
|
|
1357
1355
|
};
|
|
1356
|
+
var OfferFundingContract = {
|
|
1357
|
+
fromDto: (dto) => ({
|
|
1358
|
+
chain: Chain(dto.chain),
|
|
1359
|
+
address: EvmContractAddress(dto.address)
|
|
1360
|
+
}),
|
|
1361
|
+
/**
|
|
1362
|
+
* Drops every contract on a chain this SDK does not name, as
|
|
1363
|
+
* {@link OfferVaultContract.listFromDto} does.
|
|
1364
|
+
*/
|
|
1365
|
+
listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferFundingContract.fromDto)
|
|
1366
|
+
};
|
|
1358
1367
|
var OfferDetail = {
|
|
1359
1368
|
fromDto: (dto) => {
|
|
1360
1369
|
const fundingAssets = requiredArray(
|
|
@@ -1396,7 +1405,15 @@ var OfferDetail = {
|
|
|
1396
1405
|
...base2,
|
|
1397
1406
|
...OfferEditorial.fromDto(dto, "OfferDetail"),
|
|
1398
1407
|
type: dto.type,
|
|
1399
|
-
logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url")
|
|
1408
|
+
logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url"),
|
|
1409
|
+
// `[]` is fine and a missing key is not, as for `swap_contracts`:
|
|
1410
|
+
// this is the spender a participation's approval names.
|
|
1411
|
+
fundingContracts: OfferFundingContract.listFromDto(
|
|
1412
|
+
requiredArray(
|
|
1413
|
+
dto.funding_contracts,
|
|
1414
|
+
"OfferDetail.funding_contracts"
|
|
1415
|
+
)
|
|
1416
|
+
)
|
|
1400
1417
|
};
|
|
1401
1418
|
case "superstate::swap":
|
|
1402
1419
|
return {
|
|
@@ -1474,8 +1491,6 @@ var Milestone = {
|
|
|
1474
1491
|
|
|
1475
1492
|
// src/universal/types/providers/coin-list/token-sale.ts
|
|
1476
1493
|
var ParticipationId = (value) => value;
|
|
1477
|
-
var Blockchain = (value) => value;
|
|
1478
|
-
var WalletAddress = (value) => value;
|
|
1479
1494
|
var ParticipationsPaginationParams = {
|
|
1480
1495
|
toQueryParams: (params) => {
|
|
1481
1496
|
const queryParams = PaginationParams.toQueryParams(params);
|
|
@@ -1499,10 +1514,10 @@ var Participation = {
|
|
|
1499
1514
|
amount: dto.amount,
|
|
1500
1515
|
displayAmount: dto.amount_string,
|
|
1501
1516
|
asset: Asset.fromDto(dto.asset),
|
|
1502
|
-
chain:
|
|
1517
|
+
chain: isChain(dto.chain) ? dto.chain : null,
|
|
1503
1518
|
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
1504
1519
|
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
1505
|
-
walletAddress: walletAddress ?
|
|
1520
|
+
walletAddress: walletAddress ? EvmWalletAddress(walletAddress) : null
|
|
1506
1521
|
};
|
|
1507
1522
|
}
|
|
1508
1523
|
};
|
|
@@ -1519,6 +1534,22 @@ var CreateParticipationParams = {
|
|
|
1519
1534
|
})
|
|
1520
1535
|
};
|
|
1521
1536
|
|
|
1537
|
+
// src/universal/api/pagination.ts
|
|
1538
|
+
async function fetchAllPages(fetchPage, baseParams) {
|
|
1539
|
+
const items = [];
|
|
1540
|
+
let cursor = null;
|
|
1541
|
+
do {
|
|
1542
|
+
const params = {
|
|
1543
|
+
...baseParams ?? {},
|
|
1544
|
+
after: cursor ?? void 0
|
|
1545
|
+
};
|
|
1546
|
+
const page = await fetchPage(params);
|
|
1547
|
+
items.push(...page.data);
|
|
1548
|
+
cursor = page.startingAfter;
|
|
1549
|
+
} while (cursor);
|
|
1550
|
+
return items;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1522
1553
|
// src/universal/api/frontline/providers/coin-list/token-sale.ts
|
|
1523
1554
|
async function fetchParticipations(api, offerId) {
|
|
1524
1555
|
return fetchAllPages(
|
|
@@ -1553,7 +1584,7 @@ async function createParticipation(api, params) {
|
|
|
1553
1584
|
return Participation.fromDto(dto);
|
|
1554
1585
|
}
|
|
1555
1586
|
|
|
1556
|
-
// src/universal/core/
|
|
1587
|
+
// src/universal/core/providers/coin-list/token-sale-namespace.ts
|
|
1557
1588
|
var CoinListTokenSaleNamespaceImpl = class {
|
|
1558
1589
|
constructor(ctx) {
|
|
1559
1590
|
this.ctx = ctx;
|
|
@@ -1585,180 +1616,6 @@ var CoinListTokenSaleNamespaceImpl = class {
|
|
|
1585
1616
|
}
|
|
1586
1617
|
};
|
|
1587
1618
|
|
|
1588
|
-
// src/universal/types/blockchain/ui.ts
|
|
1589
|
-
var FormattedAmountUi = (value) => value;
|
|
1590
|
-
var FormattedPercentUi = (value) => value;
|
|
1591
|
-
var TxExplorerUrl = (value) => value;
|
|
1592
|
-
var ShortenedWalletAddress = (value) => value;
|
|
1593
|
-
var FormattedAmountAssetUi = (value) => value;
|
|
1594
|
-
var AssetIconUrl = (value) => value;
|
|
1595
|
-
|
|
1596
|
-
// src/universal/core/shared/blockchain/formatters.ts
|
|
1597
|
-
import { formatUnits } from "viem";
|
|
1598
|
-
function shortenAddress(address) {
|
|
1599
|
-
const short = address.length > 10 ? `${address.slice(0, 6)}\u2026${address.slice(-4)}` : address;
|
|
1600
|
-
return ShortenedWalletAddress(short);
|
|
1601
|
-
}
|
|
1602
|
-
function formatAmount(amount, locale, options) {
|
|
1603
|
-
const decimal = formatRawAmount(amount);
|
|
1604
|
-
let [integerPart, fractionPart = ""] = decimal.split(".");
|
|
1605
|
-
const maxFractionDigits = options?.maxFractionDigits;
|
|
1606
|
-
const minFractionDigits = Math.min(
|
|
1607
|
-
options?.minFractionDigits ?? (maxFractionDigits !== void 0 ? maxFractionDigits : 2),
|
|
1608
|
-
maxFractionDigits ?? amount.decimals,
|
|
1609
|
-
amount.decimals
|
|
1610
|
-
);
|
|
1611
|
-
if (maxFractionDigits !== void 0 && fractionPart.length > maxFractionDigits) {
|
|
1612
|
-
({ integerPart, fractionPart } = roundFractionHalfUp(
|
|
1613
|
-
integerPart,
|
|
1614
|
-
fractionPart,
|
|
1615
|
-
maxFractionDigits
|
|
1616
|
-
));
|
|
1617
|
-
}
|
|
1618
|
-
const trimmed = fractionPart.replace(/0+$/, "");
|
|
1619
|
-
const fraction = trimmed.padEnd(minFractionDigits, "0");
|
|
1620
|
-
const integerFormatted = BigInt(integerPart).toLocaleString(locale);
|
|
1621
|
-
if (minFractionDigits === 0 && fraction === "") {
|
|
1622
|
-
return FormattedAmountUi(integerFormatted);
|
|
1623
|
-
}
|
|
1624
|
-
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
1625
|
-
return FormattedAmountUi(`${integerFormatted}${decimalSeparator}${fraction}`);
|
|
1626
|
-
}
|
|
1627
|
-
function roundFractionHalfUp(integerPart, fractionPart, maxFractionDigits) {
|
|
1628
|
-
if (fractionPart.length <= maxFractionDigits) {
|
|
1629
|
-
return { integerPart, fractionPart };
|
|
1630
|
-
}
|
|
1631
|
-
if (maxFractionDigits === 0) {
|
|
1632
|
-
const roundUp = fractionPart[0] >= "5";
|
|
1633
|
-
const integer = BigInt(integerPart) + (roundUp ? 1n : 0n);
|
|
1634
|
-
return { integerPart: integer.toString(), fractionPart: "" };
|
|
1635
|
-
}
|
|
1636
|
-
const trimmed = fractionPart.slice(0, maxFractionDigits);
|
|
1637
|
-
if (fractionPart[maxFractionDigits] < "5") {
|
|
1638
|
-
return { integerPart, fractionPart: trimmed };
|
|
1639
|
-
}
|
|
1640
|
-
const digits = trimmed.split("").map((digit) => Number.parseInt(digit, 10));
|
|
1641
|
-
let carry = 1;
|
|
1642
|
-
for (let i = digits.length - 1; i >= 0 && carry > 0; i -= 1) {
|
|
1643
|
-
const sum = digits[i] + carry;
|
|
1644
|
-
if (sum === 10) {
|
|
1645
|
-
digits[i] = 0;
|
|
1646
|
-
carry = 1;
|
|
1647
|
-
} else {
|
|
1648
|
-
digits[i] = sum;
|
|
1649
|
-
carry = 0;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
return {
|
|
1653
|
-
integerPart: carry > 0 ? (BigInt(integerPart) + 1n).toString() : integerPart,
|
|
1654
|
-
fractionPart: digits.join("")
|
|
1655
|
-
};
|
|
1656
|
-
}
|
|
1657
|
-
function formatRawAmount(amount) {
|
|
1658
|
-
return formatUnits(amount.raw, amount.decimals);
|
|
1659
|
-
}
|
|
1660
|
-
function formatCompactAmount(amount, locale) {
|
|
1661
|
-
const value = Number(formatRawAmount(amount));
|
|
1662
|
-
const formatted = new Intl.NumberFormat(locale, {
|
|
1663
|
-
notation: "compact",
|
|
1664
|
-
maximumFractionDigits: 2
|
|
1665
|
-
}).format(value);
|
|
1666
|
-
return FormattedAmountUi(formatted);
|
|
1667
|
-
}
|
|
1668
|
-
function formatBpsAsPercent(bps, locale) {
|
|
1669
|
-
const whole = bps / 100n;
|
|
1670
|
-
const fraction = bps % 100n;
|
|
1671
|
-
const wholeFormatted = whole.toLocaleString(locale);
|
|
1672
|
-
const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
|
|
1673
|
-
if (fraction === 0n) {
|
|
1674
|
-
return FormattedPercentUi(`${wholeFormatted}%`);
|
|
1675
|
-
}
|
|
1676
|
-
const fractionFormatted = fraction.toString().padStart(2, "0").replace(/0+$/, "");
|
|
1677
|
-
return FormattedPercentUi(
|
|
1678
|
-
`${wholeFormatted}${decimalSeparator}${fractionFormatted}%`
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1681
|
-
function usdAmount(amount) {
|
|
1682
|
-
return FormattedAmountAssetUi(`$${amount}`);
|
|
1683
|
-
}
|
|
1684
|
-
function assetAmount(amount, symbol) {
|
|
1685
|
-
return FormattedAmountAssetUi(`${amount} ${symbol}`);
|
|
1686
|
-
}
|
|
1687
|
-
var NA_AMOUNT_ASSET_UI = FormattedAmountAssetUi("-");
|
|
1688
|
-
var SHARE_MAX_FRACTION_DIGITS = AssetDecimals(6);
|
|
1689
|
-
var SHARE_MIN_FRACTION_DIGITS = AssetDecimals(2);
|
|
1690
|
-
function formatShareAmount(amount, locale) {
|
|
1691
|
-
return formatAmount(amount, locale, {
|
|
1692
|
-
maxFractionDigits: SHARE_MAX_FRACTION_DIGITS,
|
|
1693
|
-
minFractionDigits: SHARE_MIN_FRACTION_DIGITS
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
var USD_FRACTION_DIGITS = AssetDecimals(2);
|
|
1697
|
-
function formattedUsdPrice(amount, locale) {
|
|
1698
|
-
if (!amount) return NA_AMOUNT_ASSET_UI;
|
|
1699
|
-
return usdAmount(
|
|
1700
|
-
formatAmount(amount, locale, { maxFractionDigits: USD_FRACTION_DIGITS })
|
|
1701
|
-
);
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
// src/universal/core/shared/blockchain/chain.ts
|
|
1705
|
-
import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
|
|
1706
|
-
var VIEM_CHAINS = {
|
|
1707
|
-
ethereum_mainnet: mainnet,
|
|
1708
|
-
ethereum_sepolia: sepolia,
|
|
1709
|
-
base_mainnet: base,
|
|
1710
|
-
base_sepolia: baseSepolia
|
|
1711
|
-
};
|
|
1712
|
-
function viemChain(chain) {
|
|
1713
|
-
return VIEM_CHAINS[chain];
|
|
1714
|
-
}
|
|
1715
|
-
function getChainId(chain) {
|
|
1716
|
-
return VIEM_CHAINS[chain].id;
|
|
1717
|
-
}
|
|
1718
|
-
function chainFromId(chainId) {
|
|
1719
|
-
const chains = Object.keys(VIEM_CHAINS);
|
|
1720
|
-
const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
|
|
1721
|
-
if (!chain) {
|
|
1722
|
-
throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
|
|
1723
|
-
}
|
|
1724
|
-
return chain;
|
|
1725
|
-
}
|
|
1726
|
-
function getNetworkName(chain) {
|
|
1727
|
-
switch (chain) {
|
|
1728
|
-
case "ethereum_mainnet":
|
|
1729
|
-
return "Ethereum";
|
|
1730
|
-
case "ethereum_sepolia":
|
|
1731
|
-
return "Ethereum Sepolia";
|
|
1732
|
-
case "base_mainnet":
|
|
1733
|
-
return "Base";
|
|
1734
|
-
case "base_sepolia":
|
|
1735
|
-
return "Base Sepolia";
|
|
1736
|
-
default: {
|
|
1737
|
-
const _exhaustive = chain;
|
|
1738
|
-
return _exhaustive;
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
function txExplorerUrl(chain, txHash) {
|
|
1743
|
-
return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
|
|
1744
|
-
}
|
|
1745
|
-
function explorerBaseUrl(chain) {
|
|
1746
|
-
switch (chain) {
|
|
1747
|
-
case "ethereum_mainnet":
|
|
1748
|
-
return "https://etherscan.io";
|
|
1749
|
-
case "ethereum_sepolia":
|
|
1750
|
-
return "https://sepolia.etherscan.io";
|
|
1751
|
-
case "base_mainnet":
|
|
1752
|
-
return "https://basescan.org";
|
|
1753
|
-
case "base_sepolia":
|
|
1754
|
-
return "https://sepolia-explorer.base.org";
|
|
1755
|
-
default: {
|
|
1756
|
-
const _exhaustive = chain;
|
|
1757
|
-
return _exhaustive;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
1619
|
// src/universal/types/providers/ondo/ondo.ts
|
|
1763
1620
|
var OndoTradingStatus = {
|
|
1764
1621
|
fromDto: (dto) => {
|
|
@@ -1813,7 +1670,7 @@ var OndoBuyTransaction = {
|
|
|
1813
1670
|
raw: dto.notional_value,
|
|
1814
1671
|
decimals: spendDecimals
|
|
1815
1672
|
}),
|
|
1816
|
-
receiveOutputAmount:
|
|
1673
|
+
receiveOutputAmount: positiveAmountFromRawOrThrow({
|
|
1817
1674
|
label: "receive_output_amount",
|
|
1818
1675
|
raw: dto.receive_output_amount,
|
|
1819
1676
|
decimals: outputDecimals,
|
|
@@ -1832,7 +1689,7 @@ var OndoSellTransaction = {
|
|
|
1832
1689
|
fromDto: (dto) => {
|
|
1833
1690
|
const spendDecimals = AssetDecimals(dto.spend_input_decimals);
|
|
1834
1691
|
const outputDecimals = AssetDecimals(dto.receive_output_decimals);
|
|
1835
|
-
const expectedQuantity =
|
|
1692
|
+
const expectedQuantity = positiveAmountFromRawOrThrow({
|
|
1836
1693
|
label: "expected_quantity",
|
|
1837
1694
|
raw: dto.expected_quantity,
|
|
1838
1695
|
decimals: outputDecimals,
|
|
@@ -1866,12 +1723,12 @@ var OndoSellTransaction = {
|
|
|
1866
1723
|
};
|
|
1867
1724
|
function parseSwapCore(dto, spendDecimals) {
|
|
1868
1725
|
return {
|
|
1869
|
-
tx:
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
expiresAt:
|
|
1874
|
-
spendInputAmount:
|
|
1726
|
+
tx: txFromWire(dto),
|
|
1727
|
+
// A transaction whose expiry cannot be read is not safely fillable - the
|
|
1728
|
+
// deadline is encoded in the calldata either way, so broadcasting against
|
|
1729
|
+
// an unknown one only spends gas on a revert.
|
|
1730
|
+
expiresAt: requiredDate(dto.expires_at, "expires_at"),
|
|
1731
|
+
spendInputAmount: positiveAmountFromRawOrThrow({
|
|
1875
1732
|
label: "spend_input_amount",
|
|
1876
1733
|
raw: dto.spend_input_amount,
|
|
1877
1734
|
decimals: spendDecimals,
|
|
@@ -1889,7 +1746,7 @@ function parseSwapCore(dto, spendDecimals) {
|
|
|
1889
1746
|
};
|
|
1890
1747
|
}
|
|
1891
1748
|
function parseMinimumQuantity(raw, decimals, expectedQuantity) {
|
|
1892
|
-
const amount =
|
|
1749
|
+
const amount = positiveAmountFromRawOrThrow({
|
|
1893
1750
|
label: "minimum_quantity",
|
|
1894
1751
|
raw,
|
|
1895
1752
|
decimals,
|
|
@@ -1902,27 +1759,6 @@ function parseMinimumQuantity(raw, decimals, expectedQuantity) {
|
|
|
1902
1759
|
}
|
|
1903
1760
|
return amount;
|
|
1904
1761
|
}
|
|
1905
|
-
function parsePositiveAmount({
|
|
1906
|
-
label,
|
|
1907
|
-
raw,
|
|
1908
|
-
decimals,
|
|
1909
|
-
reason
|
|
1910
|
-
}) {
|
|
1911
|
-
const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
|
|
1912
|
-
if (amount.raw <= 0n) {
|
|
1913
|
-
throw new ValidationError(
|
|
1914
|
-
`${label}: must be greater than zero ("${raw}") - ${reason}`
|
|
1915
|
-
);
|
|
1916
|
-
}
|
|
1917
|
-
return amount;
|
|
1918
|
-
}
|
|
1919
|
-
function parseExpiresAt(value) {
|
|
1920
|
-
const date = new Date(value);
|
|
1921
|
-
if (Number.isNaN(date.getTime())) {
|
|
1922
|
-
throw new ValidationError(`expires_at: not a date ("${value}")`);
|
|
1923
|
-
}
|
|
1924
|
-
return date;
|
|
1925
|
-
}
|
|
1926
1762
|
|
|
1927
1763
|
// src/universal/api/frontline/providers/ondo/ondo.ts
|
|
1928
1764
|
async function getOndoTradingStatus(api, params) {
|
|
@@ -1978,27 +1814,15 @@ async function buildOndoSell(api, params) {
|
|
|
1978
1814
|
// or a QA run reads as a puzzle rather than a diagnosis.
|
|
1979
1815
|
note: "the quote resolves the asset on Ethereum mainnet while the swap executes on the chain requested, so these disagree until frontline serves a chain-scoped quote"
|
|
1980
1816
|
});
|
|
1981
|
-
return OndoSellTransaction.fromDto(dto);
|
|
1982
|
-
}
|
|
1983
|
-
function swapBody(params) {
|
|
1984
|
-
return {
|
|
1985
|
-
symbol: params.symbol,
|
|
1986
|
-
chain: params.chain,
|
|
1987
|
-
wallet_address: params.walletAddress,
|
|
1988
|
-
amount: params.amount.raw.toString()
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
1991
|
-
function assertSpendScaleAgrees({
|
|
1992
|
-
published,
|
|
1993
|
-
sized,
|
|
1994
|
-
trade,
|
|
1995
|
-
note
|
|
1996
|
-
}) {
|
|
1997
|
-
if (published === sized.decimals) return;
|
|
1998
|
-
const because = note === void 0 ? "" : ` - ${note}`;
|
|
1999
|
-
throw new ValidationError(
|
|
2000
|
-
`spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
|
|
2001
|
-
);
|
|
1817
|
+
return OndoSellTransaction.fromDto(dto);
|
|
1818
|
+
}
|
|
1819
|
+
function swapBody(params) {
|
|
1820
|
+
return {
|
|
1821
|
+
symbol: params.symbol,
|
|
1822
|
+
chain: params.chain,
|
|
1823
|
+
wallet_address: params.walletAddress,
|
|
1824
|
+
amount: params.amount.raw.toString()
|
|
1825
|
+
};
|
|
2002
1826
|
}
|
|
2003
1827
|
function sizeParam(params) {
|
|
2004
1828
|
const tokenAmount = "tokenAmount" in params ? params.tokenAmount : void 0;
|
|
@@ -2019,7 +1843,7 @@ function sizeParam(params) {
|
|
|
2019
1843
|
return { notional_value: notionalValue };
|
|
2020
1844
|
}
|
|
2021
1845
|
|
|
2022
|
-
// src/universal/core/
|
|
1846
|
+
// src/universal/core/providers/ondo/ondo-namespace.ts
|
|
2023
1847
|
var OndoNamespaceImpl = class {
|
|
2024
1848
|
constructor(ctx) {
|
|
2025
1849
|
this.ctx = ctx;
|
|
@@ -2051,7 +1875,101 @@ var OndoNamespaceImpl = class {
|
|
|
2051
1875
|
}
|
|
2052
1876
|
};
|
|
2053
1877
|
|
|
2054
|
-
// src/universal/
|
|
1878
|
+
// src/universal/types/providers/superstate/swap.ts
|
|
1879
|
+
var SwapPreview = {
|
|
1880
|
+
/** Maps the contract's `Preview { input, fee, output }` struct. */
|
|
1881
|
+
fromContract: (preview) => ({
|
|
1882
|
+
inputAmount: parseUint256(preview.input, "SwapPreview.input"),
|
|
1883
|
+
fee: parseUint256(preview.fee, "SwapPreview.fee"),
|
|
1884
|
+
outputAmount: parseUint256(preview.output, "SwapPreview.output")
|
|
1885
|
+
})
|
|
1886
|
+
};
|
|
1887
|
+
var PauseFlags = (value) => value;
|
|
1888
|
+
var SwapStatus = {
|
|
1889
|
+
/**
|
|
1890
|
+
* Maps the contract's `Status { uint32 flags; State state }` struct, where
|
|
1891
|
+
* `State` is `0 = Active | 1 = Paused | 2 = Stopped`.
|
|
1892
|
+
*
|
|
1893
|
+
* `flags` is carried onto the `paused` arm only. On the other two the
|
|
1894
|
+
* contract sets it to a self-identifying marker rather than to information -
|
|
1895
|
+
* so repeating it would invite a caller to read meaning into a constant.
|
|
1896
|
+
*
|
|
1897
|
+
* @throws ValidationError on a `state` outside the enum. A contract that has
|
|
1898
|
+
* grown a fourth state is one the SDK does not model, and guessing `active`
|
|
1899
|
+
* would let a halted swap read as a live one.
|
|
1900
|
+
*/
|
|
1901
|
+
fromContract: (status) => {
|
|
1902
|
+
switch (status.state) {
|
|
1903
|
+
case 0:
|
|
1904
|
+
return { state: "active" };
|
|
1905
|
+
case 1:
|
|
1906
|
+
return { state: "paused", pausedLevels: PauseFlags(status.flags) };
|
|
1907
|
+
case 2:
|
|
1908
|
+
return { state: "stopped" };
|
|
1909
|
+
default:
|
|
1910
|
+
throw new ValidationError(
|
|
1911
|
+
`SwapStatus.state: unknown contract state (${status.state})`
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
var AllowWalletResponse = {
|
|
1917
|
+
fromDto: (dto) => {
|
|
1918
|
+
switch (dto.action) {
|
|
1919
|
+
case "broadcast_transaction":
|
|
1920
|
+
return {
|
|
1921
|
+
action: "broadcast_transaction",
|
|
1922
|
+
tx: txFromWire(dto)
|
|
1923
|
+
};
|
|
1924
|
+
case "none":
|
|
1925
|
+
return {
|
|
1926
|
+
action: "none",
|
|
1927
|
+
alreadyAllowed: dto.already_allowed
|
|
1928
|
+
};
|
|
1929
|
+
default: {
|
|
1930
|
+
const _exhaustive = dto;
|
|
1931
|
+
return _exhaustive;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
|
|
1937
|
+
// src/universal/core/providers/superstate/blockchain/quote.ts
|
|
1938
|
+
var SwapQuote = {
|
|
1939
|
+
/**
|
|
1940
|
+
* Assembles a {@link SwapQuote} from a raw contract {@link SwapPreview}. The
|
|
1941
|
+
* input and fee are denominated in the input token; the output in the output
|
|
1942
|
+
* token.
|
|
1943
|
+
*/
|
|
1944
|
+
fromPreview: (preview, inputDecimals, outputDecimals) => ({
|
|
1945
|
+
inputTokenAmount: BlockchainAmount({
|
|
1946
|
+
raw: preview.inputAmount,
|
|
1947
|
+
decimals: inputDecimals
|
|
1948
|
+
}),
|
|
1949
|
+
fee: BlockchainAmount({ raw: preview.fee, decimals: inputDecimals }),
|
|
1950
|
+
outputTokenAmount: BlockchainAmount({
|
|
1951
|
+
raw: preview.outputAmount,
|
|
1952
|
+
decimals: outputDecimals
|
|
1953
|
+
})
|
|
1954
|
+
})
|
|
1955
|
+
};
|
|
1956
|
+
|
|
1957
|
+
// src/universal/api/frontline/providers/superstate/swap.ts
|
|
1958
|
+
async function allowWallet(api, params) {
|
|
1959
|
+
const dto = await api.send({
|
|
1960
|
+
method: "POST",
|
|
1961
|
+
url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
|
|
1962
|
+
body: {
|
|
1963
|
+
wallet_address: params.walletAddress,
|
|
1964
|
+
chain: params.chain,
|
|
1965
|
+
signature: params.signature
|
|
1966
|
+
},
|
|
1967
|
+
attributes: Attributes.protected()
|
|
1968
|
+
});
|
|
1969
|
+
return AllowWalletResponse.fromDto(dto);
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
// src/universal/core/providers/superstate/blockchain/abi.ts
|
|
2055
1973
|
var SUPERSTATE_SWAP_ABI = [
|
|
2056
1974
|
{
|
|
2057
1975
|
type: "function",
|
|
@@ -2923,80 +2841,105 @@ var SUPERSTATE_SWAP_ABI = [
|
|
|
2923
2841
|
}
|
|
2924
2842
|
];
|
|
2925
2843
|
|
|
2926
|
-
// src/universal/
|
|
2927
|
-
var
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
}
|
|
2844
|
+
// src/universal/core/shared/blockchain/erc20/abi.ts
|
|
2845
|
+
var ERC20_ABI = [
|
|
2846
|
+
{
|
|
2847
|
+
type: "function",
|
|
2848
|
+
name: "allowance",
|
|
2849
|
+
inputs: [
|
|
2850
|
+
{ name: "owner", type: "address" },
|
|
2851
|
+
{ name: "spender", type: "address" }
|
|
2852
|
+
],
|
|
2853
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2854
|
+
stateMutability: "view"
|
|
2855
|
+
},
|
|
2856
|
+
{
|
|
2857
|
+
type: "function",
|
|
2858
|
+
name: "approve",
|
|
2859
|
+
inputs: [
|
|
2860
|
+
{ name: "spender", type: "address" },
|
|
2861
|
+
{ name: "amount", type: "uint256" }
|
|
2862
|
+
],
|
|
2863
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2864
|
+
stateMutability: "nonpayable"
|
|
2865
|
+
},
|
|
2866
|
+
{
|
|
2867
|
+
type: "function",
|
|
2868
|
+
name: "balanceOf",
|
|
2869
|
+
inputs: [{ name: "account", type: "address" }],
|
|
2870
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2871
|
+
stateMutability: "view"
|
|
2872
|
+
},
|
|
2873
|
+
{
|
|
2874
|
+
type: "function",
|
|
2875
|
+
name: "decimals",
|
|
2876
|
+
inputs: [],
|
|
2877
|
+
outputs: [{ name: "", type: "uint8" }],
|
|
2878
|
+
stateMutability: "view"
|
|
2879
|
+
},
|
|
2880
|
+
{
|
|
2881
|
+
type: "function",
|
|
2882
|
+
name: "name",
|
|
2883
|
+
inputs: [],
|
|
2884
|
+
outputs: [{ name: "", type: "string" }],
|
|
2885
|
+
stateMutability: "view"
|
|
2886
|
+
},
|
|
2887
|
+
{
|
|
2888
|
+
type: "function",
|
|
2889
|
+
name: "symbol",
|
|
2890
|
+
inputs: [],
|
|
2891
|
+
outputs: [{ name: "", type: "string" }],
|
|
2892
|
+
stateMutability: "view"
|
|
2893
|
+
},
|
|
2894
|
+
{
|
|
2895
|
+
type: "function",
|
|
2896
|
+
name: "totalSupply",
|
|
2897
|
+
inputs: [],
|
|
2898
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2899
|
+
stateMutability: "view"
|
|
2900
|
+
},
|
|
2901
|
+
{
|
|
2902
|
+
type: "function",
|
|
2903
|
+
name: "transfer",
|
|
2904
|
+
inputs: [
|
|
2905
|
+
{ name: "recipient", type: "address" },
|
|
2906
|
+
{ name: "amount", type: "uint256" }
|
|
2907
|
+
],
|
|
2908
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2909
|
+
stateMutability: "nonpayable"
|
|
2910
|
+
},
|
|
2911
|
+
{
|
|
2912
|
+
type: "function",
|
|
2913
|
+
name: "transferFrom",
|
|
2914
|
+
inputs: [
|
|
2915
|
+
{ name: "sender", type: "address" },
|
|
2916
|
+
{ name: "recipient", type: "address" },
|
|
2917
|
+
{ name: "amount", type: "uint256" }
|
|
2918
|
+
],
|
|
2919
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2920
|
+
stateMutability: "nonpayable"
|
|
2921
|
+
},
|
|
2922
|
+
{
|
|
2923
|
+
type: "event",
|
|
2924
|
+
name: "Approval",
|
|
2925
|
+
inputs: [
|
|
2926
|
+
{ name: "owner", type: "address", indexed: true },
|
|
2927
|
+
{ name: "spender", type: "address", indexed: true },
|
|
2928
|
+
{ name: "value", type: "uint256", indexed: false }
|
|
2929
|
+
],
|
|
2930
|
+
anonymous: false
|
|
2931
|
+
},
|
|
2932
|
+
{
|
|
2933
|
+
type: "event",
|
|
2934
|
+
name: "Transfer",
|
|
2935
|
+
inputs: [
|
|
2936
|
+
{ name: "from", type: "address", indexed: true },
|
|
2937
|
+
{ name: "to", type: "address", indexed: true },
|
|
2938
|
+
{ name: "value", type: "uint256", indexed: false }
|
|
2939
|
+
],
|
|
2940
|
+
anonymous: false
|
|
2941
|
+
}
|
|
2942
|
+
];
|
|
3000
2943
|
|
|
3001
2944
|
// src/universal/api/rpc/providers/superstate/swap.ts
|
|
3002
2945
|
async function getSwapAuthorization(clients, params) {
|
|
@@ -3047,7 +2990,7 @@ async function getSwapOutputToken(clients, params) {
|
|
|
3047
2990
|
};
|
|
3048
2991
|
}
|
|
3049
2992
|
|
|
3050
|
-
// src/universal/core/
|
|
2993
|
+
// src/universal/core/providers/superstate/superstate-namespace.ts
|
|
3051
2994
|
var SuperstateSwapNamespaceImpl = class {
|
|
3052
2995
|
constructor(ctx) {
|
|
3053
2996
|
this.ctx = ctx;
|
|
@@ -3067,6 +3010,20 @@ var SuperstateSwapNamespaceImpl = class {
|
|
|
3067
3010
|
async () => getSwapPreview(this.ctx.rpc, params)
|
|
3068
3011
|
);
|
|
3069
3012
|
}
|
|
3013
|
+
async getQuote(params) {
|
|
3014
|
+
return this.log.wrap("getQuote", params, async () => {
|
|
3015
|
+
const { amount, outputTokenDecimals, ...ref } = params;
|
|
3016
|
+
const preview = await getSwapPreview(this.ctx.rpc, {
|
|
3017
|
+
...ref,
|
|
3018
|
+
amount: amount.raw
|
|
3019
|
+
});
|
|
3020
|
+
return SwapQuote.fromPreview(
|
|
3021
|
+
preview,
|
|
3022
|
+
amount.decimals,
|
|
3023
|
+
outputTokenDecimals
|
|
3024
|
+
);
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3070
3027
|
async getStatus(params) {
|
|
3071
3028
|
return this.log.wrap(
|
|
3072
3029
|
"getStatus",
|
|
@@ -3264,6 +3221,202 @@ var RequirementsNamespaceImpl = class {
|
|
|
3264
3221
|
}
|
|
3265
3222
|
};
|
|
3266
3223
|
|
|
3224
|
+
// src/universal/types/offer-option-address.ts
|
|
3225
|
+
var OfferOptionAddressId = (value) => value;
|
|
3226
|
+
var OfferOptionAddress = {
|
|
3227
|
+
/** Maps the API DTO into the SDK offer-option-address domain model. */
|
|
3228
|
+
fromDto: (dto) => ({
|
|
3229
|
+
id: OfferOptionAddressId(dto.id),
|
|
3230
|
+
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
3231
|
+
address: EvmWalletAddress(dto.address),
|
|
3232
|
+
protocol: dto.protocol,
|
|
3233
|
+
createdAt: new Date(dto.created_at)
|
|
3234
|
+
})
|
|
3235
|
+
};
|
|
3236
|
+
var ConnectExternalWalletParams = {
|
|
3237
|
+
/** Maps connect-wallet params into the API DTO payload. */
|
|
3238
|
+
toDto: (params) => ({
|
|
3239
|
+
offer_option_id: params.offerOptionId,
|
|
3240
|
+
wallet_address: params.walletAddress,
|
|
3241
|
+
chain: params.chain,
|
|
3242
|
+
signature: params.signature
|
|
3243
|
+
})
|
|
3244
|
+
};
|
|
3245
|
+
|
|
3246
|
+
// src/universal/types/wallet-ownership-challenge.ts
|
|
3247
|
+
var WalletOwnershipChallenge = {
|
|
3248
|
+
/** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
|
|
3249
|
+
fromDto: (dto) => ({
|
|
3250
|
+
message: dto.message,
|
|
3251
|
+
expiresAt: new Date(dto.expires_at)
|
|
3252
|
+
})
|
|
3253
|
+
};
|
|
3254
|
+
var CreateWalletOwnershipChallengeParams = {
|
|
3255
|
+
/**
|
|
3256
|
+
* Maps challenge-request params into the API DTO payload. The discriminated
|
|
3257
|
+
* union guarantees SIWE fields are present exactly when `challengeType` is
|
|
3258
|
+
* `siwe`, so the mapping narrows on the discriminant.
|
|
3259
|
+
*/
|
|
3260
|
+
toDto: (params) => {
|
|
3261
|
+
switch (params.challengeType) {
|
|
3262
|
+
case "plain":
|
|
3263
|
+
return {
|
|
3264
|
+
wallet_address: params.walletAddress,
|
|
3265
|
+
chain: params.chain,
|
|
3266
|
+
challenge_type: "plain"
|
|
3267
|
+
};
|
|
3268
|
+
case "siwe":
|
|
3269
|
+
return {
|
|
3270
|
+
wallet_address: params.walletAddress,
|
|
3271
|
+
chain: params.chain,
|
|
3272
|
+
challenge_type: "siwe",
|
|
3273
|
+
domain: params.domain,
|
|
3274
|
+
uri: params.uri,
|
|
3275
|
+
statement: params.statement
|
|
3276
|
+
};
|
|
3277
|
+
default: {
|
|
3278
|
+
const _exhaustive = params;
|
|
3279
|
+
return _exhaustive;
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
};
|
|
3284
|
+
|
|
3285
|
+
// src/universal/api/frontline/wallet-connect.ts
|
|
3286
|
+
async function createWalletOwnershipChallenge(api, params) {
|
|
3287
|
+
const dto = await api.send({
|
|
3288
|
+
method: "POST",
|
|
3289
|
+
url: "/v1/wallet-ownership",
|
|
3290
|
+
body: CreateWalletOwnershipChallengeParams.toDto(params),
|
|
3291
|
+
attributes: Attributes.protected()
|
|
3292
|
+
});
|
|
3293
|
+
return WalletOwnershipChallenge.fromDto(dto);
|
|
3294
|
+
}
|
|
3295
|
+
async function connectExternalWallet(api, params) {
|
|
3296
|
+
const dto = await api.send({
|
|
3297
|
+
method: "POST",
|
|
3298
|
+
url: `/v1/offers/${params.offerId}/addresses`,
|
|
3299
|
+
body: ConnectExternalWalletParams.toDto(params),
|
|
3300
|
+
attributes: Attributes.protected()
|
|
3301
|
+
});
|
|
3302
|
+
return OfferOptionAddress.fromDto(dto);
|
|
3303
|
+
}
|
|
3304
|
+
async function listOptionAddresses(api, offerId, offerOptionId) {
|
|
3305
|
+
const { data } = await api.send({
|
|
3306
|
+
method: "GET",
|
|
3307
|
+
url: `/v1/offers/${offerId}/addresses`,
|
|
3308
|
+
queryParams: { offer_option_id: offerOptionId },
|
|
3309
|
+
attributes: Attributes.protected()
|
|
3310
|
+
});
|
|
3311
|
+
return data.map(OfferOptionAddress.fromDto);
|
|
3312
|
+
}
|
|
3313
|
+
async function removeOptionAddress(api, offerId, addressId) {
|
|
3314
|
+
const dto = await api.send({
|
|
3315
|
+
method: "DELETE",
|
|
3316
|
+
url: `/v1/offers/${offerId}/addresses/${addressId}`,
|
|
3317
|
+
attributes: Attributes.protected()
|
|
3318
|
+
});
|
|
3319
|
+
return OfferOptionAddress.fromDto(dto);
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
// src/universal/core/wallets/wallets-namespace.ts
|
|
3323
|
+
var WalletsNamespaceImpl = class {
|
|
3324
|
+
constructor(ctx) {
|
|
3325
|
+
this.ctx = ctx;
|
|
3326
|
+
this.log = internalLogger(ctx.logger, "WALLETS");
|
|
3327
|
+
}
|
|
3328
|
+
async createOwnershipChallenge(params) {
|
|
3329
|
+
return this.log.wrap("createOwnershipChallenge", params, async () => {
|
|
3330
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3331
|
+
return createWalletOwnershipChallenge(
|
|
3332
|
+
this.ctx.api,
|
|
3333
|
+
params
|
|
3334
|
+
);
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
async connectExternal(params) {
|
|
3338
|
+
return this.log.wrap("connectExternal", params, async () => {
|
|
3339
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3340
|
+
return connectExternalWallet(this.ctx.api, params);
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3343
|
+
async list(params) {
|
|
3344
|
+
return this.log.wrap("list", params, async () => {
|
|
3345
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3346
|
+
return listOptionAddresses(
|
|
3347
|
+
this.ctx.api,
|
|
3348
|
+
params.offerId,
|
|
3349
|
+
params.offerOptionId
|
|
3350
|
+
);
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
async remove(params) {
|
|
3354
|
+
return this.log.wrap("remove", params, async () => {
|
|
3355
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3356
|
+
return removeOptionAddress(
|
|
3357
|
+
this.ctx.api,
|
|
3358
|
+
params.offerId,
|
|
3359
|
+
params.addressId
|
|
3360
|
+
);
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
};
|
|
3364
|
+
|
|
3365
|
+
// src/universal/api/frontline/offers.ts
|
|
3366
|
+
async function fetchOffers(api, clientCreds) {
|
|
3367
|
+
return fetchAllPages((params) => fetchOffersPage(api, params, clientCreds));
|
|
3368
|
+
}
|
|
3369
|
+
async function fetchOffersPage(api, params, clientCreds) {
|
|
3370
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
3371
|
+
const pageDto = await api.send({
|
|
3372
|
+
method: "GET",
|
|
3373
|
+
url: "/v1/offers",
|
|
3374
|
+
queryParams,
|
|
3375
|
+
attributes: Attributes.concat(
|
|
3376
|
+
Attributes.protected(),
|
|
3377
|
+
Attributes.clientCredentials(clientCreds)
|
|
3378
|
+
)
|
|
3379
|
+
});
|
|
3380
|
+
return PaginatedResponse.fromDtoPage(pageDto, Offer.listFromDto);
|
|
3381
|
+
}
|
|
3382
|
+
async function fetchOfferDetails(api, id, clientCreds) {
|
|
3383
|
+
const dto = await api.send({
|
|
3384
|
+
method: "GET",
|
|
3385
|
+
url: `/v1/offers/${id}`,
|
|
3386
|
+
attributes: Attributes.concat(
|
|
3387
|
+
Attributes.protected(),
|
|
3388
|
+
Attributes.clientCredentials(clientCreds)
|
|
3389
|
+
)
|
|
3390
|
+
});
|
|
3391
|
+
return OfferDetail.fromDto(dto);
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3394
|
+
// src/universal/core/offers/offers-namespace.ts
|
|
3395
|
+
var OffersNamespaceImpl = class {
|
|
3396
|
+
constructor(ctx) {
|
|
3397
|
+
this.ctx = ctx;
|
|
3398
|
+
this.log = internalLogger(ctx.logger, "OFFERS");
|
|
3399
|
+
}
|
|
3400
|
+
async list() {
|
|
3401
|
+
return this.log.wrap("list", void 0, async () => {
|
|
3402
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3403
|
+
return fetchOffers(this.ctx.api, void 0);
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
async listPage(params) {
|
|
3407
|
+
return this.log.wrap("listPage", params, async () => {
|
|
3408
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3409
|
+
return fetchOffersPage(this.ctx.api, params, void 0);
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
async get(id) {
|
|
3413
|
+
return this.log.wrap("get", id, async () => {
|
|
3414
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3415
|
+
return fetchOfferDetails(this.ctx.api, id, void 0);
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
};
|
|
3419
|
+
|
|
3267
3420
|
// src/universal/api/rpc/erc20.ts
|
|
3268
3421
|
async function getTokenAllowance(clients, params) {
|
|
3269
3422
|
const allowance = await clients(params.chain).readContract({
|
|
@@ -3371,207 +3524,26 @@ function tokensOfChain(chain, assets, baseUrl) {
|
|
|
3371
3524
|
decimals: AssetDecimals(asset.decimals),
|
|
3372
3525
|
logo: TokenLogo.fromDto(asset.logo, baseUrl),
|
|
3373
3526
|
logoDark: asset.logo_dark === void 0 ? null : TokenLogo.fromDto(asset.logo_dark, baseUrl)
|
|
3374
|
-
}));
|
|
3375
|
-
}
|
|
3376
|
-
function assertSupportedSchemaVersion(version) {
|
|
3377
|
-
if (version !== 1) {
|
|
3378
|
-
throw new ValidationError(
|
|
3379
|
-
`Unsupported token registry schema_version: ${version}`
|
|
3380
|
-
);
|
|
3381
|
-
}
|
|
3382
|
-
}
|
|
3383
|
-
var logoImageFromDto = (dto, baseUrl) => ({
|
|
3384
|
-
url: resolveLogoUrl(dto.url, baseUrl),
|
|
3385
|
-
width: dto.width,
|
|
3386
|
-
height: dto.height
|
|
3387
|
-
});
|
|
3388
|
-
var resolveLogoUrl = (url, baseUrl) => TokenLogoUrl(
|
|
3389
|
-
url.startsWith("http") ? url : `${baseUrl.replace(/\/$/, "")}${url}`
|
|
3390
|
-
);
|
|
3391
|
-
|
|
3392
|
-
// src/universal/api/nabu/tokens.ts
|
|
3393
|
-
import { getAddress } from "viem";
|
|
3394
|
-
|
|
3395
|
-
// src/universal/api/frontline/config.ts
|
|
3396
|
-
var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
|
|
3397
|
-
var HEADER_API_VERSION = "X-API-Version";
|
|
3398
|
-
var HEADER_USER_AGENT = "User-Agent";
|
|
3399
|
-
var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
|
|
3400
|
-
var API_VERSION = "2025-10-17";
|
|
3401
|
-
var COINLIST_BASE_URL = "https://coinlist.co";
|
|
3402
|
-
var OAUTH_PAGE_PATH = "/oauth/authorize";
|
|
3403
|
-
var SUPPORT_NEW_TICKET_URL = "https://support.coinlist.co/support/tickets/new";
|
|
3404
|
-
var VERIFY_IDENTITY_PATH = "/verify-identity";
|
|
3405
|
-
var VERIFY_IDENTITY_ACCREDITATION_PATH = "/verify-identity/accreditation_full";
|
|
3406
|
-
var WALLET_PATH = "/wallet";
|
|
3407
|
-
|
|
3408
|
-
// src/universal/api/http-client.ts
|
|
3409
|
-
var HttpClient = class {
|
|
3410
|
-
constructor(config, middleware = {}, logger = null, options = {}) {
|
|
3411
|
-
this.config = config;
|
|
3412
|
-
this.middleware = middleware;
|
|
3413
|
-
this.log = internalLogger(logger, "HTTP");
|
|
3414
|
-
this.makeRequestId = options.makeRequestId ?? defaultMakeRequestId;
|
|
3415
|
-
}
|
|
3416
|
-
async send(request) {
|
|
3417
|
-
return this.runRequestWithAfterMiddleware(request);
|
|
3418
|
-
}
|
|
3419
|
-
/**
|
|
3420
|
-
* Runs beforeRequest, executeRequest, then the full afterRequest middleware
|
|
3421
|
-
* chain. Used by send() and by the retry() callback so that when a
|
|
3422
|
-
* middleware calls retry(), the retried response also goes through all
|
|
3423
|
-
* afterRequest middleware (e.g. session renewal, retry). Middleware
|
|
3424
|
-
* must use request.attributes.retryAttempt (or similar) to avoid infinite
|
|
3425
|
-
* recursion when they trigger retries.
|
|
3426
|
-
*/
|
|
3427
|
-
async runRequestWithAfterMiddleware(request) {
|
|
3428
|
-
const preparedRequest = await this.runBeforeRequestMiddleware(
|
|
3429
|
-
this.withClientDefaults(request)
|
|
3430
|
-
);
|
|
3431
|
-
let response = await this.executeRequest(preparedRequest);
|
|
3432
|
-
for (const middleware of this.middleware.afterRequest ?? []) {
|
|
3433
|
-
let retried = false;
|
|
3434
|
-
response = await middleware({
|
|
3435
|
-
request: preparedRequest,
|
|
3436
|
-
response,
|
|
3437
|
-
retry: (nextRequest = preparedRequest) => {
|
|
3438
|
-
retried = true;
|
|
3439
|
-
return this.runRequestWithAfterMiddleware(nextRequest);
|
|
3440
|
-
}
|
|
3441
|
-
});
|
|
3442
|
-
if (retried) {
|
|
3443
|
-
return response;
|
|
3444
|
-
}
|
|
3445
|
-
}
|
|
3446
|
-
return response;
|
|
3447
|
-
}
|
|
3448
|
-
withClientDefaults(request) {
|
|
3449
|
-
const url = this.resolveUrl(request.url);
|
|
3450
|
-
const headers = {
|
|
3451
|
-
...request.headers ?? {},
|
|
3452
|
-
...this.config.xApiVersion !== void 0 ? { [HEADER_API_VERSION]: this.config.xApiVersion } : {}
|
|
3453
|
-
};
|
|
3454
|
-
return {
|
|
3455
|
-
...request,
|
|
3456
|
-
url,
|
|
3457
|
-
headers,
|
|
3458
|
-
// Only when absent: a retry or a post-renewal re-send arrives with the
|
|
3459
|
-
// first attempt's id already on it, and keeping it is the whole point.
|
|
3460
|
-
attributes: Attributes.getRequestId(request.attributes) === null ? Attributes.concat(
|
|
3461
|
-
request.attributes ?? Attributes.empty,
|
|
3462
|
-
Attributes.requestId(this.makeRequestId())
|
|
3463
|
-
) : request.attributes
|
|
3464
|
-
};
|
|
3465
|
-
}
|
|
3466
|
-
/**
|
|
3467
|
-
* Resolves a request URL against the client's baseUrl.
|
|
3468
|
-
*
|
|
3469
|
-
* @internal Public only for testing. Do not use in application code; use
|
|
3470
|
-
* {@link HttpClient.send} with a path and the client will resolve the URL.
|
|
3471
|
-
*/
|
|
3472
|
-
resolveUrl(url) {
|
|
3473
|
-
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
3474
|
-
return url;
|
|
3475
|
-
}
|
|
3476
|
-
const base2 = this.config.baseUrl.replace(/\/$/, "");
|
|
3477
|
-
const path = url.startsWith("/") ? url : `/${url}`;
|
|
3478
|
-
return base2 + path;
|
|
3479
|
-
}
|
|
3480
|
-
async runBeforeRequestMiddleware(initialRequest) {
|
|
3481
|
-
let request = initialRequest;
|
|
3482
|
-
for (const middleware of this.middleware.beforeRequest ?? []) {
|
|
3483
|
-
request = await middleware(request);
|
|
3484
|
-
}
|
|
3485
|
-
return request;
|
|
3486
|
-
}
|
|
3487
|
-
/**
|
|
3488
|
-
* One physical attempt, logged as one line.
|
|
3489
|
-
*
|
|
3490
|
-
* A non-2xx is a `warn` rather than an `error` because the wire does not
|
|
3491
|
-
* know whether it is a failure: the retry middleware may turn a 503 into a
|
|
3492
|
-
* success, and the token registry reads a 404 as "not listed". The namespace
|
|
3493
|
-
* above decides, and logs the `error` when it does.
|
|
3494
|
-
*/
|
|
3495
|
-
async executeRequest(request) {
|
|
3496
|
-
const requestId2 = Attributes.getRequestId(request.attributes);
|
|
3497
|
-
const log = requestId2 === null ? this.log : this.log.child({ requestId: requestId2 });
|
|
3498
|
-
const attempt = Attributes.getRetryAttempt(request.attributes) + 1;
|
|
3499
|
-
const startedAt = Date.now();
|
|
3500
|
-
log.debug(() => ({
|
|
3501
|
-
msg: "request sent",
|
|
3502
|
-
fields: describeRequestUnredacted(request)
|
|
3503
|
-
}));
|
|
3504
|
-
try {
|
|
3505
|
-
const response = await makeRequest(request);
|
|
3506
|
-
const elapsed = Date.now() - startedAt;
|
|
3507
|
-
const outcome = () => ({
|
|
3508
|
-
msg: "request completed",
|
|
3509
|
-
fields: {
|
|
3510
|
-
...identifyRequest(request),
|
|
3511
|
-
"http.response.status_code": response.status,
|
|
3512
|
-
duration_ms: elapsed,
|
|
3513
|
-
attempt
|
|
3514
|
-
}
|
|
3515
|
-
});
|
|
3516
|
-
if (response.status >= 200 && response.status < 300) {
|
|
3517
|
-
log.info(outcome);
|
|
3518
|
-
} else {
|
|
3519
|
-
log.warn(outcome);
|
|
3520
|
-
}
|
|
3521
|
-
log.debug(() => ({
|
|
3522
|
-
msg: "response received",
|
|
3523
|
-
fields: { body: response.body }
|
|
3524
|
-
}));
|
|
3525
|
-
return requestId2 === null ? response : { ...response, requestId: requestId2 };
|
|
3526
|
-
} catch (error) {
|
|
3527
|
-
const elapsed = Date.now() - startedAt;
|
|
3528
|
-
log.warning(
|
|
3529
|
-
() => ({
|
|
3530
|
-
msg: "request threw",
|
|
3531
|
-
fields: {
|
|
3532
|
-
...identifyRequest(request),
|
|
3533
|
-
duration_ms: elapsed,
|
|
3534
|
-
attempt
|
|
3535
|
-
}
|
|
3536
|
-
}),
|
|
3537
|
-
error
|
|
3538
|
-
);
|
|
3539
|
-
throw error;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
};
|
|
3543
|
-
function identifyRequest(request) {
|
|
3544
|
-
const { host, path } = splitUrl(request.url);
|
|
3545
|
-
return {
|
|
3546
|
-
"http.request.method": request.method,
|
|
3547
|
-
"server.address": host,
|
|
3548
|
-
"url.path": path
|
|
3549
|
-
};
|
|
3550
|
-
}
|
|
3551
|
-
function splitUrl(url) {
|
|
3552
|
-
try {
|
|
3553
|
-
const parsed = new URL(url);
|
|
3554
|
-
return { host: parsed.host, path: parsed.pathname };
|
|
3555
|
-
} catch (_) {
|
|
3556
|
-
return { host: null, path: url };
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
3559
|
-
function defaultMakeRequestId() {
|
|
3560
|
-
return Math.random().toString(36).slice(2, 10).padEnd(8, "0");
|
|
3527
|
+
}));
|
|
3561
3528
|
}
|
|
3562
|
-
function
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
};
|
|
3529
|
+
function assertSupportedSchemaVersion(version) {
|
|
3530
|
+
if (version !== 1) {
|
|
3531
|
+
throw new ValidationError(
|
|
3532
|
+
`Unsupported token registry schema_version: ${version}`
|
|
3533
|
+
);
|
|
3534
|
+
}
|
|
3569
3535
|
}
|
|
3536
|
+
var logoImageFromDto = (dto, baseUrl) => ({
|
|
3537
|
+
url: resolveLogoUrl(dto.url, baseUrl),
|
|
3538
|
+
width: dto.width,
|
|
3539
|
+
height: dto.height
|
|
3540
|
+
});
|
|
3541
|
+
var resolveLogoUrl = (url, baseUrl) => TokenLogoUrl(
|
|
3542
|
+
url.startsWith("http") ? url : `${baseUrl.replace(/\/$/, "")}${url}`
|
|
3543
|
+
);
|
|
3570
3544
|
|
|
3571
3545
|
// src/universal/api/nabu/tokens.ts
|
|
3572
|
-
|
|
3573
|
-
return new HttpClient({ baseUrl }, {}, logger);
|
|
3574
|
-
}
|
|
3546
|
+
import { getAddress } from "viem";
|
|
3575
3547
|
async function fetchTokenMetadata(client, token) {
|
|
3576
3548
|
const address = checksummed(token.address);
|
|
3577
3549
|
let response;
|
|
@@ -3659,254 +3631,64 @@ function checksummed(address) {
|
|
|
3659
3631
|
}
|
|
3660
3632
|
}
|
|
3661
3633
|
|
|
3662
|
-
// src/universal/core/tokens/tokens-namespace.ts
|
|
3634
|
+
// src/universal/core/shared/blockchain/tokens/tokens-namespace.ts
|
|
3663
3635
|
var TokensNamespaceImpl = class {
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
* and the auth check would both be dead weight here.
|
|
3668
|
-
*/
|
|
3669
|
-
constructor(baseUrl, logger = null) {
|
|
3670
|
-
this.api = createNabuApiClient(baseUrl, logger);
|
|
3671
|
-
this.log = internalLogger(logger, "TOKENS");
|
|
3636
|
+
constructor(ctx) {
|
|
3637
|
+
this.ctx = ctx;
|
|
3638
|
+
this.log = internalLogger(ctx.logger, "TOKENS");
|
|
3672
3639
|
}
|
|
3673
3640
|
get(token) {
|
|
3674
3641
|
return this.log.wrap(
|
|
3675
3642
|
"get",
|
|
3676
3643
|
token,
|
|
3677
|
-
() => fetchTokenMetadata(this.
|
|
3644
|
+
() => fetchTokenMetadata(this.ctx.nabu, token)
|
|
3678
3645
|
);
|
|
3679
3646
|
}
|
|
3680
3647
|
list(chain) {
|
|
3681
3648
|
return this.log.wrap(
|
|
3682
3649
|
"list",
|
|
3683
3650
|
chain,
|
|
3684
|
-
() => chain === void 0 ? fetchAllTokensMetadata(this.
|
|
3651
|
+
() => chain === void 0 ? fetchAllTokensMetadata(this.ctx.nabu) : fetchTokensMetadata(this.ctx.nabu, chain)
|
|
3685
3652
|
);
|
|
3686
3653
|
}
|
|
3687
3654
|
};
|
|
3688
3655
|
|
|
3689
|
-
// src/universal/types/offer-option-address.ts
|
|
3690
|
-
var OfferOptionAddressId = (value) => value;
|
|
3691
|
-
var OfferOptionAddress = {
|
|
3692
|
-
/** Maps the API DTO into the SDK offer-option-address domain model. */
|
|
3693
|
-
fromDto: (dto) => ({
|
|
3694
|
-
id: OfferOptionAddressId(dto.id),
|
|
3695
|
-
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
3696
|
-
address: EvmWalletAddress(dto.address),
|
|
3697
|
-
protocol: dto.protocol,
|
|
3698
|
-
createdAt: new Date(dto.created_at)
|
|
3699
|
-
})
|
|
3700
|
-
};
|
|
3701
|
-
var ConnectExternalWalletParams = {
|
|
3702
|
-
/** Maps connect-wallet params into the API DTO payload. */
|
|
3703
|
-
toDto: (params) => ({
|
|
3704
|
-
offer_option_id: params.offerOptionId,
|
|
3705
|
-
wallet_address: params.walletAddress,
|
|
3706
|
-
chain: params.chain,
|
|
3707
|
-
signature: params.signature
|
|
3708
|
-
})
|
|
3709
|
-
};
|
|
3710
|
-
|
|
3711
|
-
// src/universal/types/wallet-ownership-challenge.ts
|
|
3712
|
-
var WalletOwnershipChallenge = {
|
|
3713
|
-
/** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
|
|
3714
|
-
fromDto: (dto) => ({
|
|
3715
|
-
message: dto.message,
|
|
3716
|
-
expiresAt: new Date(dto.expires_at)
|
|
3717
|
-
})
|
|
3718
|
-
};
|
|
3719
|
-
var CreateWalletOwnershipChallengeParams = {
|
|
3720
|
-
/**
|
|
3721
|
-
* Maps challenge-request params into the API DTO payload. The discriminated
|
|
3722
|
-
* union guarantees SIWE fields are present exactly when `challengeType` is
|
|
3723
|
-
* `siwe`, so the mapping narrows on the discriminant.
|
|
3724
|
-
*/
|
|
3725
|
-
toDto: (params) => {
|
|
3726
|
-
switch (params.challengeType) {
|
|
3727
|
-
case "plain":
|
|
3728
|
-
return {
|
|
3729
|
-
wallet_address: params.walletAddress,
|
|
3730
|
-
chain: params.chain,
|
|
3731
|
-
challenge_type: "plain"
|
|
3732
|
-
};
|
|
3733
|
-
case "siwe":
|
|
3734
|
-
return {
|
|
3735
|
-
wallet_address: params.walletAddress,
|
|
3736
|
-
chain: params.chain,
|
|
3737
|
-
challenge_type: "siwe",
|
|
3738
|
-
domain: params.domain,
|
|
3739
|
-
uri: params.uri,
|
|
3740
|
-
statement: params.statement
|
|
3741
|
-
};
|
|
3742
|
-
default: {
|
|
3743
|
-
const _exhaustive = params;
|
|
3744
|
-
return _exhaustive;
|
|
3745
|
-
}
|
|
3746
|
-
}
|
|
3747
|
-
}
|
|
3748
|
-
};
|
|
3749
|
-
|
|
3750
|
-
// src/universal/api/frontline/wallet-connect.ts
|
|
3751
|
-
async function createWalletOwnershipChallenge(api, params) {
|
|
3752
|
-
const dto = await api.send({
|
|
3753
|
-
method: "POST",
|
|
3754
|
-
url: "/v1/wallet-ownership",
|
|
3755
|
-
body: CreateWalletOwnershipChallengeParams.toDto(params),
|
|
3756
|
-
attributes: Attributes.protected()
|
|
3757
|
-
});
|
|
3758
|
-
return WalletOwnershipChallenge.fromDto(dto);
|
|
3759
|
-
}
|
|
3760
|
-
async function connectExternalWallet(api, params) {
|
|
3761
|
-
const dto = await api.send({
|
|
3762
|
-
method: "POST",
|
|
3763
|
-
url: `/v1/offers/${params.offerId}/addresses`,
|
|
3764
|
-
body: ConnectExternalWalletParams.toDto(params),
|
|
3765
|
-
attributes: Attributes.protected()
|
|
3766
|
-
});
|
|
3767
|
-
return OfferOptionAddress.fromDto(dto);
|
|
3768
|
-
}
|
|
3769
|
-
async function listOptionAddresses(api, offerId, offerOptionId) {
|
|
3770
|
-
const { data } = await api.send({
|
|
3771
|
-
method: "GET",
|
|
3772
|
-
url: `/v1/offers/${offerId}/addresses`,
|
|
3773
|
-
queryParams: { offer_option_id: offerOptionId },
|
|
3774
|
-
attributes: Attributes.protected()
|
|
3775
|
-
});
|
|
3776
|
-
return data.map(OfferOptionAddress.fromDto);
|
|
3777
|
-
}
|
|
3778
|
-
async function removeOptionAddress(api, offerId, addressId) {
|
|
3779
|
-
const dto = await api.send({
|
|
3780
|
-
method: "DELETE",
|
|
3781
|
-
url: `/v1/offers/${offerId}/addresses/${addressId}`,
|
|
3782
|
-
attributes: Attributes.protected()
|
|
3783
|
-
});
|
|
3784
|
-
return OfferOptionAddress.fromDto(dto);
|
|
3785
|
-
}
|
|
3786
|
-
|
|
3787
|
-
// src/universal/core/wallets/wallets-namespace.ts
|
|
3788
|
-
var WalletsNamespaceImpl = class {
|
|
3789
|
-
constructor(ctx) {
|
|
3790
|
-
this.ctx = ctx;
|
|
3791
|
-
this.log = internalLogger(ctx.logger, "WALLETS");
|
|
3792
|
-
}
|
|
3793
|
-
async createOwnershipChallenge(params) {
|
|
3794
|
-
return this.log.wrap("createOwnershipChallenge", params, async () => {
|
|
3795
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3796
|
-
return createWalletOwnershipChallenge(
|
|
3797
|
-
this.ctx.api,
|
|
3798
|
-
params
|
|
3799
|
-
);
|
|
3800
|
-
});
|
|
3801
|
-
}
|
|
3802
|
-
async connectExternal(params) {
|
|
3803
|
-
return this.log.wrap("connectExternal", params, async () => {
|
|
3804
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3805
|
-
return connectExternalWallet(this.ctx.api, params);
|
|
3806
|
-
});
|
|
3807
|
-
}
|
|
3808
|
-
async list(params) {
|
|
3809
|
-
return this.log.wrap("list", params, async () => {
|
|
3810
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3811
|
-
return listOptionAddresses(
|
|
3812
|
-
this.ctx.api,
|
|
3813
|
-
params.offerId,
|
|
3814
|
-
params.offerOptionId
|
|
3815
|
-
);
|
|
3816
|
-
});
|
|
3817
|
-
}
|
|
3818
|
-
async remove(params) {
|
|
3819
|
-
return this.log.wrap("remove", params, async () => {
|
|
3820
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3821
|
-
return removeOptionAddress(
|
|
3822
|
-
this.ctx.api,
|
|
3823
|
-
params.offerId,
|
|
3824
|
-
params.addressId
|
|
3825
|
-
);
|
|
3826
|
-
});
|
|
3827
|
-
}
|
|
3828
|
-
};
|
|
3829
|
-
|
|
3830
|
-
// src/universal/types/oauth-session.ts
|
|
3831
|
-
var ClientCredentialsOAuth = (value) => value;
|
|
3832
|
-
var OAuthRefreshToken = (value) => value;
|
|
3833
|
-
var OAuthSession = {
|
|
3834
|
-
fromDto: (dto) => {
|
|
3835
|
-
const expiresAt = new Date(Date.now() + dto.expires_in * 1e3);
|
|
3836
|
-
return {
|
|
3837
|
-
accessToken: {
|
|
3838
|
-
value: dto.access_token,
|
|
3839
|
-
expiresAt
|
|
3840
|
-
},
|
|
3841
|
-
...dto.refresh_token != null && dto.refresh_token !== "" ? { refreshToken: OAuthRefreshToken(dto.refresh_token) } : void 0
|
|
3842
|
-
};
|
|
3843
|
-
}
|
|
3844
|
-
};
|
|
3845
|
-
|
|
3846
|
-
// src/universal/api/frontline/offers.ts
|
|
3847
|
-
async function fetchOffers(api, clientCreds) {
|
|
3848
|
-
return fetchAllPages((params) => fetchOffersPage(api, params, clientCreds));
|
|
3849
|
-
}
|
|
3850
|
-
async function fetchOffersPage(api, params, clientCreds) {
|
|
3851
|
-
const queryParams = PaginationParams.toQueryParams(params);
|
|
3852
|
-
const pageDto = await api.send({
|
|
3853
|
-
method: "GET",
|
|
3854
|
-
url: "/v1/offers",
|
|
3855
|
-
queryParams,
|
|
3856
|
-
attributes: Attributes.concat(
|
|
3857
|
-
Attributes.protected(),
|
|
3858
|
-
Attributes.clientCredentials(clientCreds)
|
|
3859
|
-
)
|
|
3860
|
-
});
|
|
3861
|
-
return PaginatedResponse.fromDtoPage(pageDto, Offer.listFromDto);
|
|
3862
|
-
}
|
|
3863
|
-
async function fetchOfferDetails(api, id, clientCreds) {
|
|
3864
|
-
const dto = await api.send({
|
|
3865
|
-
method: "GET",
|
|
3866
|
-
url: `/v1/offers/${id}`,
|
|
3867
|
-
attributes: Attributes.concat(
|
|
3868
|
-
Attributes.protected(),
|
|
3869
|
-
Attributes.clientCredentials(clientCreds)
|
|
3870
|
-
)
|
|
3871
|
-
});
|
|
3872
|
-
return OfferDetail.fromDto(dto);
|
|
3873
|
-
}
|
|
3874
|
-
|
|
3875
3656
|
export {
|
|
3876
3657
|
sha256,
|
|
3877
3658
|
arrayBufferToBase64Url,
|
|
3878
3659
|
generateSecureRandomBase64Url,
|
|
3879
3660
|
getUUIDv4,
|
|
3880
|
-
PUBLIC_API_BASE_URL,
|
|
3881
|
-
HEADER_USER_AGENT,
|
|
3882
|
-
HEADER_IDEMPOTENCY_KEY,
|
|
3883
|
-
API_VERSION,
|
|
3884
|
-
COINLIST_BASE_URL,
|
|
3885
|
-
OAUTH_PAGE_PATH,
|
|
3886
|
-
SUPPORT_NEW_TICKET_URL,
|
|
3887
|
-
VERIFY_IDENTITY_PATH,
|
|
3888
|
-
VERIFY_IDENTITY_ACCREDITATION_PATH,
|
|
3889
|
-
WALLET_PATH,
|
|
3890
3661
|
SentWith,
|
|
3891
3662
|
TokenTrigger,
|
|
3892
3663
|
isRejectedToken,
|
|
3893
3664
|
Attributes,
|
|
3894
3665
|
HttpError,
|
|
3895
3666
|
apiErrorCode,
|
|
3896
|
-
Request,
|
|
3897
3667
|
NotImplementedError,
|
|
3898
3668
|
NotAuthenticatedError,
|
|
3899
3669
|
ValidationError,
|
|
3900
3670
|
InvariantError,
|
|
3901
3671
|
MathError,
|
|
3672
|
+
classifyLogCause,
|
|
3902
3673
|
describeErrorUnredacted,
|
|
3903
3674
|
internalLogger,
|
|
3904
|
-
HttpClient,
|
|
3905
3675
|
EpochMillis,
|
|
3906
3676
|
Millis,
|
|
3907
3677
|
Seconds,
|
|
3908
3678
|
isExpired,
|
|
3909
3679
|
ERC20_ABI,
|
|
3680
|
+
FormattedAmountUi,
|
|
3681
|
+
FormattedPercentUi,
|
|
3682
|
+
TxExplorerUrl,
|
|
3683
|
+
ShortenedWalletAddress,
|
|
3684
|
+
FormattedAmountAssetUi,
|
|
3685
|
+
AssetIconUrl,
|
|
3686
|
+
viemChain,
|
|
3687
|
+
getChainId,
|
|
3688
|
+
chainFromId,
|
|
3689
|
+
contractOn,
|
|
3690
|
+
getNetworkName,
|
|
3691
|
+
txExplorerUrl,
|
|
3910
3692
|
ETHEREUM_CHAINS,
|
|
3911
3693
|
EthereumChain,
|
|
3912
3694
|
SOLANA_CHAINS,
|
|
@@ -3929,18 +3711,30 @@ export {
|
|
|
3929
3711
|
KnownAssetSymbol,
|
|
3930
3712
|
Bps,
|
|
3931
3713
|
blockchainAmountFromRawOrThrow,
|
|
3714
|
+
positiveAmountFromRawOrThrow,
|
|
3715
|
+
pricePerShare,
|
|
3932
3716
|
parseBlockchainAmount,
|
|
3933
|
-
CentrifugeVaultQuote,
|
|
3934
3717
|
CentrifugeVaultStatus,
|
|
3935
3718
|
CentrifugeVaultBuyTransaction,
|
|
3936
3719
|
CentrifugeVaultClaimTransaction,
|
|
3937
|
-
|
|
3938
|
-
|
|
3720
|
+
CentrifugeAssets,
|
|
3721
|
+
CentrifugeShares,
|
|
3722
|
+
CentrifugeDepositPosition,
|
|
3723
|
+
CentrifugeRedeemPosition,
|
|
3939
3724
|
CentrifugeVaultLeg,
|
|
3940
3725
|
CentrifugeVaultLegId,
|
|
3941
3726
|
CentrifugeVaultClaimProceedsTransaction,
|
|
3942
3727
|
CentrifugeNamespaceImpl,
|
|
3943
|
-
|
|
3728
|
+
shortenAddress,
|
|
3729
|
+
formatAmount,
|
|
3730
|
+
formatRawAmount,
|
|
3731
|
+
formatCompactAmount,
|
|
3732
|
+
formatBpsAsPercent,
|
|
3733
|
+
usdAmount,
|
|
3734
|
+
assetAmount,
|
|
3735
|
+
NA_AMOUNT_ASSET_UI,
|
|
3736
|
+
formatShareAmount,
|
|
3737
|
+
formattedUsdPrice,
|
|
3944
3738
|
Cursor,
|
|
3945
3739
|
PaginatedResponse,
|
|
3946
3740
|
PaginationParams,
|
|
@@ -3960,6 +3754,7 @@ export {
|
|
|
3960
3754
|
OfferOptionSlug,
|
|
3961
3755
|
OfferSwapContract,
|
|
3962
3756
|
OfferVaultContract,
|
|
3757
|
+
OfferFundingContract,
|
|
3963
3758
|
OfferDetail,
|
|
3964
3759
|
OfferOption,
|
|
3965
3760
|
FaqItem,
|
|
@@ -3967,33 +3762,10 @@ export {
|
|
|
3967
3762
|
TermItem,
|
|
3968
3763
|
Milestone,
|
|
3969
3764
|
ParticipationId,
|
|
3970
|
-
Blockchain,
|
|
3971
|
-
WalletAddress,
|
|
3972
3765
|
ParticipationsPaginationParams,
|
|
3973
3766
|
Participation,
|
|
3974
3767
|
CreateParticipationParams,
|
|
3975
3768
|
CoinListTokenSaleNamespaceImpl,
|
|
3976
|
-
FormattedAmountUi,
|
|
3977
|
-
FormattedPercentUi,
|
|
3978
|
-
TxExplorerUrl,
|
|
3979
|
-
ShortenedWalletAddress,
|
|
3980
|
-
FormattedAmountAssetUi,
|
|
3981
|
-
AssetIconUrl,
|
|
3982
|
-
shortenAddress,
|
|
3983
|
-
formatAmount,
|
|
3984
|
-
formatRawAmount,
|
|
3985
|
-
formatCompactAmount,
|
|
3986
|
-
formatBpsAsPercent,
|
|
3987
|
-
usdAmount,
|
|
3988
|
-
assetAmount,
|
|
3989
|
-
NA_AMOUNT_ASSET_UI,
|
|
3990
|
-
formatShareAmount,
|
|
3991
|
-
formattedUsdPrice,
|
|
3992
|
-
viemChain,
|
|
3993
|
-
getChainId,
|
|
3994
|
-
chainFromId,
|
|
3995
|
-
getNetworkName,
|
|
3996
|
-
txExplorerUrl,
|
|
3997
3769
|
OndoTradingStatus,
|
|
3998
3770
|
OndoQuote,
|
|
3999
3771
|
OndoBuyTransaction,
|
|
@@ -4004,10 +3776,8 @@ export {
|
|
|
4004
3776
|
PauseFlags,
|
|
4005
3777
|
SwapStatus,
|
|
4006
3778
|
AllowWalletResponse,
|
|
3779
|
+
SwapQuote,
|
|
4007
3780
|
SuperstateSwapNamespaceImpl,
|
|
4008
|
-
fetchOffers,
|
|
4009
|
-
fetchOffersPage,
|
|
4010
|
-
fetchOfferDetails,
|
|
4011
3781
|
DocumentSubmission,
|
|
4012
3782
|
KycToken,
|
|
4013
3783
|
Iso2CountryCode,
|
|
@@ -4019,19 +3789,20 @@ export {
|
|
|
4019
3789
|
RequirementStatusInfo,
|
|
4020
3790
|
fetchOfferRequirements,
|
|
4021
3791
|
RequirementsNamespaceImpl,
|
|
4022
|
-
Erc20NamespaceImpl,
|
|
4023
|
-
TokenLogoUrl,
|
|
4024
|
-
TokenLogo,
|
|
4025
|
-
TokenMetadata,
|
|
4026
|
-
TokensNamespaceImpl,
|
|
4027
3792
|
OfferOptionAddressId,
|
|
4028
3793
|
OfferOptionAddress,
|
|
4029
3794
|
ConnectExternalWalletParams,
|
|
4030
3795
|
WalletOwnershipChallenge,
|
|
4031
3796
|
CreateWalletOwnershipChallengeParams,
|
|
4032
3797
|
WalletsNamespaceImpl,
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
3798
|
+
fetchOffers,
|
|
3799
|
+
fetchOffersPage,
|
|
3800
|
+
fetchOfferDetails,
|
|
3801
|
+
OffersNamespaceImpl,
|
|
3802
|
+
Erc20NamespaceImpl,
|
|
3803
|
+
TokenLogoUrl,
|
|
3804
|
+
TokenLogo,
|
|
3805
|
+
TokenMetadata,
|
|
3806
|
+
TokensNamespaceImpl
|
|
4036
3807
|
};
|
|
4037
|
-
//# sourceMappingURL=chunk-
|
|
3808
|
+
//# sourceMappingURL=chunk-2FZAXGVH.js.map
|