@owney/sdk 0.7.26-beta.3 → 0.7.26-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +48 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +48 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2309,6 +2309,21 @@ function createSwapApi(baseUrl, apiKey) {
|
|
|
2309
2309
|
* Already filtered server-side to what a quote will accept, so anything
|
|
2310
2310
|
* returned here can be paid with.
|
|
2311
2311
|
*/
|
|
2312
|
+
/**
|
|
2313
|
+
* Tokens the wallet holds on one chain.
|
|
2314
|
+
*
|
|
2315
|
+
* Already filtered upstream to non-zero balances of tokens the routing API
|
|
2316
|
+
* would quote — 1inch answers with every token it knows about, zeros
|
|
2317
|
+
* included, and the curation that decides what is offerable lives there.
|
|
2318
|
+
*/
|
|
2319
|
+
walletBalances: (params) => request(
|
|
2320
|
+
baseUrl,
|
|
2321
|
+
apiKey,
|
|
2322
|
+
`/balances?${new URLSearchParams({
|
|
2323
|
+
chainId: String(params.chainId),
|
|
2324
|
+
walletAddress: params.walletAddress
|
|
2325
|
+
})}`
|
|
2326
|
+
),
|
|
2312
2327
|
searchTokens: (params) => request(
|
|
2313
2328
|
baseUrl,
|
|
2314
2329
|
apiKey,
|
|
@@ -4712,6 +4727,39 @@ var OwneySDK = class {
|
|
|
4712
4727
|
async getSwapTokens() {
|
|
4713
4728
|
return this.swapApi().listTokens();
|
|
4714
4729
|
}
|
|
4730
|
+
/**
|
|
4731
|
+
* What the wallet actually holds, across every supported chain, restricted
|
|
4732
|
+
* to tokens a swap could use.
|
|
4733
|
+
*
|
|
4734
|
+
* `getSwapTokens` answers "what may someone pay with in principle" from a
|
|
4735
|
+
* fixed list. This answers "what has this wallet got", which is a different
|
|
4736
|
+
* question and the one a picker needs: a user can hold something routable —
|
|
4737
|
+
* tBTC, say — that no fixed list of ours would ever mention.
|
|
4738
|
+
*
|
|
4739
|
+
* Each chain is asked separately because that is how the balance product is
|
|
4740
|
+
* shaped, and a chain that fails contributes nothing rather than failing the
|
|
4741
|
+
* lot. A picker with two chains in it beats an error. (ROUT-242)
|
|
4742
|
+
*/
|
|
4743
|
+
async getWalletBalances(chainIds) {
|
|
4744
|
+
const state = this.requireState();
|
|
4745
|
+
const chains = chainIds ?? SUPPORTED_CHAIN_IDS;
|
|
4746
|
+
const failedChainIds = [];
|
|
4747
|
+
const results = await Promise.all(
|
|
4748
|
+
chains.map(async (chainId) => {
|
|
4749
|
+
try {
|
|
4750
|
+
const { tokens } = await this.swapApi().walletBalances({
|
|
4751
|
+
chainId,
|
|
4752
|
+
walletAddress: state.walletAddress
|
|
4753
|
+
});
|
|
4754
|
+
return tokens.map((token) => ({ ...token, chainId }));
|
|
4755
|
+
} catch {
|
|
4756
|
+
failedChainIds.push(chainId);
|
|
4757
|
+
return [];
|
|
4758
|
+
}
|
|
4759
|
+
})
|
|
4760
|
+
);
|
|
4761
|
+
return { tokens: results.flat(), failedChainIds };
|
|
4762
|
+
}
|
|
4715
4763
|
/**
|
|
4716
4764
|
* Search the assets a user may pay with, across every supported chain.
|
|
4717
4765
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,26 @@ type SwapChainTokens = {
|
|
|
54
54
|
* the bulk list does, and the extra fields are the ones a picker needs to let
|
|
55
55
|
* someone choose safely between three tokens all called PEPE.
|
|
56
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* A token the wallet actually holds, as the Pay with picker needs it.
|
|
59
|
+
*
|
|
60
|
+
* The picker used to read a fixed list of (token, chain) pairs, so it could
|
|
61
|
+
* only ever offer those. This is the other direction — what is really there —
|
|
62
|
+
* already intersected server-side with what the routing API would quote, so
|
|
63
|
+
* every row can be acted on. (ROUT-242)
|
|
64
|
+
*/
|
|
65
|
+
type SwapWalletBalance = {
|
|
66
|
+
readonly symbol: string;
|
|
67
|
+
readonly address: `0x${string}`;
|
|
68
|
+
readonly decimals: number;
|
|
69
|
+
readonly chainId: number;
|
|
70
|
+
readonly name?: string;
|
|
71
|
+
readonly logoURI?: string;
|
|
72
|
+
readonly tags?: readonly string[];
|
|
73
|
+
readonly isNative?: true;
|
|
74
|
+
/** Smallest unit, as a decimal string. */
|
|
75
|
+
readonly balance: string;
|
|
76
|
+
};
|
|
57
77
|
type SwapTokenSearchResult = SwapTokenInfo & {
|
|
58
78
|
readonly chainId: number;
|
|
59
79
|
readonly name?: string;
|
|
@@ -925,6 +945,24 @@ declare class OwneySDK {
|
|
|
925
945
|
getSwapTokens(): Promise<{
|
|
926
946
|
chains: SwapChainTokens[];
|
|
927
947
|
}>;
|
|
948
|
+
/**
|
|
949
|
+
* What the wallet actually holds, across every supported chain, restricted
|
|
950
|
+
* to tokens a swap could use.
|
|
951
|
+
*
|
|
952
|
+
* `getSwapTokens` answers "what may someone pay with in principle" from a
|
|
953
|
+
* fixed list. This answers "what has this wallet got", which is a different
|
|
954
|
+
* question and the one a picker needs: a user can hold something routable —
|
|
955
|
+
* tBTC, say — that no fixed list of ours would ever mention.
|
|
956
|
+
*
|
|
957
|
+
* Each chain is asked separately because that is how the balance product is
|
|
958
|
+
* shaped, and a chain that fails contributes nothing rather than failing the
|
|
959
|
+
* lot. A picker with two chains in it beats an error. (ROUT-242)
|
|
960
|
+
*/
|
|
961
|
+
getWalletBalances(chainIds?: readonly number[]): Promise<{
|
|
962
|
+
tokens: SwapWalletBalance[];
|
|
963
|
+
/** Chains that could not be read, so the caller can say so or retry. */
|
|
964
|
+
failedChainIds: number[];
|
|
965
|
+
}>;
|
|
928
966
|
/**
|
|
929
967
|
* Search the assets a user may pay with, across every supported chain.
|
|
930
968
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,26 @@ type SwapChainTokens = {
|
|
|
54
54
|
* the bulk list does, and the extra fields are the ones a picker needs to let
|
|
55
55
|
* someone choose safely between three tokens all called PEPE.
|
|
56
56
|
*/
|
|
57
|
+
/**
|
|
58
|
+
* A token the wallet actually holds, as the Pay with picker needs it.
|
|
59
|
+
*
|
|
60
|
+
* The picker used to read a fixed list of (token, chain) pairs, so it could
|
|
61
|
+
* only ever offer those. This is the other direction — what is really there —
|
|
62
|
+
* already intersected server-side with what the routing API would quote, so
|
|
63
|
+
* every row can be acted on. (ROUT-242)
|
|
64
|
+
*/
|
|
65
|
+
type SwapWalletBalance = {
|
|
66
|
+
readonly symbol: string;
|
|
67
|
+
readonly address: `0x${string}`;
|
|
68
|
+
readonly decimals: number;
|
|
69
|
+
readonly chainId: number;
|
|
70
|
+
readonly name?: string;
|
|
71
|
+
readonly logoURI?: string;
|
|
72
|
+
readonly tags?: readonly string[];
|
|
73
|
+
readonly isNative?: true;
|
|
74
|
+
/** Smallest unit, as a decimal string. */
|
|
75
|
+
readonly balance: string;
|
|
76
|
+
};
|
|
57
77
|
type SwapTokenSearchResult = SwapTokenInfo & {
|
|
58
78
|
readonly chainId: number;
|
|
59
79
|
readonly name?: string;
|
|
@@ -925,6 +945,24 @@ declare class OwneySDK {
|
|
|
925
945
|
getSwapTokens(): Promise<{
|
|
926
946
|
chains: SwapChainTokens[];
|
|
927
947
|
}>;
|
|
948
|
+
/**
|
|
949
|
+
* What the wallet actually holds, across every supported chain, restricted
|
|
950
|
+
* to tokens a swap could use.
|
|
951
|
+
*
|
|
952
|
+
* `getSwapTokens` answers "what may someone pay with in principle" from a
|
|
953
|
+
* fixed list. This answers "what has this wallet got", which is a different
|
|
954
|
+
* question and the one a picker needs: a user can hold something routable —
|
|
955
|
+
* tBTC, say — that no fixed list of ours would ever mention.
|
|
956
|
+
*
|
|
957
|
+
* Each chain is asked separately because that is how the balance product is
|
|
958
|
+
* shaped, and a chain that fails contributes nothing rather than failing the
|
|
959
|
+
* lot. A picker with two chains in it beats an error. (ROUT-242)
|
|
960
|
+
*/
|
|
961
|
+
getWalletBalances(chainIds?: readonly number[]): Promise<{
|
|
962
|
+
tokens: SwapWalletBalance[];
|
|
963
|
+
/** Chains that could not be read, so the caller can say so or retry. */
|
|
964
|
+
failedChainIds: number[];
|
|
965
|
+
}>;
|
|
928
966
|
/**
|
|
929
967
|
* Search the assets a user may pay with, across every supported chain.
|
|
930
968
|
*
|
package/dist/index.js
CHANGED
|
@@ -2275,6 +2275,21 @@ function createSwapApi(baseUrl, apiKey) {
|
|
|
2275
2275
|
* Already filtered server-side to what a quote will accept, so anything
|
|
2276
2276
|
* returned here can be paid with.
|
|
2277
2277
|
*/
|
|
2278
|
+
/**
|
|
2279
|
+
* Tokens the wallet holds on one chain.
|
|
2280
|
+
*
|
|
2281
|
+
* Already filtered upstream to non-zero balances of tokens the routing API
|
|
2282
|
+
* would quote — 1inch answers with every token it knows about, zeros
|
|
2283
|
+
* included, and the curation that decides what is offerable lives there.
|
|
2284
|
+
*/
|
|
2285
|
+
walletBalances: (params) => request(
|
|
2286
|
+
baseUrl,
|
|
2287
|
+
apiKey,
|
|
2288
|
+
`/balances?${new URLSearchParams({
|
|
2289
|
+
chainId: String(params.chainId),
|
|
2290
|
+
walletAddress: params.walletAddress
|
|
2291
|
+
})}`
|
|
2292
|
+
),
|
|
2278
2293
|
searchTokens: (params) => request(
|
|
2279
2294
|
baseUrl,
|
|
2280
2295
|
apiKey,
|
|
@@ -4689,6 +4704,39 @@ var OwneySDK = class {
|
|
|
4689
4704
|
async getSwapTokens() {
|
|
4690
4705
|
return this.swapApi().listTokens();
|
|
4691
4706
|
}
|
|
4707
|
+
/**
|
|
4708
|
+
* What the wallet actually holds, across every supported chain, restricted
|
|
4709
|
+
* to tokens a swap could use.
|
|
4710
|
+
*
|
|
4711
|
+
* `getSwapTokens` answers "what may someone pay with in principle" from a
|
|
4712
|
+
* fixed list. This answers "what has this wallet got", which is a different
|
|
4713
|
+
* question and the one a picker needs: a user can hold something routable —
|
|
4714
|
+
* tBTC, say — that no fixed list of ours would ever mention.
|
|
4715
|
+
*
|
|
4716
|
+
* Each chain is asked separately because that is how the balance product is
|
|
4717
|
+
* shaped, and a chain that fails contributes nothing rather than failing the
|
|
4718
|
+
* lot. A picker with two chains in it beats an error. (ROUT-242)
|
|
4719
|
+
*/
|
|
4720
|
+
async getWalletBalances(chainIds) {
|
|
4721
|
+
const state = this.requireState();
|
|
4722
|
+
const chains = chainIds ?? SUPPORTED_CHAIN_IDS;
|
|
4723
|
+
const failedChainIds = [];
|
|
4724
|
+
const results = await Promise.all(
|
|
4725
|
+
chains.map(async (chainId) => {
|
|
4726
|
+
try {
|
|
4727
|
+
const { tokens } = await this.swapApi().walletBalances({
|
|
4728
|
+
chainId,
|
|
4729
|
+
walletAddress: state.walletAddress
|
|
4730
|
+
});
|
|
4731
|
+
return tokens.map((token) => ({ ...token, chainId }));
|
|
4732
|
+
} catch {
|
|
4733
|
+
failedChainIds.push(chainId);
|
|
4734
|
+
return [];
|
|
4735
|
+
}
|
|
4736
|
+
})
|
|
4737
|
+
);
|
|
4738
|
+
return { tokens: results.flat(), failedChainIds };
|
|
4739
|
+
}
|
|
4692
4740
|
/**
|
|
4693
4741
|
* Search the assets a user may pay with, across every supported chain.
|
|
4694
4742
|
*
|