@spritz-finance/service-client 0.35.0 → 0.36.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/lib/bridge/bridgeServiceClient.js +3 -4
- package/lib/onramp/onrampServiceClient.d.ts +5 -0
- package/lib/onramp/onrampServiceClient.js +23 -8
- package/lib/payableAccounts/payableAccountsServiceClient.d.ts +15 -103
- package/lib/payableAccounts/payableAccountsServiceClient.js +42 -19
- package/lib/web3/web3ServiceClient.d.ts +20 -10
- package/lib/web3/web3ServiceClient.js +50 -17
- package/package.json +1 -1
|
@@ -44,7 +44,6 @@ exports.getExternalPayments = getExternalPayments;
|
|
|
44
44
|
exports.BridgeClient = __importStar(require("./bridgeServiceClient"));
|
|
45
45
|
const restClient_1 = require("../restClient");
|
|
46
46
|
const baseClient = (0, restClient_1.getRestClient)(process.env.BRIDGE_SERVICE_API_IAM_URL, "/v2/bridge/api");
|
|
47
|
-
const ONRAMP_ENDPOINT = "/bridge";
|
|
48
47
|
const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
|
|
49
48
|
async function getTransferHashes(externalPaymentIds) {
|
|
50
49
|
return baseClient
|
|
@@ -53,7 +52,7 @@ async function getTransferHashes(externalPaymentIds) {
|
|
|
53
52
|
}
|
|
54
53
|
async function createBridgeBankAccount(userId, accountId, input) {
|
|
55
54
|
return baseClient
|
|
56
|
-
.post(`${
|
|
55
|
+
.post(`${ONRAMP_ROUTER_ENDPOINT}/users/${userId}/bank-accounts/${accountId}`, input)
|
|
57
56
|
.then((res) => res.data);
|
|
58
57
|
}
|
|
59
58
|
// Unlike the legacy `/user/:id` route, `/api/users/:id` refreshes the user's
|
|
@@ -66,7 +65,7 @@ async function getBridgeUser(userId) {
|
|
|
66
65
|
}
|
|
67
66
|
async function validateTransfer({ userId, transferId, amount, toAddress, }) {
|
|
68
67
|
return baseClient
|
|
69
|
-
.post(`${
|
|
68
|
+
.post(`${ONRAMP_ROUTER_ENDPOINT}/off-ramps/transfers/validate`, {
|
|
70
69
|
userId,
|
|
71
70
|
transferId,
|
|
72
71
|
amount,
|
|
@@ -88,6 +87,6 @@ async function getExchangeRates(from, to) {
|
|
|
88
87
|
}
|
|
89
88
|
async function getExternalPayments(paymentIds) {
|
|
90
89
|
return baseClient
|
|
91
|
-
.get(`${
|
|
90
|
+
.get(`${ONRAMP_ROUTER_ENDPOINT}/external-payments?paymentIds=${paymentIds.join(",")}`)
|
|
92
91
|
.then((res) => res.data);
|
|
93
92
|
}
|
|
@@ -2,6 +2,11 @@ export * as OnrampClient from "./onrampServiceClient";
|
|
|
2
2
|
import { OnRampPayment } from "../lib/graphClient/generated";
|
|
3
3
|
import { BridgeUser, CreateBridgeUserParams, SyncOnrampTransferInput } from "./types";
|
|
4
4
|
export declare function syncTransfer(input: SyncOnrampTransferInput): Promise<OnRampPayment>;
|
|
5
|
+
/**
|
|
6
|
+
* Every completed on-ramp, unpaginated, as the legacy
|
|
7
|
+
* `/payments/user/:id/completed` route returned it (`/api/on-ramps/users/:id`
|
|
8
|
+
* is the paginated list).
|
|
9
|
+
*/
|
|
5
10
|
export declare function getUserCompletedPayments(userId: string): Promise<OnRampPayment[]>;
|
|
6
11
|
export declare function upsertBridgeUser(input: CreateBridgeUserParams): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<BridgeUser | null>>;
|
|
7
12
|
export declare function createBusinessUser(userId: string, businessName: string): Promise<{
|
|
@@ -42,26 +42,41 @@ exports.OnrampClient = __importStar(require("./onrampServiceClient"));
|
|
|
42
42
|
const restClient_1 = require("../restClient");
|
|
43
43
|
const baseClient = (0, restClient_1.getRestClient)(process.env.ONRAMP_SERVICE_API_IAM_URL, "/v2/bridge/api");
|
|
44
44
|
const ONRAMP_ENDPOINT = "/bridge";
|
|
45
|
+
const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
|
|
46
|
+
/**
|
|
47
|
+
* Awaits an `/api` request and returns the bare body its legacy route answered
|
|
48
|
+
* with. The `/api` routes answer every failure as a 200 failure envelope;
|
|
49
|
+
* throw on it, as the legacy route's non-2xx did.
|
|
50
|
+
*/
|
|
51
|
+
async function legacyBareBody(request, failureMessage) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const body = (await request).data;
|
|
54
|
+
if (body.status === "failure") {
|
|
55
|
+
throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
|
|
56
|
+
}
|
|
57
|
+
return body.data;
|
|
58
|
+
}
|
|
45
59
|
async function syncTransfer(input) {
|
|
46
60
|
return baseClient
|
|
47
61
|
.post(`${ONRAMP_ENDPOINT}/external-transfer`, input)
|
|
48
62
|
.then((res) => res.data);
|
|
49
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Every completed on-ramp, unpaginated, as the legacy
|
|
66
|
+
* `/payments/user/:id/completed` route returned it (`/api/on-ramps/users/:id`
|
|
67
|
+
* is the paginated list).
|
|
68
|
+
*/
|
|
50
69
|
async function getUserCompletedPayments(userId) {
|
|
51
|
-
return baseClient
|
|
52
|
-
.get(`${ONRAMP_ENDPOINT}/payments/user/${userId}/completed`)
|
|
53
|
-
.then((res) => res.data);
|
|
70
|
+
return legacyBareBody(baseClient.get(`${ONRAMP_ROUTER_ENDPOINT}/on-ramps/users/${userId}/completed`), "Failed to get completed payments");
|
|
54
71
|
}
|
|
55
72
|
async function upsertBridgeUser(input) {
|
|
56
73
|
return baseClient
|
|
57
|
-
.post(`${
|
|
74
|
+
.post(`${ONRAMP_ROUTER_ENDPOINT}/users`, input)
|
|
58
75
|
.then((res) => res.data);
|
|
59
76
|
}
|
|
60
77
|
async function createBusinessUser(userId, businessName) {
|
|
61
|
-
return baseClient
|
|
62
|
-
.post(`${ONRAMP_ENDPOINT}/business-user`, {
|
|
78
|
+
return legacyBareBody(baseClient.post(`${ONRAMP_ROUTER_ENDPOINT}/users/business`, {
|
|
63
79
|
userId,
|
|
64
80
|
businessName,
|
|
65
|
-
})
|
|
66
|
-
.then((res) => res.data);
|
|
81
|
+
}), "Failed to create business user");
|
|
67
82
|
}
|
|
@@ -1,107 +1,14 @@
|
|
|
1
1
|
export * as PayableAccountsClient from "./payableAccountsServiceClient";
|
|
2
|
+
import { ApiResponse } from "../types";
|
|
2
3
|
import { BankAccountPayoutRail, BankAccountUnpayableCode, DebitCardDetails, DebitCardUnpayableCode, ExternalBillInput, PayableAccount, PayableAccountInstitution, SimpleCardTransaction, UpsertVirtualCardInput } from "./types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}) | (Omit<import("../lib/graphClient/generated").BankAccount, "type" | "institution"> & {
|
|
12
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
13
|
-
externalId?: string | null;
|
|
14
|
-
institutionId?: string | null;
|
|
15
|
-
nickname?: string | null;
|
|
16
|
-
payable: boolean;
|
|
17
|
-
testPaymentAvailable: boolean;
|
|
18
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
19
|
-
} & {
|
|
20
|
-
disabledPayoutRails?: import("./types").DisabledPayoutRail[] | null;
|
|
21
|
-
unpayableCode?: BankAccountUnpayableCode | null;
|
|
22
|
-
unpayableReason?: string | null;
|
|
23
|
-
unpayableAt?: string | null;
|
|
24
|
-
}) | (Omit<import("../lib/graphClient/generated").VirtualCard, "type" | "institution"> & {
|
|
25
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
26
|
-
externalId?: string | null;
|
|
27
|
-
institutionId?: string | null;
|
|
28
|
-
nickname?: string | null;
|
|
29
|
-
payable: boolean;
|
|
30
|
-
testPaymentAvailable: boolean;
|
|
31
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
32
|
-
}) | (Omit<import("../lib/graphClient/generated").DebitCard, "type" | "institution"> & {
|
|
33
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
34
|
-
externalId?: string | null;
|
|
35
|
-
institutionId?: string | null;
|
|
36
|
-
nickname?: string | null;
|
|
37
|
-
payable: boolean;
|
|
38
|
-
testPaymentAvailable: boolean;
|
|
39
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
40
|
-
} & {
|
|
41
|
-
providerRegistrations?: import("./types").ProviderRegistration[];
|
|
42
|
-
unpayableCode?: DebitCardUnpayableCode | null;
|
|
43
|
-
unpayableReason?: string | null;
|
|
44
|
-
unpayableAt?: string | null;
|
|
45
|
-
}) | (Omit<import("../lib/graphClient/generated").OneTimePayment, "type" | "institution"> & {
|
|
46
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
47
|
-
externalId?: string | null;
|
|
48
|
-
institutionId?: string | null;
|
|
49
|
-
nickname?: string | null;
|
|
50
|
-
payable: boolean;
|
|
51
|
-
testPaymentAvailable: boolean;
|
|
52
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
53
|
-
})>;
|
|
54
|
-
export declare function getAccountByExternalId(externalId: string): Promise<(Omit<import("../lib/graphClient/generated").Bill, "type" | "institution"> & {
|
|
55
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
56
|
-
externalId?: string | null;
|
|
57
|
-
institutionId?: string | null;
|
|
58
|
-
nickname?: string | null;
|
|
59
|
-
payable: boolean;
|
|
60
|
-
testPaymentAvailable: boolean;
|
|
61
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
62
|
-
}) | (Omit<import("../lib/graphClient/generated").BankAccount, "type" | "institution"> & {
|
|
63
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
64
|
-
externalId?: string | null;
|
|
65
|
-
institutionId?: string | null;
|
|
66
|
-
nickname?: string | null;
|
|
67
|
-
payable: boolean;
|
|
68
|
-
testPaymentAvailable: boolean;
|
|
69
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
70
|
-
} & {
|
|
71
|
-
disabledPayoutRails?: import("./types").DisabledPayoutRail[] | null;
|
|
72
|
-
unpayableCode?: BankAccountUnpayableCode | null;
|
|
73
|
-
unpayableReason?: string | null;
|
|
74
|
-
unpayableAt?: string | null;
|
|
75
|
-
}) | (Omit<import("../lib/graphClient/generated").VirtualCard, "type" | "institution"> & {
|
|
76
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
77
|
-
externalId?: string | null;
|
|
78
|
-
institutionId?: string | null;
|
|
79
|
-
nickname?: string | null;
|
|
80
|
-
payable: boolean;
|
|
81
|
-
testPaymentAvailable: boolean;
|
|
82
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
83
|
-
}) | (Omit<import("../lib/graphClient/generated").DebitCard, "type" | "institution"> & {
|
|
84
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
85
|
-
externalId?: string | null;
|
|
86
|
-
institutionId?: string | null;
|
|
87
|
-
nickname?: string | null;
|
|
88
|
-
payable: boolean;
|
|
89
|
-
testPaymentAvailable: boolean;
|
|
90
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
91
|
-
} & {
|
|
92
|
-
providerRegistrations?: import("./types").ProviderRegistration[];
|
|
93
|
-
unpayableCode?: DebitCardUnpayableCode | null;
|
|
94
|
-
unpayableReason?: string | null;
|
|
95
|
-
unpayableAt?: string | null;
|
|
96
|
-
}) | (Omit<import("../lib/graphClient/generated").OneTimePayment, "type" | "institution"> & {
|
|
97
|
-
__t: import("../lib/graphClient/generated").PayableAccountType;
|
|
98
|
-
externalId?: string | null;
|
|
99
|
-
institutionId?: string | null;
|
|
100
|
-
nickname?: string | null;
|
|
101
|
-
payable: boolean;
|
|
102
|
-
testPaymentAvailable: boolean;
|
|
103
|
-
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
104
|
-
})>;
|
|
4
|
+
/**
|
|
5
|
+
* The bare account, as the legacy `/payable-account/id/:id` route returned it,
|
|
6
|
+
* and `null` when there is none (as that route answered, whatever the declared
|
|
7
|
+
* type says). Its `/api` replacement also serves the v2 lookup, so it adds a
|
|
8
|
+
* debit card's `providerRegistrations`; drop them to keep the v1 shape.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getAccount(accountId: string): Promise<PayableAccount>;
|
|
11
|
+
export declare function getAccountByExternalId(externalId: string): Promise<PayableAccount>;
|
|
105
12
|
export declare function getAccountsForUser(userId: string): Promise<PayableAccount[]>;
|
|
106
13
|
export declare function getAccounts(accountIds: string[]): Promise<PayableAccount[]>;
|
|
107
14
|
export declare function getAccountInstitution(institutionId: string): Promise<PayableAccountInstitution>;
|
|
@@ -114,7 +21,12 @@ export declare function upsertBillFromExternalAccount(input: ExternalBillInput):
|
|
|
114
21
|
testPaymentAvailable: boolean;
|
|
115
22
|
provider: import("../lib/graphClient/generated").AccountProvider;
|
|
116
23
|
}>;
|
|
117
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Same `/api` route as `getAccount`, envelope kept. That route answers a
|
|
26
|
+
* missing account with `data: null`; the legacy v2 route failed with "Account
|
|
27
|
+
* not found", so keep that failure.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getAccountById(accountId: string): Promise<ApiResponse<PayableAccount>>;
|
|
118
30
|
export declare function createUSVirtualCardNoKyc(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<PayableAccount>>;
|
|
119
31
|
export declare function upsertVirtualCard(input: UpsertVirtualCardInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<PayableAccount>>;
|
|
120
32
|
export declare function getRecentCardSpendTransactions(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<SimpleCardTransaction[]>>;
|
|
@@ -55,40 +55,63 @@ const PAYABLE_ACCOUNTS_ENDPOINT = "/payable-accounts";
|
|
|
55
55
|
// The Hono ServiceApi (`/api/{proxy+}`) is mapped on the shared gateway domain
|
|
56
56
|
// under the `payable-accounts-v2` key (serverless.yaml HTTPAPIMapping).
|
|
57
57
|
const PAYABLE_ACCOUNTS_ROUTER_ENDPOINT = "/payable-accounts-v2/api";
|
|
58
|
+
/**
|
|
59
|
+
* Awaits an `/api` request and returns the bare body its legacy route answered
|
|
60
|
+
* with. The `/api` routes answer every failure as a 200 failure envelope;
|
|
61
|
+
* throw on it, as the legacy route's non-2xx did.
|
|
62
|
+
*/
|
|
63
|
+
async function legacyBareBody(request, failureMessage) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const body = (await request).data;
|
|
66
|
+
if (body.status === "failure") {
|
|
67
|
+
throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
|
|
68
|
+
}
|
|
69
|
+
return body.data;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The bare account, as the legacy `/payable-account/id/:id` route returned it,
|
|
73
|
+
* and `null` when there is none (as that route answered, whatever the declared
|
|
74
|
+
* type says). Its `/api` replacement also serves the v2 lookup, so it adds a
|
|
75
|
+
* debit card's `providerRegistrations`; drop them to keep the v1 shape.
|
|
76
|
+
*/
|
|
58
77
|
async function getAccount(accountId) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
const account = await legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/${accountId}`), "Failed to get payable account");
|
|
79
|
+
if (!account || !("providerRegistrations" in account))
|
|
80
|
+
return account;
|
|
81
|
+
const { providerRegistrations: _registrations, ...v1Account } = account;
|
|
82
|
+
return v1Account;
|
|
62
83
|
}
|
|
63
84
|
async function getAccountByExternalId(externalId) {
|
|
64
|
-
return baseClient
|
|
65
|
-
.get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-account/externalId/${externalId}`)
|
|
66
|
-
.then((res) => res.data);
|
|
85
|
+
return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/external-id/${externalId}`), "Failed to get payable account by external id");
|
|
67
86
|
}
|
|
68
87
|
async function getAccountsForUser(userId) {
|
|
69
|
-
return baseClient
|
|
70
|
-
.get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-accounts/user/${userId}`)
|
|
71
|
-
.then((res) => res.data);
|
|
88
|
+
return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/user/${userId}`), "Failed to get payable accounts for user");
|
|
72
89
|
}
|
|
73
90
|
async function getAccounts(accountIds) {
|
|
74
|
-
return baseClient
|
|
75
|
-
.get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-accounts?accountIds=${accountIds.join(",")}`)
|
|
76
|
-
.then((res) => res.data);
|
|
91
|
+
return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts?accountIds=${accountIds.join(",")}`), "Failed to get payable accounts");
|
|
77
92
|
}
|
|
78
93
|
async function getAccountInstitution(institutionId) {
|
|
79
|
-
return baseClient
|
|
80
|
-
.get(`${PAYABLE_ACCOUNTS_ENDPOINT}/account-institution/id/${institutionId}`)
|
|
81
|
-
.then((res) => res.data);
|
|
94
|
+
return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/account-institutions/${institutionId}`), "Failed to get account institution");
|
|
82
95
|
}
|
|
83
96
|
async function upsertBillFromExternalAccount(input) {
|
|
84
97
|
return baseClient
|
|
85
98
|
.post(`${PAYABLE_ACCOUNTS_ENDPOINT}/bills/upsert-external-account`, input)
|
|
86
99
|
.then((res) => res.data);
|
|
87
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Same `/api` route as `getAccount`, envelope kept. That route answers a
|
|
103
|
+
* missing account with `data: null`; the legacy v2 route failed with "Account
|
|
104
|
+
* not found", so keep that failure.
|
|
105
|
+
*/
|
|
88
106
|
async function getAccountById(accountId) {
|
|
89
|
-
|
|
90
|
-
.get(`${
|
|
107
|
+
const body = await baseClient
|
|
108
|
+
.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/${accountId}`)
|
|
91
109
|
.then((res) => res.data);
|
|
110
|
+
if (body.status === "failure")
|
|
111
|
+
return body;
|
|
112
|
+
if (!body.data)
|
|
113
|
+
return { status: "failure", error: { message: "Account not found" } };
|
|
114
|
+
return { status: "success", data: body.data };
|
|
92
115
|
}
|
|
93
116
|
async function createUSVirtualCardNoKyc(userId) {
|
|
94
117
|
return baseClient
|
|
@@ -97,12 +120,12 @@ async function createUSVirtualCardNoKyc(userId) {
|
|
|
97
120
|
}
|
|
98
121
|
async function upsertVirtualCard(input) {
|
|
99
122
|
return baseClient
|
|
100
|
-
.post(`${
|
|
123
|
+
.post(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/cards/upsert`, input)
|
|
101
124
|
.then((res) => res.data);
|
|
102
125
|
}
|
|
103
126
|
async function getRecentCardSpendTransactions(userId) {
|
|
104
127
|
return baseClient
|
|
105
|
-
.get(`${
|
|
128
|
+
.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/cards/user/${userId}/recent-transactions`)
|
|
106
129
|
.then((res) => res.data);
|
|
107
130
|
}
|
|
108
131
|
/**
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
export * as Web3Client from "./web3ServiceClient";
|
|
2
|
+
import { ApiFailure, ApiResponse } from "../types";
|
|
2
3
|
import { ExactInQuoteInput, ExactInQuoteResponse, ListListedKaminoVaultIdsInput, ListListedKaminoVaultIdsResponse, OpsSignerMigrationState, OpsSignerReplacement, OpsSignerType, Portfolio, SignerUsageType, SolanaPaymentBuildInput, SolanaPaymentBuildResult, TokenBalance, UserOpsSigner, WalletTokenBalanceInput } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* The bare quote, as the legacy `/quote/swap/exactIn` route returned it. A
|
|
6
|
+
* failed quote still throws on the route's 400, as before.
|
|
7
|
+
*/
|
|
3
8
|
export declare function getExactInQuote(input: ExactInQuoteInput): Promise<ExactInQuoteResponse>;
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Balances on `input.network` only, dust filtered as on the legacy
|
|
11
|
+
* `/token-balances` route: `/api/token-balances` runs the same service.
|
|
12
|
+
* (`/api/wallet-balances` is multichain with dust and is NOT a substitute.)
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTokenBalances(input: WalletTokenBalanceInput): Promise<ApiResponse<TokenBalance[]>>;
|
|
15
|
+
export declare function getPortfolio(address: string): Promise<ApiFailure | import("../types").ApiSuccess<Portfolio>>;
|
|
6
16
|
export declare function getUserOpsSigner(input: {
|
|
7
17
|
userId: string;
|
|
8
18
|
signerType: OpsSignerType;
|
|
9
|
-
}): Promise<
|
|
19
|
+
}): Promise<ApiResponse<UserOpsSigner>>;
|
|
10
20
|
export declare function getUserOpsSignerByAddress(input: {
|
|
11
21
|
address: `0x${string}`;
|
|
12
|
-
}): Promise<
|
|
22
|
+
}): Promise<ApiResponse<UserOpsSigner>>;
|
|
13
23
|
export declare function getSmartAccountAddress(input: {
|
|
14
24
|
userId: string;
|
|
15
25
|
usageType: SignerUsageType;
|
|
16
|
-
}): Promise<
|
|
26
|
+
}): Promise<ApiResponse<`0x${string}`>>;
|
|
17
27
|
/**
|
|
18
28
|
* Provisions the user's signer for `signerType` if they do not already have one
|
|
19
29
|
* and returns it. Turnkey bills per derived address, so signers are minted
|
|
@@ -23,7 +33,7 @@ export declare function getSmartAccountAddress(input: {
|
|
|
23
33
|
export declare function ensureUserOpsSigner(input: {
|
|
24
34
|
userId: string;
|
|
25
35
|
signerType: OpsSignerType;
|
|
26
|
-
}): Promise<
|
|
36
|
+
}): Promise<ApiResponse<UserOpsSigner>>;
|
|
27
37
|
/**
|
|
28
38
|
* Creates an inactive signer in the current ops wallet for a legacy user. The
|
|
29
39
|
* existing signer remains active until its consumer completes the external
|
|
@@ -32,10 +42,10 @@ export declare function ensureUserOpsSigner(input: {
|
|
|
32
42
|
export declare function stageUserOpsSignerReplacement(input: {
|
|
33
43
|
userId: string;
|
|
34
44
|
signerType: OpsSignerType;
|
|
35
|
-
}): Promise<
|
|
45
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<OpsSignerReplacement>>;
|
|
36
46
|
export declare function getUserOpsSignerReplacement(input: {
|
|
37
47
|
userId: string;
|
|
38
48
|
signerType: OpsSignerType;
|
|
39
|
-
}): Promise<
|
|
40
|
-
export declare function buildSolanaPayment(input: SolanaPaymentBuildInput): Promise<
|
|
41
|
-
export declare function listListedKaminoVaultIds(input?: ListListedKaminoVaultIdsInput): Promise<
|
|
49
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<OpsSignerMigrationState>>;
|
|
50
|
+
export declare function buildSolanaPayment(input: SolanaPaymentBuildInput): Promise<ApiFailure | import("../types").ApiSuccess<SolanaPaymentBuildResult>>;
|
|
51
|
+
export declare function listListedKaminoVaultIds(input?: ListListedKaminoVaultIdsInput): Promise<ApiFailure | import("../types").ApiSuccess<ListListedKaminoVaultIdsResponse>>;
|
|
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.Web3Client = void 0;
|
|
37
40
|
exports.getExactInQuote = getExactInQuote;
|
|
@@ -46,19 +49,57 @@ exports.getUserOpsSignerReplacement = getUserOpsSignerReplacement;
|
|
|
46
49
|
exports.buildSolanaPayment = buildSolanaPayment;
|
|
47
50
|
exports.listListedKaminoVaultIds = listListedKaminoVaultIds;
|
|
48
51
|
exports.Web3Client = __importStar(require("./web3ServiceClient"));
|
|
52
|
+
const axios_1 = __importDefault(require("axios"));
|
|
49
53
|
const restClient_1 = require("../restClient");
|
|
50
54
|
const baseClient = (0, restClient_1.getRestClient)(process.env.WEB3_SERVICE_API_IAM_URL, "/v2/web3/api");
|
|
51
55
|
const WEB3_ENDPOINT = "/web3";
|
|
52
56
|
const WEB3_V2_ENDPOINT = "/v2/web3/api";
|
|
57
|
+
/**
|
|
58
|
+
* Resolves with the `/api` envelope, success or failure. web3's `/api` routes
|
|
59
|
+
* answer a failure with a 4xx/5xx carrying the failure envelope, where the
|
|
60
|
+
* legacy routes answered 200; resolve with that envelope, as before. Anything
|
|
61
|
+
* else (a transport error, a body that is not an envelope) still throws.
|
|
62
|
+
*/
|
|
63
|
+
async function legacyEnvelope(request) {
|
|
64
|
+
var _a;
|
|
65
|
+
try {
|
|
66
|
+
return (await request).data;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const body = axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.data : undefined;
|
|
70
|
+
if (isFailureEnvelope(body))
|
|
71
|
+
return body;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isFailureEnvelope(body) {
|
|
76
|
+
var _a;
|
|
77
|
+
return (typeof body === "object" &&
|
|
78
|
+
body !== null &&
|
|
79
|
+
body.status === "failure" &&
|
|
80
|
+
typeof ((_a = body.error) === null || _a === void 0 ? void 0 : _a.message) === "string");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The bare quote, as the legacy `/quote/swap/exactIn` route returned it. A
|
|
84
|
+
* failed quote still throws on the route's 400, as before.
|
|
85
|
+
*/
|
|
53
86
|
async function getExactInQuote(input) {
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const body = await baseClient
|
|
89
|
+
.post(`${WEB3_V2_ENDPOINT}/quote/swap/exactIn`, input)
|
|
56
90
|
.then((res) => res.data);
|
|
91
|
+
if (body.status === "failure") {
|
|
92
|
+
throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get ExactIn swap quote");
|
|
93
|
+
}
|
|
94
|
+
return body.data;
|
|
57
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Balances on `input.network` only, dust filtered as on the legacy
|
|
98
|
+
* `/token-balances` route: `/api/token-balances` runs the same service.
|
|
99
|
+
* (`/api/wallet-balances` is multichain with dust and is NOT a substitute.)
|
|
100
|
+
*/
|
|
58
101
|
async function getTokenBalances(input) {
|
|
59
|
-
return baseClient
|
|
60
|
-
.post(`${WEB3_ENDPOINT}/token-balances`, input)
|
|
61
|
-
.then((res) => res.data);
|
|
102
|
+
return legacyEnvelope(baseClient.post(`${WEB3_V2_ENDPOINT}/token-balances`, input));
|
|
62
103
|
}
|
|
63
104
|
async function getPortfolio(address) {
|
|
64
105
|
return baseClient
|
|
@@ -66,19 +107,13 @@ async function getPortfolio(address) {
|
|
|
66
107
|
.then((res) => res.data);
|
|
67
108
|
}
|
|
68
109
|
async function getUserOpsSigner(input) {
|
|
69
|
-
return baseClient
|
|
70
|
-
.get(`${WEB3_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`)
|
|
71
|
-
.then((res) => res.data);
|
|
110
|
+
return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`));
|
|
72
111
|
}
|
|
73
112
|
async function getUserOpsSignerByAddress(input) {
|
|
74
|
-
return baseClient
|
|
75
|
-
.get(`${WEB3_ENDPOINT}/ops-signer/address?address=${input.address}`)
|
|
76
|
-
.then((res) => res.data);
|
|
113
|
+
return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/address?address=${input.address}`));
|
|
77
114
|
}
|
|
78
115
|
async function getSmartAccountAddress(input) {
|
|
79
|
-
return baseClient
|
|
80
|
-
.get(`${WEB3_ENDPOINT}/ops-signer/smart-account/${input.userId}?usageType=${input.usageType}`)
|
|
81
|
-
.then((res) => res.data);
|
|
116
|
+
return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/smart-account/${input.userId}?usageType=${input.usageType}`));
|
|
82
117
|
}
|
|
83
118
|
/**
|
|
84
119
|
* Provisions the user's signer for `signerType` if they do not already have one
|
|
@@ -87,9 +122,7 @@ async function getSmartAccountAddress(input) {
|
|
|
87
122
|
* instead of `getUserOpsSigner` anywhere a missing signer should be created.
|
|
88
123
|
*/
|
|
89
124
|
async function ensureUserOpsSigner(input) {
|
|
90
|
-
return baseClient
|
|
91
|
-
.post(`${WEB3_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`)
|
|
92
|
-
.then((res) => res.data);
|
|
125
|
+
return legacyEnvelope(baseClient.post(`${WEB3_V2_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`));
|
|
93
126
|
}
|
|
94
127
|
/**
|
|
95
128
|
* Creates an inactive signer in the current ops wallet for a legacy user. The
|