@upshiftfinance/sdk 0.3.0 → 0.5.0
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 +6 -2
- package/esm/index.d.mts +15 -0
- package/esm/index.mjs +18 -0
- package/lib/abis/KycRegistry.d.ts +109 -0
- package/lib/abis/KycRegistry.js +73 -0
- package/lib/abis/index.d.ts +1 -0
- package/lib/abis/index.js +1 -0
- package/lib/adapters/sui/actions.d.ts +420 -0
- package/lib/adapters/sui/actions.js +701 -0
- package/lib/adapters/sui/client.d.ts +3 -3
- package/lib/adapters/sui/client.js +27 -9
- package/lib/adapters/sui/getters.d.ts +268 -0
- package/lib/adapters/sui/getters.js +669 -0
- package/lib/adapters/sui/index.d.ts +243 -3
- package/lib/adapters/sui/index.js +250 -3
- package/lib/adapters/sui/targets.d.ts +42 -1
- package/lib/adapters/sui/targets.js +42 -1
- package/lib/core/analytics/method-taxonomy.d.ts +1 -1
- package/lib/core/analytics/method-taxonomy.js +9 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/constants/core.d.ts +5 -0
- package/lib/core/constants/core.js +5 -0
- package/lib/core/constants/kyc.d.ts +9 -0
- package/lib/core/constants/kyc.js +12 -0
- package/lib/core/constants/web3.d.ts +2 -2
- package/lib/core/constants/web3.js +9 -2
- package/lib/core/errors/index.d.ts +90 -1
- package/lib/core/errors/index.js +94 -1
- package/lib/core/fetcher.d.ts +5 -0
- package/lib/core/fetcher.js +1 -1
- package/lib/core/helpers/chain-support.d.ts +2 -2
- package/lib/core/helpers/chain-support.js +3 -3
- package/lib/core/helpers/kyc.d.ts +47 -0
- package/lib/core/helpers/kyc.js +111 -0
- package/lib/core/helpers/revert-decode.js +3 -2
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +2 -0
- package/lib/evm/methods/crossChainVault.js +25 -43
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/main.d.ts +33 -3
- package/lib/main.js +32 -0
- package/lib/modules/api/kyc.d.ts +4 -0
- package/lib/modules/api/kyc.js +148 -0
- package/lib/modules/api/main.d.ts +63 -1
- package/lib/modules/api/main.js +64 -0
- package/lib/modules/vaults/getters.d.ts +3 -1
- package/lib/modules/vaults/getters.js +82 -10
- package/lib/modules/vaults/main.d.ts +41 -3
- package/lib/modules/vaults/main.js +82 -6
- package/lib/modules/vaults/types.d.ts +7 -1
- package/lib/modules/vaults/utils.js +4 -1
- package/lib/sdk.d.ts +16363 -14615
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/kyc.d.ts +61 -0
- package/lib/types/kyc.js +3 -0
- package/lib/types/vaults.d.ts +2 -0
- package/lib/types/webserver.d.ts +5 -0
- package/package.json +21 -2
|
@@ -8,39 +8,6 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module evm/methods/crossChainVault
|
|
10
10
|
*/
|
|
11
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
-
}
|
|
17
|
-
Object.defineProperty(o, k2, desc);
|
|
18
|
-
}) : (function(o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
}));
|
|
22
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
-
}) : function(o, v) {
|
|
25
|
-
o["default"] = v;
|
|
26
|
-
});
|
|
27
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
-
var ownKeys = function(o) {
|
|
29
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
-
var ar = [];
|
|
31
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
-
return ar;
|
|
33
|
-
};
|
|
34
|
-
return ownKeys(o);
|
|
35
|
-
};
|
|
36
|
-
return function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
})();
|
|
44
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
12
|
exports.LAYERZERO_ENDPOINT_IDS = void 0;
|
|
46
13
|
exports.buildCrossChainVaultTx = buildCrossChainVaultTx;
|
|
@@ -59,6 +26,7 @@ exports.getAvailableChains = getAvailableChains;
|
|
|
59
26
|
exports.formatCrossChainError = formatCrossChainError;
|
|
60
27
|
exports.getLayerZeroScanUrl = getLayerZeroScanUrl;
|
|
61
28
|
const attribution_1 = require("../../core/attribution");
|
|
29
|
+
const ethers_1 = require("ethers");
|
|
62
30
|
const core_1 = require("../../core");
|
|
63
31
|
const crossChain_1 = require("../types/crossChain");
|
|
64
32
|
const OFT_1 = require("../../abis/OFT");
|
|
@@ -369,19 +337,33 @@ async function buildCrossChainVaultTx(props) {
|
|
|
369
337
|
const hubRpc = hubChain?.rpcUrls;
|
|
370
338
|
const hubRpcUrl = hubRpc?.default?.http?.[0];
|
|
371
339
|
let hubPublicClient;
|
|
372
|
-
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
340
|
+
if (hubRpcUrl) {
|
|
341
|
+
// Hub reads (multi-asset previews) go through ethers, which is a hard
|
|
342
|
+
// dependency. This used to dynamically import the optional `viem` peer, which tsc
|
|
343
|
+
// compiles to a literal CJS require that bundlers resolve at build time
|
|
344
|
+
// and fail on when `viem` is not installed.
|
|
345
|
+
// `createProvider` is cached per (url, chainId) and uses a static
|
|
346
|
+
// network, so each readContract costs exactly one `eth_call`.
|
|
347
|
+
const hubChainId = hubChain?.id;
|
|
348
|
+
const provider = (0, core_1.createProvider)(hubRpcUrl, hubChainId);
|
|
349
|
+
hubPublicClient = {
|
|
350
|
+
readContract: async (args) => {
|
|
351
|
+
const { address, abi, functionName, args: callArgs = [], } = args;
|
|
352
|
+
const result = await new ethers_1.Contract(address, abi, provider)
|
|
353
|
+
.getFunction(functionName)
|
|
354
|
+
.staticCallResult(...callArgs);
|
|
355
|
+
// Match viem's readContract shape: a single output is returned
|
|
356
|
+
// bare; multiple outputs as a positional array.
|
|
357
|
+
return result.length === 1 ? result[0] : result.toArray();
|
|
358
|
+
},
|
|
359
|
+
};
|
|
379
360
|
}
|
|
380
|
-
|
|
381
|
-
//
|
|
361
|
+
else {
|
|
362
|
+
// No hub RPC on the chain object: only multi-asset paths read the hub,
|
|
363
|
+
// so fail those (redeem previews fall back to 1:1, as before).
|
|
382
364
|
hubPublicClient = {
|
|
383
365
|
readContract: async () => {
|
|
384
|
-
throw new
|
|
366
|
+
throw new core_1.UpshiftValidationError('INVALID_INPUT', 'hubChain.rpcUrls.default.http[0] is required for multi-asset vault operations.');
|
|
385
367
|
},
|
|
386
368
|
};
|
|
387
369
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export * from './adapters/solana';
|
|
|
22
22
|
* Stellar export
|
|
23
23
|
*/
|
|
24
24
|
export * from './adapters/stellar';
|
|
25
|
+
/**
|
|
26
|
+
* Sui export
|
|
27
|
+
*/
|
|
28
|
+
export * from './adapters/sui';
|
|
25
29
|
export declare const VAULT_ADDRESSES: Record<"musd" | "predlp" | "sentusd" | "pregrid" | "repouscc" | "earnxrp" | "tivkbtc" | "tivusdt0" | "supermon" | "earnmon" | "k3europ" | "wmon/ausd" | "wbtc/ausd" | "earnausd_monad" | "sausd" | "farmbold" | "sentuscc" | "sentbtc" | "svusdc" | "apusdc" | "testwethtsa" | "tacusr" | "upinjusdt" | "tac-teth" | "upausd" | "taccbbtc" | "xupusdc" | "uptbtc" | "gteth" | "ageth" | "upusdc" | "hgeth" | "upssylva" | "hbbtc" | "hbhype" | "upazt" | "susdt" | "upedge" | "coreusdc" | "upcusdo" | "shifteth" | "upsusde" | "uplbtc" | "upavax" | "tacrseth" | "earnausd" | "alpineusdcflagship" | "alpinecoinshiftusdc" | "upbtc" | "upstrbtc" | "maxiusr" | "upgammausdc" | "xhype" | "wildusd" | "alpinebtc" | "prenusd" | "upyzusd" | "upnusd" | "hlpe" | "nemo eth yield", `0x${string}`>;
|
|
26
30
|
/**
|
|
27
31
|
* Export the SDK class as default
|
package/lib/index.js
CHANGED
package/lib/main.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import SolanaAdapter from './adapters/solana';
|
|
|
7
7
|
import SuiAdapter from './adapters/sui';
|
|
8
8
|
import StellarAdapter from './adapters/stellar';
|
|
9
9
|
import EVMAdapter from './adapters/evm';
|
|
10
|
-
import type { IAddress, IChainId, IVaultHistoricalParams } from './types';
|
|
10
|
+
import type { IAddress, IChainId, IKycRecord, IKycStatus, IKycWalletOptions, IVaultHistoricalParams } from './types';
|
|
11
11
|
import { UpshiftBase, type IUpshiftBase } from './core';
|
|
12
12
|
import { UpshiftVaults, type IGetVaultsOptions, type IVaultBaseOptions, type IVaultCustomOptions } from './modules/vaults';
|
|
13
13
|
import type { Signer, Wallet } from 'ethers';
|
|
@@ -266,8 +266,10 @@ export declare class UpshiftSDK extends UpshiftBase {
|
|
|
266
266
|
solanaWallet?: string;
|
|
267
267
|
stellarWallet?: string;
|
|
268
268
|
/**
|
|
269
|
-
* Sui wallet address (`0x` + 64 hex chars).
|
|
270
|
-
*
|
|
269
|
+
* Sui wallet address (`0x` + 64 hex chars). Its share balance and its
|
|
270
|
+
* pending withdrawal requests (as redemptions) are read for each Sui vault:
|
|
271
|
+
* one balance read plus, when the SDK has the contract IDs, one object read
|
|
272
|
+
* (one more per further 25 requests the wallet has made on the vault).
|
|
271
273
|
*/
|
|
272
274
|
suiWallet?: string;
|
|
273
275
|
options?: IVaultBaseOptions;
|
|
@@ -388,6 +390,34 @@ export declare class UpshiftSDK extends UpshiftBase {
|
|
|
388
390
|
chainId: number;
|
|
389
391
|
originCode: `0x${string}`;
|
|
390
392
|
}): Promise<import("./types").IOriginInfo>;
|
|
393
|
+
/**
|
|
394
|
+
* Read a wallet's status in `chainId`'s `KycRegistry`. Delegates to
|
|
395
|
+
* {@link UpshiftVaults.getKycStatus}.
|
|
396
|
+
* @param options - `chainId` and `wallet`.
|
|
397
|
+
* @returns `'none' | 'active' | 'expired' | 'blocked'`.
|
|
398
|
+
* @throws UpshiftValidationError when no provider is configured or no
|
|
399
|
+
* registry is deployed for `chainId`, or `wallet` is malformed.
|
|
400
|
+
* @throws UpshiftSDKError when the read fails.
|
|
401
|
+
* @example
|
|
402
|
+
* ```ts
|
|
403
|
+
* const status = await upshiftSdk.getKycStatus({ chainId: 1, wallet });
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
getKycStatus(options: Omit<IKycWalletOptions, 'rpcUrl'>): Promise<IKycStatus>;
|
|
407
|
+
/**
|
|
408
|
+
* Read a wallet's raw `KycRegistry` record (blocked flag and Unix-second
|
|
409
|
+
* timestamps). Delegates to {@link UpshiftVaults.getKycRecord}.
|
|
410
|
+
* @param options - `chainId` and `wallet`.
|
|
411
|
+
* @returns {@link IKycRecord}.
|
|
412
|
+
* @throws UpshiftValidationError when no provider is configured or no
|
|
413
|
+
* registry is deployed for `chainId`, or `wallet` is malformed.
|
|
414
|
+
* @throws UpshiftSDKError when the read fails.
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* const { expiresAt } = await upshiftSdk.getKycRecord({ chainId: 1, wallet });
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
getKycRecord(options: Omit<IKycWalletOptions, 'rpcUrl'>): Promise<IKycRecord>;
|
|
391
421
|
/**
|
|
392
422
|
* Get lifetime PnL for a user in a specific vault.
|
|
393
423
|
* Calculates realized and unrealized PnL based on deposit/withdrawal history and current position.
|
package/lib/main.js
CHANGED
|
@@ -463,6 +463,38 @@ class UpshiftSDK extends core_1.UpshiftBase {
|
|
|
463
463
|
async getOriginInfo(options) {
|
|
464
464
|
return await this.vaults.getOriginInfo(options);
|
|
465
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Read a wallet's status in `chainId`'s `KycRegistry`. Delegates to
|
|
468
|
+
* {@link UpshiftVaults.getKycStatus}.
|
|
469
|
+
* @param options - `chainId` and `wallet`.
|
|
470
|
+
* @returns `'none' | 'active' | 'expired' | 'blocked'`.
|
|
471
|
+
* @throws UpshiftValidationError when no provider is configured or no
|
|
472
|
+
* registry is deployed for `chainId`, or `wallet` is malformed.
|
|
473
|
+
* @throws UpshiftSDKError when the read fails.
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* const status = await upshiftSdk.getKycStatus({ chainId: 1, wallet });
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
async getKycStatus(options) {
|
|
480
|
+
return await this.vaults.getKycStatus(options);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Read a wallet's raw `KycRegistry` record (blocked flag and Unix-second
|
|
484
|
+
* timestamps). Delegates to {@link UpshiftVaults.getKycRecord}.
|
|
485
|
+
* @param options - `chainId` and `wallet`.
|
|
486
|
+
* @returns {@link IKycRecord}.
|
|
487
|
+
* @throws UpshiftValidationError when no provider is configured or no
|
|
488
|
+
* registry is deployed for `chainId`, or `wallet` is malformed.
|
|
489
|
+
* @throws UpshiftSDKError when the read fails.
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* const { expiresAt } = await upshiftSdk.getKycRecord({ chainId: 1, wallet });
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
async getKycRecord(options) {
|
|
496
|
+
return await this.vaults.getKycRecord(options);
|
|
497
|
+
}
|
|
466
498
|
/**
|
|
467
499
|
* Get lifetime PnL for a user in a specific vault.
|
|
468
500
|
* Calculates realized and unrealized PnL based on deposit/withdrawal history and current position.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IAddress, ICreateKycSessionOptions, IKycChallenge, IKycSession } from '../../types';
|
|
2
|
+
export declare function fetchKycChallenge(wallet: IAddress, chainId: number): Promise<IKycChallenge>;
|
|
3
|
+
export declare function postKycSession(options: ICreateKycSessionOptions): Promise<IKycSession>;
|
|
4
|
+
export declare function postKycSessionRefresh(sessionToken: string): Promise<string>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchKycChallenge = fetchKycChallenge;
|
|
4
|
+
exports.postKycSession = postKycSession;
|
|
5
|
+
exports.postKycSessionRefresh = postKycSessionRefresh;
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const core_1 = require("../../core/constants/core");
|
|
8
|
+
const errors_1 = require("../../core/errors");
|
|
9
|
+
const fetcher_1 = require("../../core/fetcher");
|
|
10
|
+
const REASONS = {
|
|
11
|
+
'challenge expired': 'challenge_expired',
|
|
12
|
+
'unknown or used challenge': 'challenge_used',
|
|
13
|
+
'invalid signature': 'invalid_signature',
|
|
14
|
+
'unknown or expired session': 'session_expired',
|
|
15
|
+
'session no longer valid': 'session_expired',
|
|
16
|
+
'identity blocked': 'identity_blocked',
|
|
17
|
+
'wallet is bound to another identity': 'wallet_bound',
|
|
18
|
+
'wallet limit reached for this identity': 'wallet_limit',
|
|
19
|
+
'wallet control was proven on another chain; verify again from there': 'other_chain',
|
|
20
|
+
'wallet is verified through another provider': 'other_provider',
|
|
21
|
+
'wallet is not verified for this chain': 'not_verified_for_chain',
|
|
22
|
+
'enrolment already in progress; retry shortly': 'enrolment_in_progress',
|
|
23
|
+
'a registry write for this wallet is in progress; retry shortly': 'registry_write_in_progress',
|
|
24
|
+
'enrolment timed out; retry shortly': 'enrolment_timed_out',
|
|
25
|
+
'chain has no kyc registry': 'no_registry',
|
|
26
|
+
'too many requests': 'rate_limited',
|
|
27
|
+
};
|
|
28
|
+
const IDENTITY_STATUSES = [
|
|
29
|
+
'pending',
|
|
30
|
+
'approved',
|
|
31
|
+
'rejected_retry',
|
|
32
|
+
'rejected_final',
|
|
33
|
+
'revoked',
|
|
34
|
+
'blocked',
|
|
35
|
+
];
|
|
36
|
+
function readDetail(body) {
|
|
37
|
+
const detail = body?.detail;
|
|
38
|
+
if (typeof detail === 'string')
|
|
39
|
+
return detail;
|
|
40
|
+
if (!Array.isArray(detail))
|
|
41
|
+
return '';
|
|
42
|
+
return detail
|
|
43
|
+
.map((d) => d?.msg)
|
|
44
|
+
.filter((m) => typeof m === 'string')
|
|
45
|
+
.join('; ');
|
|
46
|
+
}
|
|
47
|
+
function reasonFor(status, detail) {
|
|
48
|
+
const known = REASONS[detail.toLowerCase()];
|
|
49
|
+
if (known)
|
|
50
|
+
return known;
|
|
51
|
+
if (/has no KYC registry/i.test(detail))
|
|
52
|
+
return 'no_registry';
|
|
53
|
+
if (status === 429)
|
|
54
|
+
return 'rate_limited';
|
|
55
|
+
if (status >= 500)
|
|
56
|
+
return 'unavailable';
|
|
57
|
+
if (status === 422)
|
|
58
|
+
return 'invalid_request';
|
|
59
|
+
return 'unknown';
|
|
60
|
+
}
|
|
61
|
+
async function kycRequest(method, path, data) {
|
|
62
|
+
const res = await (0, fetcher_1.fetchUpshiftPublic)(path, {
|
|
63
|
+
method: data === undefined ? 'get' : 'post',
|
|
64
|
+
data,
|
|
65
|
+
returnErrorResponse: true,
|
|
66
|
+
});
|
|
67
|
+
const body = await res.json().catch(() => null);
|
|
68
|
+
if (res.ok) {
|
|
69
|
+
if (body && typeof body === 'object')
|
|
70
|
+
return body;
|
|
71
|
+
throw new errors_1.UpshiftServerError(res.status, `${method}: empty response body`);
|
|
72
|
+
}
|
|
73
|
+
const detail = readDetail(body);
|
|
74
|
+
const retryAfter = Number(res.headers.get('retry-after'));
|
|
75
|
+
throw new errors_1.UpshiftKycError(res.status, detail, reasonFor(res.status, detail), {
|
|
76
|
+
correlationId: res.headers.get('x-correlation-id') ?? undefined,
|
|
77
|
+
context: { method, status: res.status },
|
|
78
|
+
retryAfterMs: retryAfter > 0 ? retryAfter * 1000 : undefined,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function assertWalletAndChain(method, wallet, chainId) {
|
|
82
|
+
if (!(0, ethers_1.isAddress)(wallet)) {
|
|
83
|
+
throw new errors_1.UpshiftValidationError('INVALID_ADDRESS', `${method}: wallet is not a valid EVM address`);
|
|
84
|
+
}
|
|
85
|
+
if (!Number.isInteger(chainId) || chainId < 1) {
|
|
86
|
+
throw new errors_1.UpshiftValidationError('INVALID_CHAIN', `${method}: chainId must be a positive integer, got ${chainId}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function field(method, body, key, check) {
|
|
90
|
+
const value = body[key];
|
|
91
|
+
if (!check(value)) {
|
|
92
|
+
throw new errors_1.UpshiftServerError(200, `${method}: response field ${key} is malformed`);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
const isString = (v) => typeof v === 'string' && v.length > 0;
|
|
97
|
+
const isInteger = (v) => Number.isInteger(v);
|
|
98
|
+
const isIdentityStatus = (v) => IDENTITY_STATUSES.includes(v);
|
|
99
|
+
async function fetchKycChallenge(wallet, chainId) {
|
|
100
|
+
const method = 'getKycChallenge';
|
|
101
|
+
assertWalletAndChain(method, wallet, chainId);
|
|
102
|
+
const body = await kycRequest(method, core_1.WEBSERVER_ENDPOINTS.public.kyc.challenge(wallet, chainId));
|
|
103
|
+
return {
|
|
104
|
+
wallet: field(method, body, 'wallet', isString),
|
|
105
|
+
chainId: field(method, body, 'chain_id', isInteger),
|
|
106
|
+
nonce: field(method, body, 'nonce', isString),
|
|
107
|
+
issuedAt: field(method, body, 'issued_at', isInteger),
|
|
108
|
+
expiry: field(method, body, 'expiry', isInteger),
|
|
109
|
+
message: field(method, body, 'message', isString),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function postKycSession(options) {
|
|
113
|
+
const method = 'createKycSession';
|
|
114
|
+
const { wallet, chainId, nonce, issuedAt, expiry, signature } = options;
|
|
115
|
+
assertWalletAndChain(method, wallet, chainId);
|
|
116
|
+
if (!/^0x[0-9a-fA-F]+$/.test(signature)) {
|
|
117
|
+
throw new errors_1.UpshiftValidationError('INVALID_INPUT', `${method}: signature must be 0x-prefixed hex`);
|
|
118
|
+
}
|
|
119
|
+
if (!isString(nonce) || !isInteger(issuedAt) || !isInteger(expiry)) {
|
|
120
|
+
throw new errors_1.UpshiftValidationError('INVALID_INPUT', `${method}: nonce, issuedAt and expiry must come from getKycChallenge`);
|
|
121
|
+
}
|
|
122
|
+
const body = await kycRequest(method, core_1.WEBSERVER_ENDPOINTS.public.kyc.session, {
|
|
123
|
+
wallet,
|
|
124
|
+
chain_id: chainId,
|
|
125
|
+
nonce,
|
|
126
|
+
issued_at: issuedAt,
|
|
127
|
+
expiry,
|
|
128
|
+
signature,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
accessToken: field(method, body, 'access_token', isString),
|
|
132
|
+
sessionToken: field(method, body, 'session_token', isString),
|
|
133
|
+
externalUserId: field(method, body, 'external_user_id', isString),
|
|
134
|
+
levelName: field(method, body, 'level_name', isString),
|
|
135
|
+
identityStatus: field(method, body, 'identity_status', isIdentityStatus),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
async function postKycSessionRefresh(sessionToken) {
|
|
139
|
+
const method = 'refreshKycSession';
|
|
140
|
+
if (typeof sessionToken !== 'string' ||
|
|
141
|
+
sessionToken.length < 16 ||
|
|
142
|
+
sessionToken.length > 128) {
|
|
143
|
+
throw new errors_1.UpshiftValidationError('INVALID_INPUT', `${method}: sessionToken must come from createKycSession`);
|
|
144
|
+
}
|
|
145
|
+
const body = await kycRequest(method, core_1.WEBSERVER_ENDPOINTS.public.kyc.sessionRefresh, { session_token: sessionToken });
|
|
146
|
+
return field(method, body, 'access_token', isString);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=kyc.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UpshiftBase, type IUpshiftBase } from '../../core/base.class';
|
|
2
|
-
import type { ICollateralExcessOrDeficit, ICollateralSimulationInput, ICollateralSimulationResults, ICuratorWhitelistStatus, IDiscountFactorLadder, ILoanBookInfo, IOracleClassification, IOtcMarginRequirement, IOtcPositionRead, IRevertReason, ITimelockRequest, ITransparencyApySeries, ITransparencyAuditCategory, ITransparencyAuditLog, ITransparencyFees, ITransparencyGovernancePermissions, ITransparencyGovernanceRoles, ITransparencyHistoricalAllocations, ITransparencyPositions, ITransparencyRatioPoint, ITransparencyTimelocks, ITransparencyTimelockStatus, IUnrealizedPnlSnapshot, IVaultPerformanceFees, IWSSubaccountListItem } from '../../types';
|
|
2
|
+
import type { IAddress, ICollateralExcessOrDeficit, ICollateralSimulationInput, ICollateralSimulationResults, ICreateKycSessionOptions, ICuratorWhitelistStatus, IDiscountFactorLadder, IKycChallenge, IKycSession, ILoanBookInfo, IOracleClassification, IOtcMarginRequirement, IOtcPositionRead, IRevertReason, ITimelockRequest, ITransparencyApySeries, ITransparencyAuditCategory, ITransparencyAuditLog, ITransparencyFees, ITransparencyGovernancePermissions, ITransparencyGovernanceRoles, ITransparencyHistoricalAllocations, ITransparencyPositions, ITransparencyRatioPoint, ITransparencyTimelocks, ITransparencyTimelockStatus, IUnrealizedPnlSnapshot, IVaultPerformanceFees, IWSSubaccountListItem } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Read-only client for Upshift backend REST endpoints that have no on-chain
|
|
5
5
|
* equivalent: the unrealized-PnL series, the transparency dashboard
|
|
@@ -584,4 +584,66 @@ export declare class UpshiftApi extends UpshiftBase {
|
|
|
584
584
|
* const losing = all.filter((s) => s.unrealizedPnl < 0);
|
|
585
585
|
*/
|
|
586
586
|
getLatestUnrealizedPnl(): Promise<IUnrealizedPnlSnapshot[]>;
|
|
587
|
+
/**
|
|
588
|
+
* Fetch a one-time SIWE challenge that proves the wallet is the user's
|
|
589
|
+
* before KYC starts (`GET /kyc/challenge`).
|
|
590
|
+
*
|
|
591
|
+
* Makes one HTTPS request to the public Upshift API; no RPC calls. Never
|
|
592
|
+
* cached: the nonce is single use and expires after 600 s.
|
|
593
|
+
*
|
|
594
|
+
* @param params - `wallet`, the EVM wallet that will sign `message`, and
|
|
595
|
+
* `chainId`, the EVM chain whose `KycRegistry` the session activates.
|
|
596
|
+
* @returns {@link IKycChallenge}. Sign `message` verbatim with `personal_sign`.
|
|
597
|
+
* @throws UpshiftValidationError When `wallet` or `chainId` is malformed.
|
|
598
|
+
* @throws UpshiftKycError When the backend answers non-2xx: `no_registry` (400) or `unavailable` (503).
|
|
599
|
+
* @throws UpshiftServerError When the response body is malformed.
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* const challenge = await sdk.apiModule.getKycChallenge({ wallet, chainId: 1 });
|
|
603
|
+
* const signature = await walletClient.signMessage({ message: challenge.message });
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
getKycChallenge(params: {
|
|
607
|
+
wallet: IAddress;
|
|
608
|
+
chainId: number;
|
|
609
|
+
}): Promise<IKycChallenge>;
|
|
610
|
+
/**
|
|
611
|
+
* Open a KYC session with a signed challenge (`POST /kyc/session`). The
|
|
612
|
+
* first call creates the user's Sumsub applicant; later calls resume it.
|
|
613
|
+
* Every call activates the identity on `chainId`.
|
|
614
|
+
*
|
|
615
|
+
* Makes one HTTPS request and never retries: the nonce is single use. On
|
|
616
|
+
* any failure, fetch a new challenge before trying again.
|
|
617
|
+
*
|
|
618
|
+
* @param options - The challenge fields exactly as returned, plus `signature`.
|
|
619
|
+
* @returns {@link IKycSession} with the Sumsub WebSDK `accessToken`.
|
|
620
|
+
* @throws UpshiftValidationError When an input is malformed.
|
|
621
|
+
* @throws UpshiftKycError When the backend answers non-2xx. `reason` names the
|
|
622
|
+
* case; `retryable` is true for the in-progress and timed-out answers.
|
|
623
|
+
* @throws UpshiftServerError When the response body is malformed.
|
|
624
|
+
* @example
|
|
625
|
+
* ```ts
|
|
626
|
+
* const session = await sdk.apiModule.createKycSession({ ...challenge, signature });
|
|
627
|
+
* openSumsubWidget(session.accessToken);
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
createKycSession(options: ICreateKycSessionOptions): Promise<IKycSession>;
|
|
631
|
+
/**
|
|
632
|
+
* Get a fresh Sumsub WebSDK access token for an open session without a new
|
|
633
|
+
* signature (`POST /kyc/session/refresh`). A session lasts 4 h.
|
|
634
|
+
*
|
|
635
|
+
* Makes one HTTPS request; no RPC calls.
|
|
636
|
+
*
|
|
637
|
+
* @param params - `sessionToken` from {@link UpshiftApi.createKycSession}.
|
|
638
|
+
* @returns The new Sumsub access token.
|
|
639
|
+
* @throws UpshiftValidationError When `sessionToken` is malformed.
|
|
640
|
+
* @throws UpshiftKycError When the backend answers non-2xx: `session_expired` (401) once the session ends or the wallet is unbound.
|
|
641
|
+
* @example
|
|
642
|
+
* ```ts
|
|
643
|
+
* const expirationHandler = () => sdk.apiModule.refreshKycSession({ sessionToken });
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
refreshKycSession(params: {
|
|
647
|
+
sessionToken: string;
|
|
648
|
+
}): Promise<string>;
|
|
587
649
|
}
|
package/lib/modules/api/main.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.UpshiftApi = void 0;
|
|
|
10
10
|
*/
|
|
11
11
|
const ethers_1 = require("ethers");
|
|
12
12
|
const fetcher_1 = require("./fetcher");
|
|
13
|
+
const kyc_1 = require("./kyc");
|
|
13
14
|
const base_class_1 = require("../../core/base.class");
|
|
14
15
|
const core_1 = require("../../core/constants/core");
|
|
15
16
|
const errors_1 = require("../../core/errors");
|
|
@@ -906,6 +907,69 @@ class UpshiftApi extends base_class_1.UpshiftBase {
|
|
|
906
907
|
assertSnapshotArray(data, method);
|
|
907
908
|
return data.map(toUnrealizedPnlSnapshot);
|
|
908
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* Fetch a one-time SIWE challenge that proves the wallet is the user's
|
|
912
|
+
* before KYC starts (`GET /kyc/challenge`).
|
|
913
|
+
*
|
|
914
|
+
* Makes one HTTPS request to the public Upshift API; no RPC calls. Never
|
|
915
|
+
* cached: the nonce is single use and expires after 600 s.
|
|
916
|
+
*
|
|
917
|
+
* @param params - `wallet`, the EVM wallet that will sign `message`, and
|
|
918
|
+
* `chainId`, the EVM chain whose `KycRegistry` the session activates.
|
|
919
|
+
* @returns {@link IKycChallenge}. Sign `message` verbatim with `personal_sign`.
|
|
920
|
+
* @throws UpshiftValidationError When `wallet` or `chainId` is malformed.
|
|
921
|
+
* @throws UpshiftKycError When the backend answers non-2xx: `no_registry` (400) or `unavailable` (503).
|
|
922
|
+
* @throws UpshiftServerError When the response body is malformed.
|
|
923
|
+
* @example
|
|
924
|
+
* ```ts
|
|
925
|
+
* const challenge = await sdk.apiModule.getKycChallenge({ wallet, chainId: 1 });
|
|
926
|
+
* const signature = await walletClient.signMessage({ message: challenge.message });
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
async getKycChallenge(params) {
|
|
930
|
+
return (0, kyc_1.fetchKycChallenge)(params.wallet, params.chainId);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Open a KYC session with a signed challenge (`POST /kyc/session`). The
|
|
934
|
+
* first call creates the user's Sumsub applicant; later calls resume it.
|
|
935
|
+
* Every call activates the identity on `chainId`.
|
|
936
|
+
*
|
|
937
|
+
* Makes one HTTPS request and never retries: the nonce is single use. On
|
|
938
|
+
* any failure, fetch a new challenge before trying again.
|
|
939
|
+
*
|
|
940
|
+
* @param options - The challenge fields exactly as returned, plus `signature`.
|
|
941
|
+
* @returns {@link IKycSession} with the Sumsub WebSDK `accessToken`.
|
|
942
|
+
* @throws UpshiftValidationError When an input is malformed.
|
|
943
|
+
* @throws UpshiftKycError When the backend answers non-2xx. `reason` names the
|
|
944
|
+
* case; `retryable` is true for the in-progress and timed-out answers.
|
|
945
|
+
* @throws UpshiftServerError When the response body is malformed.
|
|
946
|
+
* @example
|
|
947
|
+
* ```ts
|
|
948
|
+
* const session = await sdk.apiModule.createKycSession({ ...challenge, signature });
|
|
949
|
+
* openSumsubWidget(session.accessToken);
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
async createKycSession(options) {
|
|
953
|
+
return (0, kyc_1.postKycSession)(options);
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Get a fresh Sumsub WebSDK access token for an open session without a new
|
|
957
|
+
* signature (`POST /kyc/session/refresh`). A session lasts 4 h.
|
|
958
|
+
*
|
|
959
|
+
* Makes one HTTPS request; no RPC calls.
|
|
960
|
+
*
|
|
961
|
+
* @param params - `sessionToken` from {@link UpshiftApi.createKycSession}.
|
|
962
|
+
* @returns The new Sumsub access token.
|
|
963
|
+
* @throws UpshiftValidationError When `sessionToken` is malformed.
|
|
964
|
+
* @throws UpshiftKycError When the backend answers non-2xx: `session_expired` (401) once the session ends or the wallet is unbound.
|
|
965
|
+
* @example
|
|
966
|
+
* ```ts
|
|
967
|
+
* const expirationHandler = () => sdk.apiModule.refreshKycSession({ sessionToken });
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
async refreshKycSession(params) {
|
|
971
|
+
return (0, kyc_1.postKycSessionRefresh)(params.sessionToken);
|
|
972
|
+
}
|
|
909
973
|
}
|
|
910
974
|
exports.UpshiftApi = UpshiftApi;
|
|
911
975
|
//# sourceMappingURL=main.js.map
|
|
@@ -119,11 +119,13 @@ export { getSwapRouterDepositResult } from '../../core/helpers/swap-router';
|
|
|
119
119
|
/**
|
|
120
120
|
* Vault Positions
|
|
121
121
|
*/
|
|
122
|
-
export declare function getVaultPositions({ vault, wallet, solanaWallet, stellarWallet, options, prefetchedReads, }: {
|
|
122
|
+
export declare function getVaultPositions({ vault, wallet, solanaWallet, stellarWallet, suiWallet, options, prefetchedReads, }: {
|
|
123
123
|
vault: IAddress;
|
|
124
124
|
wallet?: IAddress;
|
|
125
125
|
solanaWallet?: string;
|
|
126
126
|
stellarWallet?: string;
|
|
127
|
+
/** Sui wallet whose share balance is read for Sui vaults. */
|
|
128
|
+
suiWallet?: string;
|
|
127
129
|
options: IVaultBaseOptions;
|
|
128
130
|
/**
|
|
129
131
|
* Per-vault values already read via a Multicall3 batch at the fan-out call
|