@defuse-protocol/intents-sdk 0.14.0 → 0.15.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 +452 -345
- package/dist/index.cjs +381 -65
- package/dist/index.d.cts +16 -10
- package/dist/index.d.ts +16 -10
- package/dist/index.js +385 -54
- package/package.json +6 -2
package/dist/index.cjs
CHANGED
|
@@ -30,26 +30,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
AssertionError: () =>
|
|
34
|
-
BaseError: () =>
|
|
33
|
+
AssertionError: () => import_internal_utils24.AssertionError,
|
|
34
|
+
BaseError: () => import_internal_utils21.BaseError,
|
|
35
35
|
BridgeNameEnum: () => BridgeNameEnum,
|
|
36
36
|
Chains: () => Chains,
|
|
37
37
|
FeeExceedsAmountError: () => FeeExceedsAmountError,
|
|
38
38
|
HotWithdrawalCancelledError: () => HotWithdrawalCancelledError,
|
|
39
39
|
HotWithdrawalNotFoundError: () => HotWithdrawalNotFoundError,
|
|
40
40
|
HotWithdrawalPendingError: () => HotWithdrawalPendingError,
|
|
41
|
-
HttpRequestError: () =>
|
|
42
|
-
IntentSettlementError: () =>
|
|
41
|
+
HttpRequestError: () => import_internal_utils23.HttpRequestError,
|
|
42
|
+
IntentSettlementError: () => import_internal_utils25.IntentSettlementError,
|
|
43
43
|
IntentsSDK: () => IntentsSDK,
|
|
44
44
|
MinWithdrawalAmountError: () => MinWithdrawalAmountError,
|
|
45
|
-
PoaWithdrawalInvariantError: () =>
|
|
46
|
-
PoaWithdrawalNotFoundError: () =>
|
|
47
|
-
PoaWithdrawalPendingError: () =>
|
|
48
|
-
QuoteError: () =>
|
|
49
|
-
RelayPublishError: () =>
|
|
45
|
+
PoaWithdrawalInvariantError: () => import_internal_utils22.PoaWithdrawalInvariantError,
|
|
46
|
+
PoaWithdrawalNotFoundError: () => import_internal_utils22.PoaWithdrawalNotFoundError,
|
|
47
|
+
PoaWithdrawalPendingError: () => import_internal_utils22.PoaWithdrawalPendingError,
|
|
48
|
+
QuoteError: () => import_internal_utils25.QuoteError,
|
|
49
|
+
RelayPublishError: () => import_internal_utils25.RelayPublishError,
|
|
50
50
|
RouteEnum: () => RouteEnum,
|
|
51
|
-
RpcRequestError: () =>
|
|
52
|
-
TimeoutError: () =>
|
|
51
|
+
RpcRequestError: () => import_internal_utils23.RpcRequestError,
|
|
52
|
+
TimeoutError: () => import_internal_utils23.TimeoutError,
|
|
53
53
|
TrustlineNotFoundError: () => TrustlineNotFoundError,
|
|
54
54
|
UnsupportedDestinationMemoError: () => UnsupportedDestinationMemoError,
|
|
55
55
|
createDefaultRoute: () => createDefaultRoute,
|
|
@@ -65,7 +65,7 @@ __export(index_exports, {
|
|
|
65
65
|
module.exports = __toCommonJS(index_exports);
|
|
66
66
|
|
|
67
67
|
// src/sdk.ts
|
|
68
|
-
var
|
|
68
|
+
var import_internal_utils19 = require("@defuse-protocol/internal-utils");
|
|
69
69
|
var import_omni_sdk3 = __toESM(require("@hot-labs/omni-sdk"), 1);
|
|
70
70
|
var import_viem2 = require("viem");
|
|
71
71
|
|
|
@@ -76,6 +76,7 @@ var import_internal_utils2 = require("@defuse-protocol/internal-utils");
|
|
|
76
76
|
var RouteEnum = {
|
|
77
77
|
HotBridge: "hot_bridge",
|
|
78
78
|
PoaBridge: "poa_bridge",
|
|
79
|
+
OmniBridge: "omni_bridge",
|
|
79
80
|
NearWithdrawal: "near_withdrawal",
|
|
80
81
|
VirtualChain: "virtual_chain",
|
|
81
82
|
InternalTransfer: "internal_transfer"
|
|
@@ -229,6 +230,7 @@ var import_internal_utils5 = require("@defuse-protocol/internal-utils");
|
|
|
229
230
|
var BridgeNameEnum = {
|
|
230
231
|
Hot: "hot",
|
|
231
232
|
Poa: "poa",
|
|
233
|
+
Omni: "omni",
|
|
232
234
|
None: null
|
|
233
235
|
};
|
|
234
236
|
|
|
@@ -236,22 +238,22 @@ var BridgeNameEnum = {
|
|
|
236
238
|
var import_internal_utils3 = require("@defuse-protocol/internal-utils");
|
|
237
239
|
var Chains = {
|
|
238
240
|
Bitcoin: "bip122:000000000019d6689c085ae165831e93",
|
|
241
|
+
Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d",
|
|
242
|
+
Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82",
|
|
239
243
|
Ethereum: "eip155:1",
|
|
240
|
-
|
|
241
|
-
Arbitrum: "eip155:42161",
|
|
244
|
+
Optimism: "eip155:10",
|
|
242
245
|
BNB: "eip155:56",
|
|
246
|
+
Gnosis: "eip155:100",
|
|
243
247
|
Polygon: "eip155:137",
|
|
248
|
+
Base: "eip155:8453",
|
|
249
|
+
Arbitrum: "eip155:42161",
|
|
250
|
+
Avalanche: "eip155:43114",
|
|
251
|
+
Berachain: "eip155:80085",
|
|
244
252
|
Near: "near:mainnet",
|
|
245
253
|
Solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
246
254
|
Tron: "tron:27Lqcw",
|
|
247
|
-
Gnosis: "eip155:100",
|
|
248
255
|
XRPL: "xrpl:0",
|
|
249
|
-
Dogecoin: "bip122:1a91e3dace36e2be3bf030a65679fe82",
|
|
250
|
-
Zcash: "zcash:0",
|
|
251
|
-
Berachain: "eip155:80085",
|
|
252
256
|
TON: "tvm:-239",
|
|
253
|
-
Optimism: "eip155:10",
|
|
254
|
-
Avalanche: "eip155:43114",
|
|
255
257
|
Sui: "sui:mainnet",
|
|
256
258
|
Aptos: "aptos:mainnet",
|
|
257
259
|
Stellar: "stellar:pubnet",
|
|
@@ -809,14 +811,318 @@ var IntentsBridge = class {
|
|
|
809
811
|
}
|
|
810
812
|
};
|
|
811
813
|
|
|
812
|
-
// src/bridges/
|
|
813
|
-
var
|
|
814
|
+
// src/bridges/omni-bridge/omni-bridge.ts
|
|
815
|
+
var import_internal_utils12 = require("@defuse-protocol/internal-utils");
|
|
814
816
|
var import_ttlcache = __toESM(require("@isaacs/ttlcache"), 1);
|
|
817
|
+
var import_attempt2 = require("@lifeomic/attempt");
|
|
818
|
+
var import_omni_bridge_sdk2 = require("omni-bridge-sdk");
|
|
815
819
|
|
|
816
|
-
// src/bridges/
|
|
820
|
+
// src/bridges/omni-bridge/error.ts
|
|
817
821
|
var import_internal_utils10 = require("@defuse-protocol/internal-utils");
|
|
822
|
+
var OmniTransferNotFoundError = class extends import_internal_utils10.BaseError {
|
|
823
|
+
constructor(txHash) {
|
|
824
|
+
super("Omni transfer with given hash is not found in the relayer.", {
|
|
825
|
+
metaMessages: [`OriginTxHash: ${txHash}`],
|
|
826
|
+
name: "OmniTransferNotFoundError"
|
|
827
|
+
});
|
|
828
|
+
this.txHash = txHash;
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
var OmniTransferDestinationChainHashNotFoundError = class extends import_internal_utils10.BaseError {
|
|
832
|
+
constructor(txHash, destinationChain) {
|
|
833
|
+
super("Relayer did not return destination chain hash for a transfer.", {
|
|
834
|
+
metaMessages: [
|
|
835
|
+
`OriginTxHash: ${txHash}`,
|
|
836
|
+
`DestinationChain: ${destinationChain}`
|
|
837
|
+
],
|
|
838
|
+
name: "OmniTransferDestinationChainHashNotFoundError"
|
|
839
|
+
});
|
|
840
|
+
this.txHash = txHash;
|
|
841
|
+
this.destinationChain = destinationChain;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils10.BaseError {
|
|
845
|
+
constructor(token) {
|
|
846
|
+
super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
|
|
847
|
+
metaMessages: [`Token: ${token}`],
|
|
848
|
+
name: "TokenNotSupportedByOmniRelayerError"
|
|
849
|
+
});
|
|
850
|
+
this.token = token;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
855
|
+
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
856
|
+
var OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
857
|
+
|
|
858
|
+
// src/bridges/omni-bridge/omni-bridge-utils.ts
|
|
859
|
+
var import_internal_utils11 = require("@defuse-protocol/internal-utils");
|
|
860
|
+
var import_omni_bridge_sdk = require("omni-bridge-sdk");
|
|
818
861
|
function createWithdrawIntentPrimitive3(params) {
|
|
819
|
-
const { contractId: tokenAccountId } =
|
|
862
|
+
const { contractId: tokenAccountId, standard } = import_internal_utils11.utils.parseDefuseAssetId(
|
|
863
|
+
params.assetId
|
|
864
|
+
);
|
|
865
|
+
(0, import_internal_utils11.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
866
|
+
return {
|
|
867
|
+
intent: "ft_withdraw",
|
|
868
|
+
token: tokenAccountId,
|
|
869
|
+
receiver_id: OMNI_BRIDGE_CONTRACT,
|
|
870
|
+
amount: params.amount.toString(),
|
|
871
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : null,
|
|
872
|
+
msg: JSON.stringify({
|
|
873
|
+
recipient: (0, import_omni_bridge_sdk.omniAddress)(
|
|
874
|
+
caip2ToChainKind(params.origin),
|
|
875
|
+
params.destinationAddress
|
|
876
|
+
),
|
|
877
|
+
fee: params.transferredTokenFee.toString(),
|
|
878
|
+
native_token_fee: "0"
|
|
879
|
+
})
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
function caip2ToChainKind(network) {
|
|
883
|
+
switch (network) {
|
|
884
|
+
case Chains.Ethereum:
|
|
885
|
+
return import_omni_bridge_sdk.ChainKind.Eth;
|
|
886
|
+
case Chains.Base:
|
|
887
|
+
return import_omni_bridge_sdk.ChainKind.Base;
|
|
888
|
+
case Chains.Arbitrum:
|
|
889
|
+
return import_omni_bridge_sdk.ChainKind.Arb;
|
|
890
|
+
case Chains.Solana:
|
|
891
|
+
return import_omni_bridge_sdk.ChainKind.Sol;
|
|
892
|
+
case Chains.Bitcoin:
|
|
893
|
+
return import_omni_bridge_sdk.ChainKind.Btc;
|
|
894
|
+
default:
|
|
895
|
+
throw new Error(`Unsupported Omni network = ${network}`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function chainKindToCaip2(network) {
|
|
899
|
+
switch (network) {
|
|
900
|
+
case import_omni_bridge_sdk.ChainKind.Eth:
|
|
901
|
+
return Chains.Ethereum;
|
|
902
|
+
case import_omni_bridge_sdk.ChainKind.Base:
|
|
903
|
+
return Chains.Base;
|
|
904
|
+
case import_omni_bridge_sdk.ChainKind.Arb:
|
|
905
|
+
return Chains.Arbitrum;
|
|
906
|
+
case import_omni_bridge_sdk.ChainKind.Sol:
|
|
907
|
+
return Chains.Solana;
|
|
908
|
+
case import_omni_bridge_sdk.ChainKind.Btc:
|
|
909
|
+
return Chains.Bitcoin;
|
|
910
|
+
default:
|
|
911
|
+
throw new Error(`Unsupported Caip2 network = ${network}`);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// src/bridges/omni-bridge/omni-bridge.ts
|
|
916
|
+
var _OmniBridge = class _OmniBridge {
|
|
917
|
+
// 86400000 - 1 day
|
|
918
|
+
constructor({
|
|
919
|
+
env,
|
|
920
|
+
nearProvider
|
|
921
|
+
}) {
|
|
922
|
+
this.storageDepositCache = new import_ttlcache.default({ ttl: 864e5 });
|
|
923
|
+
// TTL cache for supported tokens with 30-second TTL
|
|
924
|
+
this.supportedTokensCache = new import_ttlcache.default({ ttl: 864e5 });
|
|
925
|
+
this.env = env;
|
|
926
|
+
this.nearProvider = nearProvider;
|
|
927
|
+
this.omniBridgeAPI = new import_omni_bridge_sdk2.OmniBridgeAPI();
|
|
928
|
+
}
|
|
929
|
+
is(routeConfig) {
|
|
930
|
+
return routeConfig.route === RouteEnum.OmniBridge;
|
|
931
|
+
}
|
|
932
|
+
supports(params) {
|
|
933
|
+
try {
|
|
934
|
+
return this.parseAssetId(params.assetId) !== null;
|
|
935
|
+
} catch {
|
|
936
|
+
return false;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
parseAssetId(assetId) {
|
|
940
|
+
const parsed = import_internal_utils12.utils.parseDefuseAssetId(assetId);
|
|
941
|
+
if (parsed.standard !== "nep141") return null;
|
|
942
|
+
const chain = (0, import_omni_bridge_sdk2.parseOriginChain)(parsed.contractId);
|
|
943
|
+
if (chain === null) return null;
|
|
944
|
+
return Object.assign(parsed, {
|
|
945
|
+
blockchain: chainKindToCaip2(chain),
|
|
946
|
+
bridgeName: BridgeNameEnum.Omni,
|
|
947
|
+
address: parsed.contractId
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
createWithdrawalIntents(args) {
|
|
951
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
952
|
+
(0, import_internal_utils12.assert)(
|
|
953
|
+
assetInfo !== null,
|
|
954
|
+
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
955
|
+
);
|
|
956
|
+
const intents = [];
|
|
957
|
+
if (args.feeEstimation.quote !== null) {
|
|
958
|
+
intents.push({
|
|
959
|
+
intent: "token_diff",
|
|
960
|
+
diff: {
|
|
961
|
+
[args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
|
|
962
|
+
[args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
|
|
963
|
+
},
|
|
964
|
+
referral: args.referral
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
const intent = createWithdrawIntentPrimitive3({
|
|
968
|
+
assetId: args.withdrawalParams.assetId,
|
|
969
|
+
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
970
|
+
amount: args.withdrawalParams.amount + args.feeEstimation.amount,
|
|
971
|
+
origin: assetInfo.blockchain,
|
|
972
|
+
storageDeposit: args.feeEstimation.quote ? BigInt(args.feeEstimation.quote.amount_out) : 0n,
|
|
973
|
+
transferredTokenFee: args.feeEstimation.amount
|
|
974
|
+
});
|
|
975
|
+
intents.push(intent);
|
|
976
|
+
return Promise.resolve(intents);
|
|
977
|
+
}
|
|
978
|
+
async validateWithdrawal(args) {
|
|
979
|
+
const assetInfo = this.parseAssetId(args.assetId);
|
|
980
|
+
(0, import_internal_utils12.assert)(assetInfo !== null, `Asset ${args.assetId} is not supported`);
|
|
981
|
+
const supportedTokens = await this.getCachedSupportedTokens();
|
|
982
|
+
if (!supportedTokens[assetInfo.contractId]) {
|
|
983
|
+
throw new TokenNotSupportedByOmniRelayerError(args.assetId);
|
|
984
|
+
}
|
|
985
|
+
(0, import_internal_utils12.assert)(
|
|
986
|
+
args.feeEstimation.amount > 0n,
|
|
987
|
+
`Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
|
|
988
|
+
);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
async estimateWithdrawalFee(args) {
|
|
992
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
993
|
+
(0, import_internal_utils12.assert)(
|
|
994
|
+
assetInfo !== null,
|
|
995
|
+
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
996
|
+
);
|
|
997
|
+
const fee = await this.omniBridgeAPI.getFee(
|
|
998
|
+
(0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, import_internal_utils12.configsByEnvironment[this.env].contractID),
|
|
999
|
+
(0, import_omni_bridge_sdk2.omniAddress)(
|
|
1000
|
+
caip2ToChainKind(assetInfo.blockchain),
|
|
1001
|
+
args.withdrawalParams.destinationAddress
|
|
1002
|
+
),
|
|
1003
|
+
(0, import_omni_bridge_sdk2.omniAddress)(import_omni_bridge_sdk2.ChainKind.Near, assetInfo.contractId)
|
|
1004
|
+
);
|
|
1005
|
+
(0, import_internal_utils12.assert)(
|
|
1006
|
+
fee.transferred_token_fee !== null,
|
|
1007
|
+
`Asset ${args.withdrawalParams.assetId} is not supported by the relayer`
|
|
1008
|
+
);
|
|
1009
|
+
const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(assetInfo.contractId);
|
|
1010
|
+
if (minStorageBalance <= userStorageBalance) {
|
|
1011
|
+
return {
|
|
1012
|
+
amount: BigInt(fee.transferred_token_fee),
|
|
1013
|
+
quote: null
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
const feeAmount = minStorageBalance - userStorageBalance;
|
|
1017
|
+
const feeQuote = await import_internal_utils12.solverRelay.getQuote({
|
|
1018
|
+
quoteParams: {
|
|
1019
|
+
defuse_asset_identifier_in: args.withdrawalParams.assetId,
|
|
1020
|
+
defuse_asset_identifier_out: NEAR_NATIVE_ASSET_ID3,
|
|
1021
|
+
exact_amount_out: feeAmount.toString(),
|
|
1022
|
+
wait_ms: args.quoteOptions?.waitMs
|
|
1023
|
+
},
|
|
1024
|
+
config: {
|
|
1025
|
+
baseURL: import_internal_utils12.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
1026
|
+
logBalanceSufficient: false,
|
|
1027
|
+
logger: args.logger
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
return {
|
|
1031
|
+
amount: BigInt(fee.transferred_token_fee) + BigInt(feeQuote.amount_in),
|
|
1032
|
+
quote: feeQuote
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
async waitForWithdrawalCompletion(args) {
|
|
1036
|
+
return (0, import_attempt2.retry)(
|
|
1037
|
+
async () => {
|
|
1038
|
+
if (args.signal?.aborted) {
|
|
1039
|
+
throw args.signal.reason;
|
|
1040
|
+
}
|
|
1041
|
+
const transfer = (await this.omniBridgeAPI.findOmniTransfers({
|
|
1042
|
+
transaction_id: args.tx.hash,
|
|
1043
|
+
offset: args.index,
|
|
1044
|
+
limit: 1
|
|
1045
|
+
}))[0];
|
|
1046
|
+
if (!transfer) throw new OmniTransferNotFoundError(args.tx.hash);
|
|
1047
|
+
const destinationChain = (0, import_omni_bridge_sdk2.getChain)(
|
|
1048
|
+
transfer.transfer_message.recipient
|
|
1049
|
+
);
|
|
1050
|
+
let txHash = null;
|
|
1051
|
+
if ((0, import_omni_bridge_sdk2.isEvmChain)(destinationChain)) {
|
|
1052
|
+
txHash = transfer.finalised?.EVMLog?.transaction_hash;
|
|
1053
|
+
} else if (destinationChain === import_omni_bridge_sdk2.ChainKind.Sol) {
|
|
1054
|
+
txHash = transfer.finalised?.Solana?.signature;
|
|
1055
|
+
} else {
|
|
1056
|
+
return { hash: null };
|
|
1057
|
+
}
|
|
1058
|
+
if (!txHash)
|
|
1059
|
+
throw new OmniTransferDestinationChainHashNotFoundError(
|
|
1060
|
+
args.tx.hash,
|
|
1061
|
+
import_omni_bridge_sdk2.ChainKind[destinationChain].toLowerCase()
|
|
1062
|
+
);
|
|
1063
|
+
return { hash: txHash };
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
...args.retryOptions ?? import_internal_utils12.RETRY_CONFIGS.TWO_MINS_GRADUAL,
|
|
1067
|
+
handleError: (err, ctx) => {
|
|
1068
|
+
if (err instanceof OmniTransferNotFoundError || err === args.signal?.reason) {
|
|
1069
|
+
ctx.abort();
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
1077
|
+
* Cache expires after one day using TTL cache.
|
|
1078
|
+
*/
|
|
1079
|
+
async getCachedStorageDepositValue(contractId) {
|
|
1080
|
+
const cached = this.storageDepositCache.get(contractId);
|
|
1081
|
+
if (cached != null) {
|
|
1082
|
+
return cached;
|
|
1083
|
+
}
|
|
1084
|
+
const data = await Promise.all([
|
|
1085
|
+
(0, import_internal_utils12.getNearNep141MinStorageBalance)({
|
|
1086
|
+
contractId,
|
|
1087
|
+
nearProvider: this.nearProvider
|
|
1088
|
+
}),
|
|
1089
|
+
(0, import_internal_utils12.getNearNep141StorageBalance)({
|
|
1090
|
+
contractId,
|
|
1091
|
+
accountId: OMNI_BRIDGE_CONTRACT,
|
|
1092
|
+
nearProvider: this.nearProvider
|
|
1093
|
+
})
|
|
1094
|
+
]);
|
|
1095
|
+
this.storageDepositCache.set(contractId, data);
|
|
1096
|
+
return data;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Gets cached tokens supported by the omni relayer, tokens not listed there can't be transferred.
|
|
1100
|
+
* Cache expires after one day using TTL cache.
|
|
1101
|
+
*/
|
|
1102
|
+
async getCachedSupportedTokens() {
|
|
1103
|
+
const cached = this.supportedTokensCache.get(
|
|
1104
|
+
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY
|
|
1105
|
+
);
|
|
1106
|
+
if (cached != null) {
|
|
1107
|
+
return cached;
|
|
1108
|
+
}
|
|
1109
|
+
const data = await this.omniBridgeAPI.getAllowlistedTokens();
|
|
1110
|
+
this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
|
|
1111
|
+
return data;
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
// 86400000 - 1 day
|
|
1115
|
+
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
|
|
1116
|
+
var OmniBridge = _OmniBridge;
|
|
1117
|
+
|
|
1118
|
+
// src/bridges/poa-bridge/poa-bridge.ts
|
|
1119
|
+
var import_internal_utils14 = require("@defuse-protocol/internal-utils");
|
|
1120
|
+
var import_ttlcache2 = __toESM(require("@isaacs/ttlcache"), 1);
|
|
1121
|
+
|
|
1122
|
+
// src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
1123
|
+
var import_internal_utils13 = require("@defuse-protocol/internal-utils");
|
|
1124
|
+
function createWithdrawIntentPrimitive4(params) {
|
|
1125
|
+
const { contractId: tokenAccountId } = import_internal_utils13.utils.parseDefuseAssetId(
|
|
820
1126
|
params.assetId
|
|
821
1127
|
);
|
|
822
1128
|
return {
|
|
@@ -891,7 +1197,7 @@ function contractIdToCaip2(contractId) {
|
|
|
891
1197
|
var PoaBridge = class {
|
|
892
1198
|
constructor({ env }) {
|
|
893
1199
|
// TTL cache for supported tokens with 30-second TTL
|
|
894
|
-
this.supportedTokensCache = new
|
|
1200
|
+
this.supportedTokensCache = new import_ttlcache2.default({ ttl: 30 * 1e3 });
|
|
895
1201
|
this.env = env;
|
|
896
1202
|
}
|
|
897
1203
|
is(routeConfig) {
|
|
@@ -909,9 +1215,9 @@ var PoaBridge = class {
|
|
|
909
1215
|
}
|
|
910
1216
|
}
|
|
911
1217
|
parseAssetId(assetId) {
|
|
912
|
-
const parsed =
|
|
1218
|
+
const parsed = import_internal_utils14.utils.parseDefuseAssetId(assetId);
|
|
913
1219
|
if (parsed.contractId.endsWith(
|
|
914
|
-
`.${
|
|
1220
|
+
`.${import_internal_utils14.configsByEnvironment[this.env].poaTokenFactoryContractID}`
|
|
915
1221
|
)) {
|
|
916
1222
|
return Object.assign(parsed, {
|
|
917
1223
|
blockchain: contractIdToCaip2(parsed.contractId),
|
|
@@ -923,7 +1229,7 @@ var PoaBridge = class {
|
|
|
923
1229
|
return null;
|
|
924
1230
|
}
|
|
925
1231
|
createWithdrawalIntents(args) {
|
|
926
|
-
const intent =
|
|
1232
|
+
const intent = createWithdrawIntentPrimitive4({
|
|
927
1233
|
...args.withdrawalParams,
|
|
928
1234
|
amount: args.withdrawalParams.amount + args.feeEstimation.amount,
|
|
929
1235
|
destinationMemo: args.withdrawalParams.destinationMemo
|
|
@@ -938,7 +1244,7 @@ var PoaBridge = class {
|
|
|
938
1244
|
*/
|
|
939
1245
|
async validateWithdrawal(args) {
|
|
940
1246
|
const assetInfo = this.parseAssetId(args.assetId);
|
|
941
|
-
(0,
|
|
1247
|
+
(0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
|
|
942
1248
|
const { tokens } = await this.getCachedSupportedTokens(
|
|
943
1249
|
[toPoaNetwork(assetInfo.blockchain)],
|
|
944
1250
|
args.logger
|
|
@@ -959,16 +1265,16 @@ var PoaBridge = class {
|
|
|
959
1265
|
}
|
|
960
1266
|
async estimateWithdrawalFee(args) {
|
|
961
1267
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
962
|
-
(0,
|
|
963
|
-
const estimation = await
|
|
1268
|
+
(0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
|
|
1269
|
+
const estimation = await import_internal_utils14.poaBridge.httpClient.getWithdrawalEstimate(
|
|
964
1270
|
{
|
|
965
|
-
token:
|
|
1271
|
+
token: import_internal_utils14.utils.getTokenAccountId(args.withdrawalParams.assetId),
|
|
966
1272
|
address: args.withdrawalParams.destinationAddress,
|
|
967
1273
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
968
1274
|
chain: toPoaNetwork(assetInfo.blockchain)
|
|
969
1275
|
},
|
|
970
1276
|
{
|
|
971
|
-
baseURL:
|
|
1277
|
+
baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
|
|
972
1278
|
logger: args.logger
|
|
973
1279
|
}
|
|
974
1280
|
);
|
|
@@ -978,12 +1284,12 @@ var PoaBridge = class {
|
|
|
978
1284
|
};
|
|
979
1285
|
}
|
|
980
1286
|
async waitForWithdrawalCompletion(args) {
|
|
981
|
-
const withdrawalStatus = await
|
|
1287
|
+
const withdrawalStatus = await import_internal_utils14.poaBridge.waitForWithdrawalCompletion({
|
|
982
1288
|
txHash: args.tx.hash,
|
|
983
1289
|
index: args.index,
|
|
984
1290
|
signal: args.signal ?? new AbortController().signal,
|
|
985
1291
|
retryOptions: args.retryOptions,
|
|
986
|
-
baseURL:
|
|
1292
|
+
baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
|
|
987
1293
|
logger: args.logger
|
|
988
1294
|
});
|
|
989
1295
|
return { hash: withdrawalStatus.destinationTxHash };
|
|
@@ -998,10 +1304,10 @@ var PoaBridge = class {
|
|
|
998
1304
|
if (cached != null) {
|
|
999
1305
|
return cached;
|
|
1000
1306
|
}
|
|
1001
|
-
const data = await
|
|
1307
|
+
const data = await import_internal_utils14.poaBridge.httpClient.getSupportedTokens(
|
|
1002
1308
|
{ chains },
|
|
1003
1309
|
{
|
|
1004
|
-
baseURL:
|
|
1310
|
+
baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
|
|
1005
1311
|
logger
|
|
1006
1312
|
}
|
|
1007
1313
|
);
|
|
@@ -1023,7 +1329,7 @@ var PUBLIC_STELLAR_RPC_URLS = {
|
|
|
1023
1329
|
};
|
|
1024
1330
|
|
|
1025
1331
|
// src/intents/intent-executer-impl/intent-executer.ts
|
|
1026
|
-
var
|
|
1332
|
+
var import_internal_utils15 = require("@defuse-protocol/internal-utils");
|
|
1027
1333
|
|
|
1028
1334
|
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
|
|
1029
1335
|
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
@@ -1404,7 +1710,7 @@ var IntentExecuter = class {
|
|
|
1404
1710
|
relayParams: relayParamsFactory,
|
|
1405
1711
|
...intentParams
|
|
1406
1712
|
}) {
|
|
1407
|
-
const verifyingContract =
|
|
1713
|
+
const verifyingContract = import_internal_utils15.configsByEnvironment[this.env].contractID;
|
|
1408
1714
|
let intentPayload = defaultIntentPayloadFactory({
|
|
1409
1715
|
verifying_contract: verifyingContract,
|
|
1410
1716
|
...intentParams
|
|
@@ -1454,7 +1760,7 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
|
|
|
1454
1760
|
}
|
|
1455
1761
|
|
|
1456
1762
|
// src/intents/intent-relayer-impl/intent-relayer-public.ts
|
|
1457
|
-
var
|
|
1763
|
+
var import_internal_utils16 = require("@defuse-protocol/internal-utils");
|
|
1458
1764
|
var IntentRelayerPublic = class {
|
|
1459
1765
|
constructor({ env }) {
|
|
1460
1766
|
this.env = env;
|
|
@@ -1476,13 +1782,13 @@ var IntentRelayerPublic = class {
|
|
|
1476
1782
|
multiPayloads,
|
|
1477
1783
|
quoteHashes
|
|
1478
1784
|
}, ctx = {}) {
|
|
1479
|
-
const a = await
|
|
1785
|
+
const a = await import_internal_utils16.solverRelay.publishIntents(
|
|
1480
1786
|
{
|
|
1481
1787
|
quote_hashes: quoteHashes,
|
|
1482
1788
|
signed_datas: multiPayloads
|
|
1483
1789
|
},
|
|
1484
1790
|
{
|
|
1485
|
-
baseURL:
|
|
1791
|
+
baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
1486
1792
|
logger: ctx.logger
|
|
1487
1793
|
}
|
|
1488
1794
|
);
|
|
@@ -1492,10 +1798,10 @@ var IntentRelayerPublic = class {
|
|
|
1492
1798
|
throw a.unwrapErr();
|
|
1493
1799
|
}
|
|
1494
1800
|
async waitForSettlement(ticket, ctx = {}) {
|
|
1495
|
-
const result = await
|
|
1801
|
+
const result = await import_internal_utils16.solverRelay.waitForIntentSettlement({
|
|
1496
1802
|
intentHash: ticket,
|
|
1497
1803
|
signal: new AbortController().signal,
|
|
1498
|
-
baseURL:
|
|
1804
|
+
baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
1499
1805
|
logger: ctx.logger
|
|
1500
1806
|
});
|
|
1501
1807
|
return {
|
|
@@ -1503,7 +1809,7 @@ var IntentRelayerPublic = class {
|
|
|
1503
1809
|
hash: result.txHash,
|
|
1504
1810
|
// Usually relayer's account id is the verifying contract (`intents.near`),
|
|
1505
1811
|
// but it is not set in stone and may change in the future.
|
|
1506
|
-
accountId:
|
|
1812
|
+
accountId: import_internal_utils16.configsByEnvironment[this.env].contractID
|
|
1507
1813
|
}
|
|
1508
1814
|
};
|
|
1509
1815
|
}
|
|
@@ -1517,14 +1823,14 @@ var noopIntentSigner = {
|
|
|
1517
1823
|
};
|
|
1518
1824
|
|
|
1519
1825
|
// src/lib/array.ts
|
|
1520
|
-
var
|
|
1826
|
+
var import_internal_utils17 = require("@defuse-protocol/internal-utils");
|
|
1521
1827
|
function zip(arr1, arr2) {
|
|
1522
|
-
(0,
|
|
1828
|
+
(0, import_internal_utils17.assert)(arr1.length === arr2.length, "Arrays must have the same length");
|
|
1523
1829
|
return arr1.map((v, i) => [v, arr2[i]]);
|
|
1524
1830
|
}
|
|
1525
1831
|
|
|
1526
1832
|
// src/lib/configure-rpc-config.ts
|
|
1527
|
-
var
|
|
1833
|
+
var import_internal_utils18 = require("@defuse-protocol/internal-utils");
|
|
1528
1834
|
|
|
1529
1835
|
// src/lib/object.ts
|
|
1530
1836
|
function pick(obj, keys) {
|
|
@@ -1548,7 +1854,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
|
|
|
1548
1854
|
).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
|
|
1549
1855
|
);
|
|
1550
1856
|
for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
|
|
1551
|
-
(0,
|
|
1857
|
+
(0, import_internal_utils18.assert)(
|
|
1552
1858
|
urls.length > 0,
|
|
1553
1859
|
`EVM RPC URLs for chain ${chainId} are not provided`
|
|
1554
1860
|
);
|
|
@@ -1562,7 +1868,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
|
|
|
1562
1868
|
userRpcUrls?.[Chains.Stellar] ?? {}
|
|
1563
1869
|
);
|
|
1564
1870
|
for (const [key, value] of Object.entries(stellarRpcUrls)) {
|
|
1565
|
-
(0,
|
|
1871
|
+
(0, import_internal_utils18.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
|
|
1566
1872
|
}
|
|
1567
1873
|
return stellarRpcUrls;
|
|
1568
1874
|
}
|
|
@@ -1574,6 +1880,9 @@ function createInternalTransferRoute() {
|
|
|
1574
1880
|
function createNearWithdrawalRoute(msg) {
|
|
1575
1881
|
return { route: RouteEnum.NearWithdrawal, msg };
|
|
1576
1882
|
}
|
|
1883
|
+
function createOmniWithdrawalRoute() {
|
|
1884
|
+
return { route: RouteEnum.OmniBridge };
|
|
1885
|
+
}
|
|
1577
1886
|
function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
|
|
1578
1887
|
return {
|
|
1579
1888
|
route: RouteEnum.VirtualChain,
|
|
@@ -1614,6 +1923,8 @@ function determineRouteConfig(sdk, withdrawalParams) {
|
|
|
1614
1923
|
route: RouteEnum.PoaBridge,
|
|
1615
1924
|
chain: parseAssetId.blockchain
|
|
1616
1925
|
};
|
|
1926
|
+
case BridgeNameEnum.Omni:
|
|
1927
|
+
return createOmniWithdrawalRoute();
|
|
1617
1928
|
case BridgeNameEnum.None:
|
|
1618
1929
|
return createNearWithdrawalRoute();
|
|
1619
1930
|
default:
|
|
@@ -1627,9 +1938,9 @@ var IntentsSDK = class {
|
|
|
1627
1938
|
constructor(args) {
|
|
1628
1939
|
this.env = args.env ?? "production";
|
|
1629
1940
|
this.referral = args.referral;
|
|
1630
|
-
const nearRpcUrls = args.rpc?.[Chains.Near] ??
|
|
1631
|
-
(0,
|
|
1632
|
-
const nearProvider = (0,
|
|
1941
|
+
const nearRpcUrls = args.rpc?.[Chains.Near] ?? import_internal_utils19.PUBLIC_NEAR_RPC_URLS;
|
|
1942
|
+
(0, import_internal_utils19.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
|
|
1943
|
+
const nearProvider = (0, import_internal_utils19.nearFailoverRpcProvider)({ urls: nearRpcUrls });
|
|
1633
1944
|
const stellarRpcUrls = configureStellarRpcUrls(
|
|
1634
1945
|
PUBLIC_STELLAR_RPC_URLS,
|
|
1635
1946
|
args.rpc
|
|
@@ -1661,6 +1972,10 @@ var IntentsSDK = class {
|
|
|
1661
1972
|
}
|
|
1662
1973
|
})
|
|
1663
1974
|
}),
|
|
1975
|
+
new OmniBridge({
|
|
1976
|
+
env: this.env,
|
|
1977
|
+
nearProvider
|
|
1978
|
+
}),
|
|
1664
1979
|
new DirectBridge({
|
|
1665
1980
|
env: this.env,
|
|
1666
1981
|
nearProvider
|
|
@@ -1680,6 +1995,7 @@ var IntentsSDK = class {
|
|
|
1680
1995
|
assetId: args.withdrawalParams.assetId,
|
|
1681
1996
|
amount: actualAmount,
|
|
1682
1997
|
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
1998
|
+
feeEstimation: args.feeEstimation,
|
|
1683
1999
|
logger: args.logger
|
|
1684
2000
|
});
|
|
1685
2001
|
return bridge.createWithdrawalIntents({
|
|
@@ -1749,7 +2065,7 @@ var IntentsSDK = class {
|
|
|
1749
2065
|
const routeConfig = determineRouteConfig(this, w);
|
|
1750
2066
|
const route = routeConfig.route;
|
|
1751
2067
|
const index = indexes.get(route);
|
|
1752
|
-
(0,
|
|
2068
|
+
(0, import_internal_utils19.assert)(index != null, "Index is not found for route");
|
|
1753
2069
|
indexes.set(route, index + 1);
|
|
1754
2070
|
return {
|
|
1755
2071
|
routeConfig,
|
|
@@ -1783,7 +2099,7 @@ var IntentsSDK = class {
|
|
|
1783
2099
|
if (Array.isArray(args.withdrawalParams)) {
|
|
1784
2100
|
return result;
|
|
1785
2101
|
}
|
|
1786
|
-
(0,
|
|
2102
|
+
(0, import_internal_utils19.assert)(result.length === 1, "Unexpected result length");
|
|
1787
2103
|
return result[0];
|
|
1788
2104
|
}
|
|
1789
2105
|
parseAssetId(assetId) {
|
|
@@ -1797,7 +2113,7 @@ var IntentsSDK = class {
|
|
|
1797
2113
|
}
|
|
1798
2114
|
async signAndSendIntent(args) {
|
|
1799
2115
|
const intentSigner = args.signer ?? this.intentSigner;
|
|
1800
|
-
(0,
|
|
2116
|
+
(0, import_internal_utils19.assert)(intentSigner != null, "Intent signer is not provided");
|
|
1801
2117
|
const intentExecuter = new IntentExecuter({
|
|
1802
2118
|
env: this.env,
|
|
1803
2119
|
logger: args.logger,
|
|
@@ -1866,12 +2182,12 @@ var IntentsSDK = class {
|
|
|
1866
2182
|
intentHash,
|
|
1867
2183
|
logger
|
|
1868
2184
|
}) {
|
|
1869
|
-
return
|
|
2185
|
+
return import_internal_utils19.solverRelay.getStatus(
|
|
1870
2186
|
{
|
|
1871
2187
|
intent_hash: intentHash
|
|
1872
2188
|
},
|
|
1873
2189
|
{
|
|
1874
|
-
baseURL:
|
|
2190
|
+
baseURL: import_internal_utils19.configsByEnvironment[this.env].solverRelayBaseURL,
|
|
1875
2191
|
logger
|
|
1876
2192
|
}
|
|
1877
2193
|
);
|
|
@@ -1902,7 +2218,7 @@ var IntentsSDK = class {
|
|
|
1902
2218
|
withdrawalParams,
|
|
1903
2219
|
intentTx,
|
|
1904
2220
|
logger: args.logger,
|
|
1905
|
-
retryOptions:
|
|
2221
|
+
retryOptions: import_internal_utils19.RETRY_CONFIGS.FIVE_MINS_STEADY
|
|
1906
2222
|
});
|
|
1907
2223
|
if (!Array.isArray(args.withdrawalParams)) {
|
|
1908
2224
|
return {
|
|
@@ -1981,14 +2297,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
|
|
|
1981
2297
|
};
|
|
1982
2298
|
|
|
1983
2299
|
// src/intents/intent-signer-impl/intent-signer-viem.ts
|
|
1984
|
-
var
|
|
2300
|
+
var import_internal_utils20 = require("@defuse-protocol/internal-utils");
|
|
1985
2301
|
var IntentSignerViem = class {
|
|
1986
2302
|
constructor(account) {
|
|
1987
2303
|
this.account = account;
|
|
1988
2304
|
}
|
|
1989
2305
|
async signIntent(intent) {
|
|
1990
2306
|
const payload = JSON.stringify({
|
|
1991
|
-
signer_id: intent.signer_id ??
|
|
2307
|
+
signer_id: intent.signer_id ?? import_internal_utils20.utils.authHandleToIntentsUserId({
|
|
1992
2308
|
identifier: this.account.address,
|
|
1993
2309
|
method: "evm"
|
|
1994
2310
|
}),
|
|
@@ -2006,7 +2322,7 @@ var IntentSignerViem = class {
|
|
|
2006
2322
|
return {
|
|
2007
2323
|
standard: "erc191",
|
|
2008
2324
|
payload,
|
|
2009
|
-
signature:
|
|
2325
|
+
signature: import_internal_utils20.utils.transformERC191Signature(signature)
|
|
2010
2326
|
};
|
|
2011
2327
|
}
|
|
2012
2328
|
};
|
|
@@ -2023,11 +2339,11 @@ function createIntentSignerViem(config) {
|
|
|
2023
2339
|
}
|
|
2024
2340
|
|
|
2025
2341
|
// index.ts
|
|
2026
|
-
var import_internal_utils18 = require("@defuse-protocol/internal-utils");
|
|
2027
|
-
var import_internal_utils19 = require("@defuse-protocol/internal-utils");
|
|
2028
|
-
var import_internal_utils20 = require("@defuse-protocol/internal-utils");
|
|
2029
2342
|
var import_internal_utils21 = require("@defuse-protocol/internal-utils");
|
|
2030
2343
|
var import_internal_utils22 = require("@defuse-protocol/internal-utils");
|
|
2344
|
+
var import_internal_utils23 = require("@defuse-protocol/internal-utils");
|
|
2345
|
+
var import_internal_utils24 = require("@defuse-protocol/internal-utils");
|
|
2346
|
+
var import_internal_utils25 = require("@defuse-protocol/internal-utils");
|
|
2031
2347
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2032
2348
|
0 && (module.exports = {
|
|
2033
2349
|
AssertionError,
|