@defuse-protocol/intents-sdk 0.59.0 → 0.60.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 +2 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +7 -3
- package/dist/src/bridges/omni-bridge/omni-bridge.js +7 -3
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +4 -2
- package/dist/src/bridges/poa-bridge/poa-bridge.js +4 -2
- package/dist/src/sdk.cjs +2 -1
- package/dist/src/sdk.js +2 -1
- package/dist/src/shared-types.d.cts +1 -0
- package/dist/src/shared-types.d.ts +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -342,6 +342,8 @@ console.log('Batch fees:', batchFees); // Array of FeeEstimation objects
|
|
|
342
342
|
|
|
343
343
|
> **Note:** `estimateWithdrawalFee` also runs `validateWithdrawal` internally. If the withdrawal parameters are invalid (e.g. invalid destination address, amount below minimum, insufficient UTXOs), the bridge's `validateWithdrawal` will throw and the error will propagate from `estimateWithdrawalFee`.
|
|
344
344
|
|
|
345
|
+
> **Note:** When `amount` is `0n` and `feeInclusive` is `false`, minimum amount validation is skipped. This is useful when the exact withdrawal amount is not yet known and you only need a fee estimate.
|
|
346
|
+
|
|
345
347
|
## Advanced Usage
|
|
346
348
|
|
|
347
349
|
### Custom RPC URLs
|
|
@@ -164,7 +164,9 @@ var OmniBridge = class {
|
|
|
164
164
|
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
165
165
|
(0, _defuse_protocol_internal_utils.assert)(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
166
166
|
Ensure the token is supported and the address is correct.`);
|
|
167
|
-
if (
|
|
167
|
+
if (!args.skipMinAmountValidation) {
|
|
168
|
+
if ((0, _omni_bridge_core.verifyTransferAmount)(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new require_errors.MinWithdrawalAmountError((0, _omni_bridge_core.getMinimumTransferableAmount)(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
169
|
+
}
|
|
168
170
|
const intentsStorageBalance = await this.getCachedIntentsStorageBalance();
|
|
169
171
|
if (intentsStorageBalance <= require_omni_bridge_constants.MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new require_error.IntentsNearOmniAvailableBalanceTooLowError(intentsStorageBalance.toString());
|
|
170
172
|
const utxoChainWithdrawal = require_omni_bridge_utils.isUtxoChain(omniChainKind);
|
|
@@ -184,8 +186,10 @@ var OmniBridge = class {
|
|
|
184
186
|
const utxoProtocolFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.OmniBridge, "utxoProtocolFee");
|
|
185
187
|
(0, _defuse_protocol_internal_utils.assert)(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
|
|
186
188
|
(0, _defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
if (!args.skipMinAmountValidation) {
|
|
190
|
+
const actualAmountWithFee = args.amount + utxoMaxGasFee + utxoProtocolFee;
|
|
191
|
+
if (actualAmountWithFee < minAmount) throw new require_errors.MinWithdrawalAmountError(minAmount, actualAmountWithFee, args.assetId);
|
|
192
|
+
}
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
195
|
async estimateWithdrawalFee(args) {
|
|
@@ -162,7 +162,9 @@ var OmniBridge = class {
|
|
|
162
162
|
const decimals = await this.getCachedTokenDecimals(destTokenAddress);
|
|
163
163
|
assert(decimals !== null, `Failed to retrieve token decimals for address ${destTokenAddress} via OmniBridge contract.
|
|
164
164
|
Ensure the token is supported and the address is correct.`);
|
|
165
|
-
if (
|
|
165
|
+
if (!args.skipMinAmountValidation) {
|
|
166
|
+
if (verifyTransferAmount(args.amount, 0n, decimals.origin_decimals, decimals.decimals) === false) throw new MinWithdrawalAmountError(getMinimumTransferableAmount(decimals.origin_decimals, decimals.decimals), args.amount, args.assetId);
|
|
167
|
+
}
|
|
166
168
|
const intentsStorageBalance = await this.getCachedIntentsStorageBalance();
|
|
167
169
|
if (intentsStorageBalance <= MIN_STORAGE_BALANCE_FOR_INTENTS_NEAR) throw new IntentsNearOmniAvailableBalanceTooLowError(intentsStorageBalance.toString());
|
|
168
170
|
const utxoChainWithdrawal = isUtxoChain(omniChainKind);
|
|
@@ -182,8 +184,10 @@ var OmniBridge = class {
|
|
|
182
184
|
const utxoProtocolFee = getUnderlyingFee(args.feeEstimation, RouteEnum.OmniBridge, "utxoProtocolFee");
|
|
183
185
|
assert(utxoMaxGasFee !== void 0 && utxoMaxGasFee > 0n, `Invalid Omni Bridge utxo max gas fee: expected > 0, got ${utxoMaxGasFee}`);
|
|
184
186
|
assert(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
+
if (!args.skipMinAmountValidation) {
|
|
188
|
+
const actualAmountWithFee = args.amount + utxoMaxGasFee + utxoProtocolFee;
|
|
189
|
+
if (actualAmountWithFee < minAmount) throw new MinWithdrawalAmountError(minAmount, actualAmountWithFee, args.assetId);
|
|
190
|
+
}
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
async estimateWithdrawalFee(args) {
|
|
@@ -76,8 +76,10 @@ var PoaBridge = class {
|
|
|
76
76
|
const { tokens } = await this.getCachedSupportedTokens([require_poa_bridge_utils.toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
77
77
|
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
78
78
|
if (tokenInfo == null) throw new require_errors.UnsupportedAssetIdError(args.assetId, "`assetId` is not supported in PoA bridge.");
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
if (!args.skipMinAmountValidation) {
|
|
80
|
+
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
81
|
+
if (args.amount < minWithdrawalAmount) throw new require_errors.MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
82
|
+
}
|
|
81
83
|
if (assetInfo.blockchain === require_caip2.Chains.XRPL) {
|
|
82
84
|
const xrplRpcUrl = this.xrplRpcUrls[0];
|
|
83
85
|
(0, _defuse_protocol_internal_utils.assert)(xrplRpcUrl, "No XRPL RPC URL configured");
|
|
@@ -74,8 +74,10 @@ var PoaBridge = class {
|
|
|
74
74
|
const { tokens } = await this.getCachedSupportedTokens([toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
75
75
|
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
76
76
|
if (tokenInfo == null) throw new UnsupportedAssetIdError(args.assetId, "`assetId` is not supported in PoA bridge.");
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
if (!args.skipMinAmountValidation) {
|
|
78
|
+
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
79
|
+
if (args.amount < minWithdrawalAmount) throw new MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
80
|
+
}
|
|
79
81
|
if (assetInfo.blockchain === Chains.XRPL) {
|
|
80
82
|
const xrplRpcUrl = this.xrplRpcUrls[0];
|
|
81
83
|
assert(xrplRpcUrl, "No XRPL RPC URL configured");
|
package/dist/src/sdk.cjs
CHANGED
|
@@ -220,7 +220,8 @@ var IntentsSDK = class {
|
|
|
220
220
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
221
221
|
feeEstimation: fee,
|
|
222
222
|
routeConfig: args.withdrawalParams.routeConfig,
|
|
223
|
-
logger: args.logger
|
|
223
|
+
logger: args.logger,
|
|
224
|
+
skipMinAmountValidation: args.withdrawalParams.amount === 0n && args.withdrawalParams.feeInclusive === false
|
|
224
225
|
});
|
|
225
226
|
return fee;
|
|
226
227
|
}
|
package/dist/src/sdk.js
CHANGED
|
@@ -218,7 +218,8 @@ var IntentsSDK = class {
|
|
|
218
218
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
219
219
|
feeEstimation: fee,
|
|
220
220
|
routeConfig: args.withdrawalParams.routeConfig,
|
|
221
|
-
logger: args.logger
|
|
221
|
+
logger: args.logger,
|
|
222
|
+
skipMinAmountValidation: args.withdrawalParams.amount === 0n && args.withdrawalParams.feeInclusive === false
|
|
222
223
|
});
|
|
223
224
|
return fee;
|
|
224
225
|
}
|
|
@@ -299,6 +299,7 @@ interface Bridge {
|
|
|
299
299
|
feeEstimation: FeeEstimation;
|
|
300
300
|
routeConfig?: RouteConfig;
|
|
301
301
|
logger?: ILogger;
|
|
302
|
+
skipMinAmountValidation?: boolean;
|
|
302
303
|
}): Promise<void>;
|
|
303
304
|
estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig" | "amount">>(args: {
|
|
304
305
|
withdrawalParams: T;
|
|
@@ -299,6 +299,7 @@ interface Bridge {
|
|
|
299
299
|
feeEstimation: FeeEstimation;
|
|
300
300
|
routeConfig?: RouteConfig;
|
|
301
301
|
logger?: ILogger;
|
|
302
|
+
skipMinAmountValidation?: boolean;
|
|
302
303
|
}): Promise<void>;
|
|
303
304
|
estimateWithdrawalFee<T extends Pick<WithdrawalParams, "assetId" | "destinationAddress" | "routeConfig" | "amount">>(args: {
|
|
304
305
|
withdrawalParams: T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"ripple-address-codec": "^5.0.0",
|
|
46
46
|
"valibot": "^1.0.0",
|
|
47
47
|
"viem": "^2.0.0",
|
|
48
|
-
"@defuse-protocol/contract-types": "0.6.
|
|
49
|
-
"@defuse-protocol/internal-utils": "0.31.
|
|
48
|
+
"@defuse-protocol/contract-types": "0.6.3",
|
|
49
|
+
"@defuse-protocol/internal-utils": "0.31.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"tsdown": "0.19.0"
|