@wirexapp/wpay-baas-sdk 0.1.10 → 0.1.12
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 +9 -3
- package/dist/{chunk-GOPZA7GB.js → chunk-IAY3T66T.js} +97 -30
- package/dist/chunk-IAY3T66T.js.map +1 -0
- package/dist/{crypto.module-b1_0pvdU.d.ts → crypto.module-DMKRqQiN.d.ts} +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modules/crypto/index.d.ts +2 -2
- package/dist/modules/crypto/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GOPZA7GB.js.map +0 -1
package/README.md
CHANGED
|
@@ -332,14 +332,20 @@ interface YieldData {
|
|
|
332
332
|
|--------|-------------|
|
|
333
333
|
| `initializeSmartDepositAddresses(forceRefresh?)` | Create/get all deposit addresses |
|
|
334
334
|
| `getAddresses()` | Get cached addresses |
|
|
335
|
+
| `getDestinationChain()` | Rhino.fi chain code funds are bridged to |
|
|
335
336
|
| `clearAddresses()` | Clear address cache |
|
|
336
337
|
|
|
337
|
-
**
|
|
338
|
-
|
|
338
|
+
**Destination chain** follows the SDK `chainId`: `8453` / `84532` → `BASE`, `5042` / `5042002` → `ARC`. Rhino.fi has no testnet chains, so testnet ids resolve to the mainnet code.
|
|
339
|
+
|
|
340
|
+
The destination chain is itself requested as a deposit chain, so the EVM group also holds a same-chain address — `ARC` → `ARC` when the SDK runs on Arc, `BASE` → `BASE` on Base.
|
|
341
|
+
|
|
342
|
+
Deposit chains the destination rejects are skipped with a warning and the remaining chains in the group are still created: no bridgeable route (Rhino.fi `DepositAddressNoBridgableTokens`, e.g. USDT-only Kaia and TRON towards Arc) and chains Rhino.fi has not enabled for deposit addresses (`DepositAddressChainsNotSupported`).
|
|
343
|
+
|
|
344
|
+
**Supported deposit networks:**
|
|
345
|
+
- EVM: the destination chain (Base or Arc), Base, Arbitrum, BNB Chain, Ethereum, Kaia, Polygon, Optimism
|
|
339
346
|
- TRON
|
|
340
347
|
- Solana
|
|
341
348
|
- Stellar
|
|
342
|
-
- Solana
|
|
343
349
|
|
|
344
350
|
---
|
|
345
351
|
|
|
@@ -4803,6 +4803,8 @@ var ContractRegistryService = class {
|
|
|
4803
4803
|
}
|
|
4804
4804
|
}
|
|
4805
4805
|
};
|
|
4806
|
+
var STELLAR_CHAIN = "STELLAR";
|
|
4807
|
+
var ARC_CHAIN = "ARC";
|
|
4806
4808
|
var supportedEVMChains = [
|
|
4807
4809
|
SupportedChains.BASE,
|
|
4808
4810
|
SupportedChains.ARBITRUM_ONE,
|
|
@@ -4812,14 +4814,51 @@ var supportedEVMChains = [
|
|
|
4812
4814
|
SupportedChains.POLYGON,
|
|
4813
4815
|
SupportedChains.OPTIMISM
|
|
4814
4816
|
];
|
|
4815
|
-
|
|
4817
|
+
function getEvmDepositChains(destinationChain) {
|
|
4818
|
+
return supportedEVMChains.includes(destinationChain) ? [...supportedEVMChains] : [destinationChain, ...supportedEVMChains];
|
|
4819
|
+
}
|
|
4820
|
+
var RHINO_DESTINATION_CHAIN_BY_CHAIN_ID = {
|
|
4821
|
+
8453: SupportedChains.BASE,
|
|
4822
|
+
84532: SupportedChains.BASE,
|
|
4823
|
+
5042: ARC_CHAIN,
|
|
4824
|
+
5042002: ARC_CHAIN
|
|
4825
|
+
};
|
|
4826
|
+
function resolveRhinoDestinationChain(chainId) {
|
|
4827
|
+
const destinationChain = RHINO_DESTINATION_CHAIN_BY_CHAIN_ID[chainId];
|
|
4828
|
+
if (!destinationChain) {
|
|
4829
|
+
const supported = Object.keys(RHINO_DESTINATION_CHAIN_BY_CHAIN_ID).join(", ");
|
|
4830
|
+
throw new ConfigurationError(
|
|
4831
|
+
`No Rhino.fi destination chain for chainId ${chainId}. Supported: ${supported}`
|
|
4832
|
+
);
|
|
4833
|
+
}
|
|
4834
|
+
return destinationChain;
|
|
4835
|
+
}
|
|
4816
4836
|
var SYSTEM_SUPPORTED_TOKENS = ["USDT", "USDC", "EURC"];
|
|
4837
|
+
var NO_BRIDGEABLE_TOKENS_TAG = "DepositAddressNoBridgableTokens";
|
|
4838
|
+
var CHAINS_NOT_SUPPORTED_TAG = "DepositAddressChainsNotSupported";
|
|
4839
|
+
function getRejectedChains(error) {
|
|
4840
|
+
if (!error || typeof error !== "object") {
|
|
4841
|
+
return [];
|
|
4842
|
+
}
|
|
4843
|
+
const { _tag, from, chains } = error;
|
|
4844
|
+
if (_tag === NO_BRIDGEABLE_TOKENS_TAG) {
|
|
4845
|
+
return typeof from === "string" ? [from] : [];
|
|
4846
|
+
}
|
|
4847
|
+
if (_tag === CHAINS_NOT_SUPPORTED_TAG && Array.isArray(chains)) {
|
|
4848
|
+
return chains.filter((chain) => typeof chain === "string");
|
|
4849
|
+
}
|
|
4850
|
+
return [];
|
|
4851
|
+
}
|
|
4817
4852
|
var SmartDepositAddressesService = class {
|
|
4818
4853
|
constructor(config) {
|
|
4819
4854
|
this.rhinoSdkInstance = null;
|
|
4820
4855
|
this.addresses = [];
|
|
4821
4856
|
this.walletService = config.walletService;
|
|
4822
4857
|
this.rhinoApiKey = config.rhinoApiKey;
|
|
4858
|
+
this.destinationChain = resolveRhinoDestinationChain(config.chainId);
|
|
4859
|
+
}
|
|
4860
|
+
getDestinationChain() {
|
|
4861
|
+
return this.destinationChain;
|
|
4823
4862
|
}
|
|
4824
4863
|
async initializeSmartDepositAddresses(forceRefresh = false) {
|
|
4825
4864
|
if (this.addresses.length > 0 && !forceRefresh) {
|
|
@@ -4838,7 +4877,7 @@ var SmartDepositAddressesService = class {
|
|
|
4838
4877
|
if (!hasTronAddresses) failedGroups.push("TRON");
|
|
4839
4878
|
if (!hasSolanaAddresses) failedGroups.push("Solana");
|
|
4840
4879
|
if (!hasStellarAddresses) failedGroups.push("Stellar");
|
|
4841
|
-
console.warn(`
|
|
4880
|
+
console.warn(`No deposit addresses for chain groups: ${failedGroups.join(", ")}`);
|
|
4842
4881
|
}
|
|
4843
4882
|
this.setAddresses(allAddresses);
|
|
4844
4883
|
return allAddresses;
|
|
@@ -4860,31 +4899,49 @@ var SmartDepositAddressesService = class {
|
|
|
4860
4899
|
const smartWalletClient = await this.walletService.getSmartWalletClient();
|
|
4861
4900
|
const smartWalletAddress = smartWalletClient.account.address;
|
|
4862
4901
|
const sdk = this.getRhinoSdk();
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
throw new Error(JSON.stringify(response.error));
|
|
4876
|
-
}
|
|
4877
|
-
const activationPromises = response.data.filter((depositData) => !depositData.isActive).map(async (depositData) => {
|
|
4878
|
-
const activationResponse = await sdk.api.depositAddresses.activate({
|
|
4879
|
-
depositAddress: depositData.depositAddress,
|
|
4880
|
-
depositChain: depositData.depositChain
|
|
4902
|
+
let depositChains = [...supportedChains];
|
|
4903
|
+
while (depositChains.length > 0) {
|
|
4904
|
+
const response = await sdk.api.depositAddresses.create({
|
|
4905
|
+
depositChains,
|
|
4906
|
+
destinationChain: this.destinationChain,
|
|
4907
|
+
destinationAddress: smartWalletAddress,
|
|
4908
|
+
bridgeIfNotSwappable: true,
|
|
4909
|
+
tokenOut: "USDC",
|
|
4910
|
+
postBridgeData: {
|
|
4911
|
+
_tag: "wirexwrap"
|
|
4912
|
+
},
|
|
4913
|
+
reusePolicy: "reuse-existing"
|
|
4881
4914
|
});
|
|
4882
|
-
if (
|
|
4883
|
-
|
|
4915
|
+
if (response.response.status === 200 && response.data) {
|
|
4916
|
+
return this.activateDepositAddresses(sdk, response.data);
|
|
4917
|
+
}
|
|
4918
|
+
const rejectedChains = getRejectedChains(response.error).filter(
|
|
4919
|
+
(chain) => depositChains.includes(chain)
|
|
4920
|
+
);
|
|
4921
|
+
if (rejectedChains.length === 0) {
|
|
4922
|
+
throw new Error(JSON.stringify(response.error));
|
|
4923
|
+
}
|
|
4924
|
+
console.warn(
|
|
4925
|
+
`Rhino.fi rejected deposit chains ${rejectedChains.join(", ")} for destination ${this.destinationChain}, skipping them`
|
|
4926
|
+
);
|
|
4927
|
+
depositChains = depositChains.filter((chain) => !rejectedChains.includes(chain));
|
|
4928
|
+
}
|
|
4929
|
+
return [];
|
|
4930
|
+
}
|
|
4931
|
+
async activateDepositAddresses(sdk, depositAddresses) {
|
|
4932
|
+
const inactiveAddresses = depositAddresses.filter((depositData) => !depositData.isActive);
|
|
4933
|
+
const activationResults = await Promise.allSettled(
|
|
4934
|
+
inactiveAddresses.map((depositData) => this.activateDepositAddress(sdk, depositData))
|
|
4935
|
+
);
|
|
4936
|
+
const failedChains = /* @__PURE__ */ new Set();
|
|
4937
|
+
activationResults.forEach((result, index) => {
|
|
4938
|
+
if (result.status === "rejected") {
|
|
4939
|
+
const chain = inactiveAddresses[index].depositChain;
|
|
4940
|
+
failedChains.add(chain);
|
|
4941
|
+
console.error(`Failed to activate ${chain} deposit address:`, result.reason);
|
|
4884
4942
|
}
|
|
4885
4943
|
});
|
|
4886
|
-
|
|
4887
|
-
return response.data.map((item) => {
|
|
4944
|
+
return depositAddresses.filter((item) => !failedChains.has(item.depositChain)).map((item) => {
|
|
4888
4945
|
const supportedTokens = (item.supportedTokens || []).map((token) => token.symbol).filter((symbol) => SYSTEM_SUPPORTED_TOKENS.includes(symbol));
|
|
4889
4946
|
return {
|
|
4890
4947
|
depositChain: item.depositChain,
|
|
@@ -4896,9 +4953,18 @@ var SmartDepositAddressesService = class {
|
|
|
4896
4953
|
};
|
|
4897
4954
|
});
|
|
4898
4955
|
}
|
|
4956
|
+
async activateDepositAddress(sdk, depositData) {
|
|
4957
|
+
const activationResponse = await sdk.api.depositAddresses.activate({
|
|
4958
|
+
depositAddress: depositData.depositAddress,
|
|
4959
|
+
depositChain: depositData.depositChain
|
|
4960
|
+
});
|
|
4961
|
+
if (activationResponse.response.status !== 200) {
|
|
4962
|
+
throw new Error(JSON.stringify(activationResponse.error));
|
|
4963
|
+
}
|
|
4964
|
+
}
|
|
4899
4965
|
async createSmartDepositAddresses() {
|
|
4900
4966
|
const results = await Promise.allSettled([
|
|
4901
|
-
this.createSmartDepositAddressForChains(
|
|
4967
|
+
this.createSmartDepositAddressForChains(getEvmDepositChains(this.destinationChain)),
|
|
4902
4968
|
this.createSmartDepositAddressForChains([SupportedChains.TRON]),
|
|
4903
4969
|
this.createSmartDepositAddressForChains([SupportedChains.SOLANA]),
|
|
4904
4970
|
this.createSmartDepositAddressForChains([STELLAR_CHAIN])
|
|
@@ -4956,7 +5022,7 @@ var SmartDepositAddressesService = class {
|
|
|
4956
5022
|
getChainsForGroup(chainGroup) {
|
|
4957
5023
|
switch (chainGroup) {
|
|
4958
5024
|
case "evm":
|
|
4959
|
-
return
|
|
5025
|
+
return getEvmDepositChains(this.destinationChain);
|
|
4960
5026
|
case "tron":
|
|
4961
5027
|
return [SupportedChains.TRON];
|
|
4962
5028
|
case "solana":
|
|
@@ -4968,7 +5034,7 @@ var SmartDepositAddressesService = class {
|
|
|
4968
5034
|
}
|
|
4969
5035
|
}
|
|
4970
5036
|
getChainGroupByChainCode(chainCode) {
|
|
4971
|
-
if (
|
|
5037
|
+
if (getEvmDepositChains(this.destinationChain).includes(chainCode)) {
|
|
4972
5038
|
return "evm";
|
|
4973
5039
|
}
|
|
4974
5040
|
if (chainCode === SupportedChains.TRON) {
|
|
@@ -5132,7 +5198,8 @@ var CryptoModule = class {
|
|
|
5132
5198
|
if (config.rhinoApiKey) {
|
|
5133
5199
|
this._smartDepositService = new SmartDepositAddressesService({
|
|
5134
5200
|
walletService: this._walletService,
|
|
5135
|
-
rhinoApiKey: config.rhinoApiKey
|
|
5201
|
+
rhinoApiKey: config.rhinoApiKey,
|
|
5202
|
+
chainId: config.chainId
|
|
5136
5203
|
});
|
|
5137
5204
|
}
|
|
5138
5205
|
}
|
|
@@ -5143,5 +5210,5 @@ var CryptoModule = class {
|
|
|
5143
5210
|
};
|
|
5144
5211
|
|
|
5145
5212
|
export { BaseAccountAbstractionService, BaseAccountContractService, BaseCryptoService, BaseOnboardingService, BaseWalletService, BaseYieldService, ContractRegistryService, CryptoModule, chainRegistry };
|
|
5146
|
-
//# sourceMappingURL=chunk-
|
|
5147
|
-
//# sourceMappingURL=chunk-
|
|
5213
|
+
//# sourceMappingURL=chunk-IAY3T66T.js.map
|
|
5214
|
+
//# sourceMappingURL=chunk-IAY3T66T.js.map
|