@defuse-protocol/intents-sdk 0.16.2 → 0.16.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 +108 -453
- package/dist/index.js +96 -457
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/sdk.ts
|
|
2
2
|
import {
|
|
3
|
-
assert as
|
|
3
|
+
assert as assert11,
|
|
4
4
|
PUBLIC_NEAR_RPC_URLS,
|
|
5
|
-
RETRY_CONFIGS as
|
|
6
|
-
configsByEnvironment as
|
|
5
|
+
RETRY_CONFIGS as RETRY_CONFIGS2,
|
|
6
|
+
configsByEnvironment as configsByEnvironment7,
|
|
7
7
|
nearFailoverRpcProvider,
|
|
8
|
-
solverRelay as
|
|
8
|
+
solverRelay as solverRelay5
|
|
9
9
|
} from "@defuse-protocol/internal-utils";
|
|
10
10
|
import hotOmniSdk from "@hot-labs/omni-sdk";
|
|
11
11
|
import { stringify } from "viem";
|
|
@@ -772,428 +772,19 @@ var IntentsBridge = class {
|
|
|
772
772
|
}
|
|
773
773
|
};
|
|
774
774
|
|
|
775
|
-
// src/bridges/
|
|
775
|
+
// src/bridges/poa-bridge/poa-bridge.ts
|
|
776
776
|
import {
|
|
777
|
-
assert as
|
|
778
|
-
RETRY_CONFIGS as RETRY_CONFIGS2,
|
|
777
|
+
assert as assert8,
|
|
779
778
|
configsByEnvironment as configsByEnvironment4,
|
|
780
|
-
|
|
781
|
-
getNearNep141StorageBalance as getNearNep141StorageBalance3,
|
|
782
|
-
solverRelay as solverRelay4,
|
|
779
|
+
poaBridge,
|
|
783
780
|
utils as utils7
|
|
784
781
|
} from "@defuse-protocol/internal-utils";
|
|
785
782
|
import TTLCache from "@isaacs/ttlcache";
|
|
786
|
-
import { retry as retry2 } from "@lifeomic/attempt";
|
|
787
|
-
import {
|
|
788
|
-
ChainKind as ChainKind2,
|
|
789
|
-
OmniBridgeAPI,
|
|
790
|
-
getBridgedToken,
|
|
791
|
-
getChain,
|
|
792
|
-
isEvmChain,
|
|
793
|
-
omniAddress as omniAddress2,
|
|
794
|
-
parseOriginChain
|
|
795
|
-
} from "omni-bridge-sdk";
|
|
796
|
-
|
|
797
|
-
// src/bridges/omni-bridge/error.ts
|
|
798
|
-
import { BaseError as BaseError3 } from "@defuse-protocol/internal-utils";
|
|
799
|
-
var OmniTransferNotFoundError = class extends BaseError3 {
|
|
800
|
-
constructor(txHash) {
|
|
801
|
-
super("Omni transfer with given hash is not found in the relayer.", {
|
|
802
|
-
metaMessages: [`OriginTxHash: ${txHash}`],
|
|
803
|
-
name: "OmniTransferNotFoundError"
|
|
804
|
-
});
|
|
805
|
-
this.txHash = txHash;
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
var OmniTransferDestinationChainHashNotFoundError = class extends BaseError3 {
|
|
809
|
-
constructor(txHash, destinationChain) {
|
|
810
|
-
super("Relayer did not return destination chain hash for a transfer.", {
|
|
811
|
-
metaMessages: [
|
|
812
|
-
`OriginTxHash: ${txHash}`,
|
|
813
|
-
`DestinationChain: ${destinationChain}`
|
|
814
|
-
],
|
|
815
|
-
name: "OmniTransferDestinationChainHashNotFoundError"
|
|
816
|
-
});
|
|
817
|
-
this.txHash = txHash;
|
|
818
|
-
this.destinationChain = destinationChain;
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
|
|
822
|
-
constructor(token) {
|
|
823
|
-
super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
|
|
824
|
-
metaMessages: [`Token: ${token}`],
|
|
825
|
-
name: "TokenNotSupportedByOmniRelayerError"
|
|
826
|
-
});
|
|
827
|
-
this.token = token;
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
var TokenNotFoundInDestinationChainError = class extends BaseError3 {
|
|
831
|
-
constructor(token, chainKind) {
|
|
832
|
-
super(
|
|
833
|
-
`The token ${token} doesn't exist in destination network ${chainKind}`,
|
|
834
|
-
{
|
|
835
|
-
metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
|
|
836
|
-
name: "TokenNotFoundInDestinationChainError"
|
|
837
|
-
}
|
|
838
|
-
);
|
|
839
|
-
this.token = token;
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
// src/bridges/omni-bridge/omni-bridge-constants.ts
|
|
844
|
-
var NEAR_NATIVE_ASSET_ID3 = "nep141:wrap.near";
|
|
845
|
-
var OMNI_BRIDGE_CONTRACT = "omni.bridge.near";
|
|
846
|
-
|
|
847
|
-
// src/bridges/omni-bridge/omni-bridge-utils.ts
|
|
848
|
-
import { assert as assert8, utils as utils6 } from "@defuse-protocol/internal-utils";
|
|
849
|
-
import { ChainKind, omniAddress } from "omni-bridge-sdk";
|
|
850
|
-
function createWithdrawIntentPrimitive3(params) {
|
|
851
|
-
const { contractId: tokenAccountId, standard } = utils6.parseDefuseAssetId(
|
|
852
|
-
params.assetId
|
|
853
|
-
);
|
|
854
|
-
assert8(standard === "nep141", "Only NEP-141 is supported");
|
|
855
|
-
return {
|
|
856
|
-
intent: "ft_withdraw",
|
|
857
|
-
token: tokenAccountId,
|
|
858
|
-
receiver_id: OMNI_BRIDGE_CONTRACT,
|
|
859
|
-
amount: params.amount.toString(),
|
|
860
|
-
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : null,
|
|
861
|
-
msg: JSON.stringify({
|
|
862
|
-
recipient: omniAddress(
|
|
863
|
-
caip2ToChainKind(params.origin),
|
|
864
|
-
params.destinationAddress
|
|
865
|
-
),
|
|
866
|
-
fee: params.transferredTokenFee.toString(),
|
|
867
|
-
native_token_fee: "0"
|
|
868
|
-
})
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
function targetChainSupportedByOmniBridge(network) {
|
|
872
|
-
switch (network) {
|
|
873
|
-
case Chains.Ethereum:
|
|
874
|
-
return true;
|
|
875
|
-
case Chains.Base:
|
|
876
|
-
return true;
|
|
877
|
-
case Chains.Arbitrum:
|
|
878
|
-
return true;
|
|
879
|
-
case Chains.Solana:
|
|
880
|
-
return true;
|
|
881
|
-
case Chains.Bitcoin:
|
|
882
|
-
return true;
|
|
883
|
-
default:
|
|
884
|
-
return false;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
function caip2ToChainKind(network) {
|
|
888
|
-
switch (network) {
|
|
889
|
-
case Chains.Ethereum:
|
|
890
|
-
return ChainKind.Eth;
|
|
891
|
-
case Chains.Base:
|
|
892
|
-
return ChainKind.Base;
|
|
893
|
-
case Chains.Arbitrum:
|
|
894
|
-
return ChainKind.Arb;
|
|
895
|
-
case Chains.Solana:
|
|
896
|
-
return ChainKind.Sol;
|
|
897
|
-
case Chains.Bitcoin:
|
|
898
|
-
return ChainKind.Btc;
|
|
899
|
-
default:
|
|
900
|
-
throw new Error(`Unsupported Omni network = ${network}`);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
function chainKindToCaip2(network) {
|
|
904
|
-
switch (network) {
|
|
905
|
-
case ChainKind.Eth:
|
|
906
|
-
return Chains.Ethereum;
|
|
907
|
-
case ChainKind.Base:
|
|
908
|
-
return Chains.Base;
|
|
909
|
-
case ChainKind.Arb:
|
|
910
|
-
return Chains.Arbitrum;
|
|
911
|
-
case ChainKind.Sol:
|
|
912
|
-
return Chains.Solana;
|
|
913
|
-
case ChainKind.Btc:
|
|
914
|
-
return Chains.Bitcoin;
|
|
915
|
-
default:
|
|
916
|
-
throw new Error(`Unsupported Caip2 network = ${network}`);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
// src/bridges/omni-bridge/omni-bridge.ts
|
|
921
|
-
var _OmniBridge = class _OmniBridge {
|
|
922
|
-
// 86400000 - 1 day
|
|
923
|
-
constructor({
|
|
924
|
-
env,
|
|
925
|
-
nearProvider
|
|
926
|
-
}) {
|
|
927
|
-
this.storageDepositCache = new TTLCache({ ttl: 864e5 });
|
|
928
|
-
// TTL cache for supported tokens with 30-second TTL
|
|
929
|
-
this.supportedTokensCache = new TTLCache({ ttl: 864e5 });
|
|
930
|
-
// 86400000 - 1 day
|
|
931
|
-
this.destinationChainAddressCache = new TTLCache({ ttl: 864e5 });
|
|
932
|
-
this.env = env;
|
|
933
|
-
this.nearProvider = nearProvider;
|
|
934
|
-
this.omniBridgeAPI = new OmniBridgeAPI();
|
|
935
|
-
}
|
|
936
|
-
is(routeConfig) {
|
|
937
|
-
return routeConfig.route === RouteEnum.OmniBridge;
|
|
938
|
-
}
|
|
939
|
-
supports(params) {
|
|
940
|
-
try {
|
|
941
|
-
if (this.targetChainSpecified(params.routeConfig)) {
|
|
942
|
-
return targetChainSupportedByOmniBridge(params.routeConfig.chain);
|
|
943
|
-
}
|
|
944
|
-
return this.parseAssetId(params.assetId) !== null;
|
|
945
|
-
} catch {
|
|
946
|
-
return false;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
targetChainSpecified(routeConfig) {
|
|
950
|
-
return Boolean(
|
|
951
|
-
routeConfig?.route && routeConfig.route === RouteEnum.OmniBridge && routeConfig.chain
|
|
952
|
-
);
|
|
953
|
-
}
|
|
954
|
-
parseAssetId(assetId) {
|
|
955
|
-
const parsed = utils7.parseDefuseAssetId(assetId);
|
|
956
|
-
if (parsed.standard !== "nep141") return null;
|
|
957
|
-
const chain = parseOriginChain(parsed.contractId);
|
|
958
|
-
if (chain === null) return null;
|
|
959
|
-
return Object.assign(parsed, {
|
|
960
|
-
blockchain: chainKindToCaip2(chain),
|
|
961
|
-
bridgeName: BridgeNameEnum.Omni,
|
|
962
|
-
address: parsed.contractId
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
async tokenSupported(assetId, routeConfig) {
|
|
966
|
-
const parsed = utils7.parseDefuseAssetId(assetId);
|
|
967
|
-
if (parsed.standard !== "nep141") return null;
|
|
968
|
-
if (this.targetChainSpecified(routeConfig)) {
|
|
969
|
-
const tokenOnDestinationNetwork = await this.getCachedDestinationTokenAddress(
|
|
970
|
-
parsed.contractId,
|
|
971
|
-
routeConfig.chain
|
|
972
|
-
);
|
|
973
|
-
if (tokenOnDestinationNetwork === null) {
|
|
974
|
-
throw new TokenNotFoundInDestinationChainError(
|
|
975
|
-
assetId,
|
|
976
|
-
routeConfig.chain
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
return Object.assign(parsed, {
|
|
980
|
-
blockchain: routeConfig.chain,
|
|
981
|
-
bridgeName: BridgeNameEnum.Omni,
|
|
982
|
-
address: parsed.contractId
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
const chain = parseOriginChain(parsed.contractId);
|
|
986
|
-
if (chain === null) return null;
|
|
987
|
-
return Object.assign(parsed, {
|
|
988
|
-
blockchain: chainKindToCaip2(chain),
|
|
989
|
-
bridgeName: BridgeNameEnum.Omni,
|
|
990
|
-
address: parsed.contractId
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
async createWithdrawalIntents(args) {
|
|
994
|
-
const assetInfo = await this.tokenSupported(
|
|
995
|
-
args.withdrawalParams.assetId,
|
|
996
|
-
args.withdrawalParams.routeConfig
|
|
997
|
-
);
|
|
998
|
-
assert9(
|
|
999
|
-
assetInfo !== null,
|
|
1000
|
-
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
1001
|
-
);
|
|
1002
|
-
const intents = [];
|
|
1003
|
-
if (args.feeEstimation.quote !== null) {
|
|
1004
|
-
intents.push({
|
|
1005
|
-
intent: "token_diff",
|
|
1006
|
-
diff: {
|
|
1007
|
-
[args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
|
|
1008
|
-
[args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
|
|
1009
|
-
},
|
|
1010
|
-
referral: args.referral
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
const intent = createWithdrawIntentPrimitive3({
|
|
1014
|
-
assetId: args.withdrawalParams.assetId,
|
|
1015
|
-
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
1016
|
-
amount: args.withdrawalParams.amount + args.feeEstimation.amount,
|
|
1017
|
-
origin: assetInfo.blockchain,
|
|
1018
|
-
storageDeposit: args.feeEstimation.quote ? BigInt(args.feeEstimation.quote.amount_out) : 0n,
|
|
1019
|
-
transferredTokenFee: args.feeEstimation.amount
|
|
1020
|
-
});
|
|
1021
|
-
intents.push(intent);
|
|
1022
|
-
return Promise.resolve(intents);
|
|
1023
|
-
}
|
|
1024
|
-
async validateWithdrawal(args) {
|
|
1025
|
-
const assetInfo = await this.tokenSupported(args.assetId, args.routeConfig);
|
|
1026
|
-
assert9(assetInfo !== null, `Asset ${args.assetId} is not supported`);
|
|
1027
|
-
const supportedTokens = await this.getCachedSupportedTokens();
|
|
1028
|
-
if (!supportedTokens[assetInfo.contractId]) {
|
|
1029
|
-
throw new TokenNotSupportedByOmniRelayerError(args.assetId);
|
|
1030
|
-
}
|
|
1031
|
-
assert9(
|
|
1032
|
-
args.feeEstimation.amount > 0n,
|
|
1033
|
-
`Fee must be greater than zero. Current fee is ${args.feeEstimation.amount}.`
|
|
1034
|
-
);
|
|
1035
|
-
return;
|
|
1036
|
-
}
|
|
1037
|
-
async estimateWithdrawalFee(args) {
|
|
1038
|
-
const assetInfo = await this.tokenSupported(
|
|
1039
|
-
args.withdrawalParams.assetId,
|
|
1040
|
-
args.withdrawalParams.routeConfig
|
|
1041
|
-
);
|
|
1042
|
-
assert9(
|
|
1043
|
-
assetInfo !== null,
|
|
1044
|
-
`Asset ${args.withdrawalParams.assetId} is not supported`
|
|
1045
|
-
);
|
|
1046
|
-
const fee = await this.omniBridgeAPI.getFee(
|
|
1047
|
-
omniAddress2(ChainKind2.Near, configsByEnvironment4[this.env].contractID),
|
|
1048
|
-
omniAddress2(
|
|
1049
|
-
caip2ToChainKind(assetInfo.blockchain),
|
|
1050
|
-
args.withdrawalParams.destinationAddress
|
|
1051
|
-
),
|
|
1052
|
-
omniAddress2(ChainKind2.Near, assetInfo.contractId)
|
|
1053
|
-
);
|
|
1054
|
-
assert9(
|
|
1055
|
-
fee.transferred_token_fee !== null,
|
|
1056
|
-
`Asset ${args.withdrawalParams.assetId} is not supported by the relayer`
|
|
1057
|
-
);
|
|
1058
|
-
const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(assetInfo.contractId);
|
|
1059
|
-
if (minStorageBalance <= userStorageBalance) {
|
|
1060
|
-
return {
|
|
1061
|
-
amount: BigInt(fee.transferred_token_fee),
|
|
1062
|
-
quote: null
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
const feeAmount = minStorageBalance - userStorageBalance;
|
|
1066
|
-
const feeQuote = await solverRelay4.getQuote({
|
|
1067
|
-
quoteParams: {
|
|
1068
|
-
defuse_asset_identifier_in: args.withdrawalParams.assetId,
|
|
1069
|
-
defuse_asset_identifier_out: NEAR_NATIVE_ASSET_ID3,
|
|
1070
|
-
exact_amount_out: feeAmount.toString(),
|
|
1071
|
-
wait_ms: args.quoteOptions?.waitMs
|
|
1072
|
-
},
|
|
1073
|
-
config: {
|
|
1074
|
-
baseURL: configsByEnvironment4[this.env].solverRelayBaseURL,
|
|
1075
|
-
logBalanceSufficient: false,
|
|
1076
|
-
logger: args.logger
|
|
1077
|
-
}
|
|
1078
|
-
});
|
|
1079
|
-
return {
|
|
1080
|
-
amount: BigInt(fee.transferred_token_fee) + BigInt(feeQuote.amount_in),
|
|
1081
|
-
quote: feeQuote
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
async waitForWithdrawalCompletion(args) {
|
|
1085
|
-
return retry2(
|
|
1086
|
-
async () => {
|
|
1087
|
-
if (args.signal?.aborted) {
|
|
1088
|
-
throw args.signal.reason;
|
|
1089
|
-
}
|
|
1090
|
-
const transfer = (await this.omniBridgeAPI.findOmniTransfers({
|
|
1091
|
-
transaction_id: args.tx.hash,
|
|
1092
|
-
offset: args.index,
|
|
1093
|
-
limit: 1
|
|
1094
|
-
}))[0];
|
|
1095
|
-
if (!transfer) throw new OmniTransferNotFoundError(args.tx.hash);
|
|
1096
|
-
const destinationChain = getChain(
|
|
1097
|
-
transfer.transfer_message.recipient
|
|
1098
|
-
);
|
|
1099
|
-
let txHash = null;
|
|
1100
|
-
if (isEvmChain(destinationChain)) {
|
|
1101
|
-
txHash = transfer.finalised?.EVMLog?.transaction_hash;
|
|
1102
|
-
} else if (destinationChain === ChainKind2.Sol) {
|
|
1103
|
-
txHash = transfer.finalised?.Solana?.signature;
|
|
1104
|
-
} else {
|
|
1105
|
-
return { hash: null };
|
|
1106
|
-
}
|
|
1107
|
-
if (!txHash)
|
|
1108
|
-
throw new OmniTransferDestinationChainHashNotFoundError(
|
|
1109
|
-
args.tx.hash,
|
|
1110
|
-
ChainKind2[destinationChain].toLowerCase()
|
|
1111
|
-
);
|
|
1112
|
-
return { hash: txHash };
|
|
1113
|
-
},
|
|
1114
|
-
{
|
|
1115
|
-
...args.retryOptions ?? RETRY_CONFIGS2.TWO_MINS_GRADUAL,
|
|
1116
|
-
handleError: (err, ctx) => {
|
|
1117
|
-
if (err instanceof OmniTransferNotFoundError || err === args.signal?.reason) {
|
|
1118
|
-
ctx.abort();
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
);
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
1126
|
-
* Cache expires after one day using TTL cache.
|
|
1127
|
-
*/
|
|
1128
|
-
async getCachedStorageDepositValue(contractId) {
|
|
1129
|
-
const cached = this.storageDepositCache.get(contractId);
|
|
1130
|
-
if (cached != null) {
|
|
1131
|
-
return cached;
|
|
1132
|
-
}
|
|
1133
|
-
const data = await Promise.all([
|
|
1134
|
-
getNearNep141MinStorageBalance3({
|
|
1135
|
-
contractId,
|
|
1136
|
-
nearProvider: this.nearProvider
|
|
1137
|
-
}),
|
|
1138
|
-
getNearNep141StorageBalance3({
|
|
1139
|
-
contractId,
|
|
1140
|
-
accountId: OMNI_BRIDGE_CONTRACT,
|
|
1141
|
-
nearProvider: this.nearProvider
|
|
1142
|
-
})
|
|
1143
|
-
]);
|
|
1144
|
-
this.storageDepositCache.set(contractId, data);
|
|
1145
|
-
return data;
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Gets cached tokens supported by the omni relayer, tokens not listed there can't be transferred.
|
|
1149
|
-
* Cache expires after one day using TTL cache.
|
|
1150
|
-
*/
|
|
1151
|
-
async getCachedSupportedTokens() {
|
|
1152
|
-
const cached = this.supportedTokensCache.get(
|
|
1153
|
-
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY
|
|
1154
|
-
);
|
|
1155
|
-
if (cached != null) {
|
|
1156
|
-
return cached;
|
|
1157
|
-
}
|
|
1158
|
-
const data = await this.omniBridgeAPI.getAllowlistedTokens();
|
|
1159
|
-
this.supportedTokensCache.set(_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY, data);
|
|
1160
|
-
return data;
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* Gets cached token address on destination chain.
|
|
1164
|
-
* Cache expires after one day using TTL cache.
|
|
1165
|
-
*/
|
|
1166
|
-
async getCachedDestinationTokenAddress(contractId, chain) {
|
|
1167
|
-
const key = `${chain}:${contractId}`;
|
|
1168
|
-
const cached = this.destinationChainAddressCache.get(key);
|
|
1169
|
-
if (cached != null) {
|
|
1170
|
-
return cached;
|
|
1171
|
-
}
|
|
1172
|
-
const tokenOnDestinationNetwork = await getBridgedToken(
|
|
1173
|
-
omniAddress2(ChainKind2.Near, contractId),
|
|
1174
|
-
caip2ToChainKind(chain)
|
|
1175
|
-
);
|
|
1176
|
-
this.destinationChainAddressCache.set(key, tokenOnDestinationNetwork);
|
|
1177
|
-
return tokenOnDestinationNetwork;
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
// 86400000 - 1 day
|
|
1181
|
-
_OmniBridge.SUPPORTED_TOKENS_CACHE_KEY = "SUPPORTED_TOKENS_CACHE_KEY";
|
|
1182
|
-
var OmniBridge = _OmniBridge;
|
|
1183
|
-
|
|
1184
|
-
// src/bridges/poa-bridge/poa-bridge.ts
|
|
1185
|
-
import {
|
|
1186
|
-
assert as assert10,
|
|
1187
|
-
configsByEnvironment as configsByEnvironment5,
|
|
1188
|
-
poaBridge,
|
|
1189
|
-
utils as utils9
|
|
1190
|
-
} from "@defuse-protocol/internal-utils";
|
|
1191
|
-
import TTLCache2 from "@isaacs/ttlcache";
|
|
1192
783
|
|
|
1193
784
|
// src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
1194
|
-
import { utils as
|
|
1195
|
-
function
|
|
1196
|
-
const { contractId: tokenAccountId } =
|
|
785
|
+
import { utils as utils6 } from "@defuse-protocol/internal-utils";
|
|
786
|
+
function createWithdrawIntentPrimitive3(params) {
|
|
787
|
+
const { contractId: tokenAccountId } = utils6.parseDefuseAssetId(
|
|
1197
788
|
params.assetId
|
|
1198
789
|
);
|
|
1199
790
|
return {
|
|
@@ -1268,7 +859,7 @@ function contractIdToCaip2(contractId) {
|
|
|
1268
859
|
var PoaBridge = class {
|
|
1269
860
|
constructor({ env }) {
|
|
1270
861
|
// TTL cache for supported tokens with 30-second TTL
|
|
1271
|
-
this.supportedTokensCache = new
|
|
862
|
+
this.supportedTokensCache = new TTLCache({ ttl: 30 * 1e3 });
|
|
1272
863
|
this.env = env;
|
|
1273
864
|
}
|
|
1274
865
|
is(routeConfig) {
|
|
@@ -1286,9 +877,9 @@ var PoaBridge = class {
|
|
|
1286
877
|
}
|
|
1287
878
|
}
|
|
1288
879
|
parseAssetId(assetId) {
|
|
1289
|
-
const parsed =
|
|
880
|
+
const parsed = utils7.parseDefuseAssetId(assetId);
|
|
1290
881
|
if (parsed.contractId.endsWith(
|
|
1291
|
-
`.${
|
|
882
|
+
`.${configsByEnvironment4[this.env].poaTokenFactoryContractID}`
|
|
1292
883
|
)) {
|
|
1293
884
|
return Object.assign(parsed, {
|
|
1294
885
|
blockchain: contractIdToCaip2(parsed.contractId),
|
|
@@ -1300,7 +891,7 @@ var PoaBridge = class {
|
|
|
1300
891
|
return null;
|
|
1301
892
|
}
|
|
1302
893
|
createWithdrawalIntents(args) {
|
|
1303
|
-
const intent =
|
|
894
|
+
const intent = createWithdrawIntentPrimitive3({
|
|
1304
895
|
...args.withdrawalParams,
|
|
1305
896
|
amount: args.withdrawalParams.amount + args.feeEstimation.amount,
|
|
1306
897
|
destinationMemo: args.withdrawalParams.destinationMemo
|
|
@@ -1315,7 +906,7 @@ var PoaBridge = class {
|
|
|
1315
906
|
*/
|
|
1316
907
|
async validateWithdrawal(args) {
|
|
1317
908
|
const assetInfo = this.parseAssetId(args.assetId);
|
|
1318
|
-
|
|
909
|
+
assert8(assetInfo != null, "Asset is not supported");
|
|
1319
910
|
const { tokens } = await this.getCachedSupportedTokens(
|
|
1320
911
|
[toPoaNetwork(assetInfo.blockchain)],
|
|
1321
912
|
args.logger
|
|
@@ -1336,16 +927,16 @@ var PoaBridge = class {
|
|
|
1336
927
|
}
|
|
1337
928
|
async estimateWithdrawalFee(args) {
|
|
1338
929
|
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
1339
|
-
|
|
930
|
+
assert8(assetInfo != null, "Asset is not supported");
|
|
1340
931
|
const estimation = await poaBridge.httpClient.getWithdrawalEstimate(
|
|
1341
932
|
{
|
|
1342
|
-
token:
|
|
933
|
+
token: utils7.getTokenAccountId(args.withdrawalParams.assetId),
|
|
1343
934
|
address: args.withdrawalParams.destinationAddress,
|
|
1344
935
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
1345
936
|
chain: toPoaNetwork(assetInfo.blockchain)
|
|
1346
937
|
},
|
|
1347
938
|
{
|
|
1348
|
-
baseURL:
|
|
939
|
+
baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
|
|
1349
940
|
logger: args.logger
|
|
1350
941
|
}
|
|
1351
942
|
);
|
|
@@ -1360,7 +951,7 @@ var PoaBridge = class {
|
|
|
1360
951
|
index: args.index,
|
|
1361
952
|
signal: args.signal ?? new AbortController().signal,
|
|
1362
953
|
retryOptions: args.retryOptions,
|
|
1363
|
-
baseURL:
|
|
954
|
+
baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
|
|
1364
955
|
logger: args.logger
|
|
1365
956
|
});
|
|
1366
957
|
return { hash: withdrawalStatus.destinationTxHash };
|
|
@@ -1378,7 +969,7 @@ var PoaBridge = class {
|
|
|
1378
969
|
const data = await poaBridge.httpClient.getSupportedTokens(
|
|
1379
970
|
{ chains },
|
|
1380
971
|
{
|
|
1381
|
-
baseURL:
|
|
972
|
+
baseURL: configsByEnvironment4[this.env].poaBridgeBaseURL,
|
|
1382
973
|
logger
|
|
1383
974
|
}
|
|
1384
975
|
);
|
|
@@ -1401,7 +992,7 @@ var PUBLIC_STELLAR_RPC_URLS = {
|
|
|
1401
992
|
|
|
1402
993
|
// src/intents/intent-executer-impl/intent-executer.ts
|
|
1403
994
|
import {
|
|
1404
|
-
configsByEnvironment as
|
|
995
|
+
configsByEnvironment as configsByEnvironment5
|
|
1405
996
|
} from "@defuse-protocol/internal-utils";
|
|
1406
997
|
|
|
1407
998
|
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
|
|
@@ -1783,7 +1374,7 @@ var IntentExecuter = class {
|
|
|
1783
1374
|
relayParams: relayParamsFactory,
|
|
1784
1375
|
...intentParams
|
|
1785
1376
|
}) {
|
|
1786
|
-
const verifyingContract =
|
|
1377
|
+
const verifyingContract = configsByEnvironment5[this.env].contractID;
|
|
1787
1378
|
let intentPayload = defaultIntentPayloadFactory({
|
|
1788
1379
|
verifying_contract: verifyingContract,
|
|
1789
1380
|
...intentParams
|
|
@@ -1834,8 +1425,8 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
|
|
|
1834
1425
|
|
|
1835
1426
|
// src/intents/intent-relayer-impl/intent-relayer-public.ts
|
|
1836
1427
|
import {
|
|
1837
|
-
configsByEnvironment as
|
|
1838
|
-
solverRelay as
|
|
1428
|
+
configsByEnvironment as configsByEnvironment6,
|
|
1429
|
+
solverRelay as solverRelay4
|
|
1839
1430
|
} from "@defuse-protocol/internal-utils";
|
|
1840
1431
|
var IntentRelayerPublic = class {
|
|
1841
1432
|
constructor({ env }) {
|
|
@@ -1858,13 +1449,13 @@ var IntentRelayerPublic = class {
|
|
|
1858
1449
|
multiPayloads,
|
|
1859
1450
|
quoteHashes
|
|
1860
1451
|
}, ctx = {}) {
|
|
1861
|
-
const a = await
|
|
1452
|
+
const a = await solverRelay4.publishIntents(
|
|
1862
1453
|
{
|
|
1863
1454
|
quote_hashes: quoteHashes,
|
|
1864
1455
|
signed_datas: multiPayloads
|
|
1865
1456
|
},
|
|
1866
1457
|
{
|
|
1867
|
-
baseURL:
|
|
1458
|
+
baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
|
|
1868
1459
|
logger: ctx.logger
|
|
1869
1460
|
}
|
|
1870
1461
|
);
|
|
@@ -1874,10 +1465,10 @@ var IntentRelayerPublic = class {
|
|
|
1874
1465
|
throw a.unwrapErr();
|
|
1875
1466
|
}
|
|
1876
1467
|
async waitForSettlement(ticket, ctx = {}) {
|
|
1877
|
-
const result = await
|
|
1468
|
+
const result = await solverRelay4.waitForIntentSettlement({
|
|
1878
1469
|
intentHash: ticket,
|
|
1879
1470
|
signal: new AbortController().signal,
|
|
1880
|
-
baseURL:
|
|
1471
|
+
baseURL: configsByEnvironment6[this.env].solverRelayBaseURL,
|
|
1881
1472
|
logger: ctx.logger
|
|
1882
1473
|
});
|
|
1883
1474
|
return {
|
|
@@ -1885,7 +1476,7 @@ var IntentRelayerPublic = class {
|
|
|
1885
1476
|
hash: result.txHash,
|
|
1886
1477
|
// Usually relayer's account id is the verifying contract (`intents.near`),
|
|
1887
1478
|
// but it is not set in stone and may change in the future.
|
|
1888
|
-
accountId:
|
|
1479
|
+
accountId: configsByEnvironment6[this.env].contractID
|
|
1889
1480
|
}
|
|
1890
1481
|
};
|
|
1891
1482
|
}
|
|
@@ -1899,14 +1490,14 @@ var noopIntentSigner = {
|
|
|
1899
1490
|
};
|
|
1900
1491
|
|
|
1901
1492
|
// src/lib/array.ts
|
|
1902
|
-
import { assert as
|
|
1493
|
+
import { assert as assert9 } from "@defuse-protocol/internal-utils";
|
|
1903
1494
|
function zip(arr1, arr2) {
|
|
1904
|
-
|
|
1495
|
+
assert9(arr1.length === arr2.length, "Arrays must have the same length");
|
|
1905
1496
|
return arr1.map((v, i) => [v, arr2[i]]);
|
|
1906
1497
|
}
|
|
1907
1498
|
|
|
1908
1499
|
// src/lib/configure-rpc-config.ts
|
|
1909
|
-
import { assert as
|
|
1500
|
+
import { assert as assert10 } from "@defuse-protocol/internal-utils";
|
|
1910
1501
|
|
|
1911
1502
|
// src/lib/object.ts
|
|
1912
1503
|
function pick(obj, keys) {
|
|
@@ -1930,7 +1521,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
|
|
|
1930
1521
|
).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
|
|
1931
1522
|
);
|
|
1932
1523
|
for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
|
|
1933
|
-
|
|
1524
|
+
assert10(
|
|
1934
1525
|
urls.length > 0,
|
|
1935
1526
|
`EVM RPC URLs for chain ${chainId} are not provided`
|
|
1936
1527
|
);
|
|
@@ -1944,7 +1535,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
|
|
|
1944
1535
|
userRpcUrls?.[Chains.Stellar] ?? {}
|
|
1945
1536
|
);
|
|
1946
1537
|
for (const [key, value] of Object.entries(stellarRpcUrls)) {
|
|
1947
|
-
|
|
1538
|
+
assert10(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
|
|
1948
1539
|
}
|
|
1949
1540
|
return stellarRpcUrls;
|
|
1950
1541
|
}
|
|
@@ -2015,7 +1606,7 @@ var IntentsSDK = class {
|
|
|
2015
1606
|
this.env = args.env ?? "production";
|
|
2016
1607
|
this.referral = args.referral;
|
|
2017
1608
|
const nearRpcUrls = args.rpc?.[Chains.Near] ?? PUBLIC_NEAR_RPC_URLS;
|
|
2018
|
-
|
|
1609
|
+
assert11(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
|
|
2019
1610
|
const nearProvider = nearFailoverRpcProvider({ urls: nearRpcUrls });
|
|
2020
1611
|
const stellarRpcUrls = configureStellarRpcUrls(
|
|
2021
1612
|
PUBLIC_STELLAR_RPC_URLS,
|
|
@@ -2048,10 +1639,10 @@ var IntentsSDK = class {
|
|
|
2048
1639
|
}
|
|
2049
1640
|
})
|
|
2050
1641
|
}),
|
|
2051
|
-
new OmniBridge({
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
}),
|
|
1642
|
+
// new OmniBridge({
|
|
1643
|
+
// env: this.env,
|
|
1644
|
+
// nearProvider,
|
|
1645
|
+
// }),
|
|
2055
1646
|
new DirectBridge({
|
|
2056
1647
|
env: this.env,
|
|
2057
1648
|
nearProvider
|
|
@@ -2142,7 +1733,7 @@ var IntentsSDK = class {
|
|
|
2142
1733
|
const routeConfig = determineRouteConfig(this, w);
|
|
2143
1734
|
const route = routeConfig.route;
|
|
2144
1735
|
const index = indexes.get(route);
|
|
2145
|
-
|
|
1736
|
+
assert11(index != null, "Index is not found for route");
|
|
2146
1737
|
indexes.set(route, index + 1);
|
|
2147
1738
|
return {
|
|
2148
1739
|
routeConfig,
|
|
@@ -2176,7 +1767,7 @@ var IntentsSDK = class {
|
|
|
2176
1767
|
if (Array.isArray(args.withdrawalParams)) {
|
|
2177
1768
|
return result;
|
|
2178
1769
|
}
|
|
2179
|
-
|
|
1770
|
+
assert11(result.length === 1, "Unexpected result length");
|
|
2180
1771
|
return result[0];
|
|
2181
1772
|
}
|
|
2182
1773
|
parseAssetId(assetId) {
|
|
@@ -2190,7 +1781,7 @@ var IntentsSDK = class {
|
|
|
2190
1781
|
}
|
|
2191
1782
|
async signAndSendIntent(args) {
|
|
2192
1783
|
const intentSigner = args.signer ?? this.intentSigner;
|
|
2193
|
-
|
|
1784
|
+
assert11(intentSigner != null, "Intent signer is not provided");
|
|
2194
1785
|
const intentExecuter = new IntentExecuter({
|
|
2195
1786
|
env: this.env,
|
|
2196
1787
|
logger: args.logger,
|
|
@@ -2259,12 +1850,12 @@ var IntentsSDK = class {
|
|
|
2259
1850
|
intentHash,
|
|
2260
1851
|
logger
|
|
2261
1852
|
}) {
|
|
2262
|
-
return
|
|
1853
|
+
return solverRelay5.getStatus(
|
|
2263
1854
|
{
|
|
2264
1855
|
intent_hash: intentHash
|
|
2265
1856
|
},
|
|
2266
1857
|
{
|
|
2267
|
-
baseURL:
|
|
1858
|
+
baseURL: configsByEnvironment7[this.env].solverRelayBaseURL,
|
|
2268
1859
|
logger
|
|
2269
1860
|
}
|
|
2270
1861
|
);
|
|
@@ -2295,7 +1886,7 @@ var IntentsSDK = class {
|
|
|
2295
1886
|
withdrawalParams,
|
|
2296
1887
|
intentTx,
|
|
2297
1888
|
logger: args.logger,
|
|
2298
|
-
retryOptions:
|
|
1889
|
+
retryOptions: RETRY_CONFIGS2.FIVE_MINS_STEADY
|
|
2299
1890
|
});
|
|
2300
1891
|
if (!Array.isArray(args.withdrawalParams)) {
|
|
2301
1892
|
return {
|
|
@@ -2374,14 +1965,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
|
|
|
2374
1965
|
};
|
|
2375
1966
|
|
|
2376
1967
|
// src/intents/intent-signer-impl/intent-signer-viem.ts
|
|
2377
|
-
import { utils as
|
|
1968
|
+
import { utils as utils8 } from "@defuse-protocol/internal-utils";
|
|
2378
1969
|
var IntentSignerViem = class {
|
|
2379
1970
|
constructor(account) {
|
|
2380
1971
|
this.account = account;
|
|
2381
1972
|
}
|
|
2382
1973
|
async signIntent(intent) {
|
|
2383
1974
|
const payload = JSON.stringify({
|
|
2384
|
-
signer_id: intent.signer_id ??
|
|
1975
|
+
signer_id: intent.signer_id ?? utils8.authHandleToIntentsUserId({
|
|
2385
1976
|
identifier: this.account.address,
|
|
2386
1977
|
method: "evm"
|
|
2387
1978
|
}),
|
|
@@ -2399,7 +1990,7 @@ var IntentSignerViem = class {
|
|
|
2399
1990
|
return {
|
|
2400
1991
|
standard: "erc191",
|
|
2401
1992
|
payload,
|
|
2402
|
-
signature:
|
|
1993
|
+
signature: utils8.transformERC191Signature(signature)
|
|
2403
1994
|
};
|
|
2404
1995
|
}
|
|
2405
1996
|
};
|
|
@@ -2419,6 +2010,54 @@ function createIntentSignerViem(config) {
|
|
|
2419
2010
|
import {
|
|
2420
2011
|
BaseError as BaseError4
|
|
2421
2012
|
} from "@defuse-protocol/internal-utils";
|
|
2013
|
+
|
|
2014
|
+
// src/bridges/omni-bridge/error.ts
|
|
2015
|
+
import { BaseError as BaseError3 } from "@defuse-protocol/internal-utils";
|
|
2016
|
+
var OmniTransferNotFoundError = class extends BaseError3 {
|
|
2017
|
+
constructor(txHash) {
|
|
2018
|
+
super("Omni transfer with given hash is not found in the relayer.", {
|
|
2019
|
+
metaMessages: [`OriginTxHash: ${txHash}`],
|
|
2020
|
+
name: "OmniTransferNotFoundError"
|
|
2021
|
+
});
|
|
2022
|
+
this.txHash = txHash;
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
var OmniTransferDestinationChainHashNotFoundError = class extends BaseError3 {
|
|
2026
|
+
constructor(txHash, destinationChain) {
|
|
2027
|
+
super("Relayer did not return destination chain hash for a transfer.", {
|
|
2028
|
+
metaMessages: [
|
|
2029
|
+
`OriginTxHash: ${txHash}`,
|
|
2030
|
+
`DestinationChain: ${destinationChain}`
|
|
2031
|
+
],
|
|
2032
|
+
name: "OmniTransferDestinationChainHashNotFoundError"
|
|
2033
|
+
});
|
|
2034
|
+
this.txHash = txHash;
|
|
2035
|
+
this.destinationChain = destinationChain;
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
var TokenNotSupportedByOmniRelayerError = class extends BaseError3 {
|
|
2039
|
+
constructor(token) {
|
|
2040
|
+
super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
|
|
2041
|
+
metaMessages: [`Token: ${token}`],
|
|
2042
|
+
name: "TokenNotSupportedByOmniRelayerError"
|
|
2043
|
+
});
|
|
2044
|
+
this.token = token;
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
var TokenNotFoundInDestinationChainError = class extends BaseError3 {
|
|
2048
|
+
constructor(token, chainKind) {
|
|
2049
|
+
super(
|
|
2050
|
+
`The token ${token} doesn't exist in destination network ${chainKind}`,
|
|
2051
|
+
{
|
|
2052
|
+
metaMessages: [`Token: ${token}`, `Destination Chain: ${chainKind}`],
|
|
2053
|
+
name: "TokenNotFoundInDestinationChainError"
|
|
2054
|
+
}
|
|
2055
|
+
);
|
|
2056
|
+
this.token = token;
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
|
|
2060
|
+
// index.ts
|
|
2422
2061
|
import {
|
|
2423
2062
|
PoaWithdrawalInvariantError,
|
|
2424
2063
|
PoaWithdrawalNotFoundError,
|