lampamazaza-new-intents-sdk 0.47.1
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/LICENSE +21 -0
- package/README.md +1083 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +19 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.cjs +10 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-constants.js +7 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +44 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.js +42 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +111 -0
- package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +110 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.cjs +8 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-constants.js +6 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +47 -0
- package/dist/src/bridges/direct-bridge/direct-bridge-utils.js +44 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.cjs +155 -0
- package/dist/src/bridges/direct-bridge/direct-bridge.js +154 -0
- package/dist/src/bridges/direct-bridge/error.cjs +16 -0
- package/dist/src/bridges/direct-bridge/error.d.cts +12 -0
- package/dist/src/bridges/direct-bridge/error.d.ts +12 -0
- package/dist/src/bridges/direct-bridge/error.js +15 -0
- package/dist/src/bridges/hot-bridge/error.cjs +23 -0
- package/dist/src/bridges/hot-bridge/error.d.cts +19 -0
- package/dist/src/bridges/hot-bridge/error.d.ts +19 -0
- package/dist/src/bridges/hot-bridge/error.js +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +21 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +6 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +20 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.cjs +11 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-constants.js +9 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +66 -0
- package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +61 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.cjs +241 -0
- package/dist/src/bridges/hot-bridge/hot-bridge.js +239 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.cjs +59 -0
- package/dist/src/bridges/intents-bridge/intents-bridge.js +59 -0
- package/dist/src/bridges/omni-bridge/error.cjs +54 -0
- package/dist/src/bridges/omni-bridge/error.d.cts +41 -0
- package/dist/src/bridges/omni-bridge/error.d.ts +41 -0
- package/dist/src/bridges/omni-bridge/error.js +49 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.cjs +12 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-constants.js +8 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +153 -0
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +143 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +316 -0
- package/dist/src/bridges/omni-bridge/omni-bridge.js +314 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +76 -0
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +73 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.cjs +175 -0
- package/dist/src/bridges/poa-bridge/poa-bridge.js +173 -0
- package/dist/src/bridges/poa-bridge/poa-constants.cjs +6 -0
- package/dist/src/bridges/poa-bridge/poa-constants.js +5 -0
- package/dist/src/classes/errors.cjs +87 -0
- package/dist/src/classes/errors.d.cts +48 -0
- package/dist/src/classes/errors.d.ts +48 -0
- package/dist/src/classes/errors.js +81 -0
- package/dist/src/constants/bridge-name-enum.cjs +11 -0
- package/dist/src/constants/bridge-name-enum.d.cts +11 -0
- package/dist/src/constants/bridge-name-enum.d.ts +11 -0
- package/dist/src/constants/bridge-name-enum.js +10 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
- package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
- package/dist/src/constants/public-rpc-urls.cjs +25 -0
- package/dist/src/constants/public-rpc-urls.js +24 -0
- package/dist/src/constants/route-enum.cjs +13 -0
- package/dist/src/constants/route-enum.d.cts +13 -0
- package/dist/src/constants/route-enum.d.ts +13 -0
- package/dist/src/constants/route-enum.js +12 -0
- package/dist/src/constants/withdrawal-timing.cjs +68 -0
- package/dist/src/constants/withdrawal-timing.js +68 -0
- package/dist/src/core/withdrawal-watcher.cjs +86 -0
- package/dist/src/core/withdrawal-watcher.d.cts +18 -0
- package/dist/src/core/withdrawal-watcher.d.ts +19 -0
- package/dist/src/core/withdrawal-watcher.js +82 -0
- package/dist/src/intents/expirable-nonce.cjs +90 -0
- package/dist/src/intents/expirable-nonce.d.cts +44 -0
- package/dist/src/intents/expirable-nonce.d.ts +45 -0
- package/dist/src/intents/expirable-nonce.js +82 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.cjs +85 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.cts +20 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.d.ts +24 -0
- package/dist/src/intents/intent-executer-impl/intent-executer.js +85 -0
- package/dist/src/intents/intent-hash.cjs +48 -0
- package/dist/src/intents/intent-hash.d.cts +8 -0
- package/dist/src/intents/intent-hash.d.ts +8 -0
- package/dist/src/intents/intent-hash.js +47 -0
- package/dist/src/intents/intent-hashes/erc191.cjs +38 -0
- package/dist/src/intents/intent-hashes/erc191.js +37 -0
- package/dist/src/intents/intent-hashes/nep413.cjs +23 -0
- package/dist/src/intents/intent-hashes/nep413.js +22 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.cjs +26 -0
- package/dist/src/intents/intent-hashes/raw-ed25519.js +25 -0
- package/dist/src/intents/intent-hashes/sep53.cjs +36 -0
- package/dist/src/intents/intent-hashes/sep53.js +35 -0
- package/dist/src/intents/intent-hashes/tip191.cjs +39 -0
- package/dist/src/intents/intent-hashes/tip191.js +38 -0
- package/dist/src/intents/intent-hashes/ton-connect.cjs +105 -0
- package/dist/src/intents/intent-hashes/ton-connect.js +104 -0
- package/dist/src/intents/intent-hashes/webauthn.cjs +26 -0
- package/dist/src/intents/intent-hashes/webauthn.js +25 -0
- package/dist/src/intents/intent-payload-builder.cjs +208 -0
- package/dist/src/intents/intent-payload-builder.d.cts +161 -0
- package/dist/src/intents/intent-payload-builder.d.ts +161 -0
- package/dist/src/intents/intent-payload-builder.js +207 -0
- package/dist/src/intents/intent-payload-factory.cjs +23 -0
- package/dist/src/intents/intent-payload-factory.js +21 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +43 -0
- package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +42 -0
- package/dist/src/intents/intent-signer-impl/factories.cjs +19 -0
- package/dist/src/intents/intent-signer-impl/factories.d.cts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.d.ts +11 -0
- package/dist/src/intents/intent-signer-impl/factories.js +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +22 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.cts +15 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.d.ts +16 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.js +21 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +37 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.cts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.d.ts +14 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-nep413.js +36 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.cjs +8 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-noop.js +7 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +31 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.cts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.d.ts +17 -0
- package/dist/src/intents/intent-signer-impl/intent-signer-viem.js +30 -0
- package/dist/src/intents/interfaces/intent-executer.d.ts +2 -0
- package/dist/src/intents/interfaces/intent-relayer.d.cts +43 -0
- package/dist/src/intents/interfaces/intent-relayer.d.ts +43 -0
- package/dist/src/intents/interfaces/intent-signer.d.cts +8 -0
- package/dist/src/intents/interfaces/intent-signer.d.ts +8 -0
- package/dist/src/intents/interfaces/salt-manager.d.cts +9 -0
- package/dist/src/intents/interfaces/salt-manager.d.ts +9 -0
- package/dist/src/intents/salt-manager.cjs +74 -0
- package/dist/src/intents/salt-manager.js +72 -0
- package/dist/src/intents/shared-types.d.cts +20 -0
- package/dist/src/intents/shared-types.d.ts +20 -0
- package/dist/src/lib/array.cjs +11 -0
- package/dist/src/lib/array.js +10 -0
- package/dist/src/lib/caip2.cjs +50 -0
- package/dist/src/lib/caip2.d.cts +38 -0
- package/dist/src/lib/caip2.d.ts +38 -0
- package/dist/src/lib/caip2.js +48 -0
- package/dist/src/lib/configure-rpc-config.cjs +20 -0
- package/dist/src/lib/configure-rpc-config.js +18 -0
- package/dist/src/lib/estimate-fee.cjs +96 -0
- package/dist/src/lib/estimate-fee.js +94 -0
- package/dist/src/lib/hex.cjs +11 -0
- package/dist/src/lib/hex.js +10 -0
- package/dist/src/lib/nep413.cjs +42 -0
- package/dist/src/lib/nep413.d.cts +14 -0
- package/dist/src/lib/nep413.d.ts +14 -0
- package/dist/src/lib/nep413.js +41 -0
- package/dist/src/lib/object.cjs +10 -0
- package/dist/src/lib/object.js +9 -0
- package/dist/src/lib/parse-defuse-asset-id.cjs +15 -0
- package/dist/src/lib/parse-defuse-asset-id.js +14 -0
- package/dist/src/lib/route-config-factory.cjs +43 -0
- package/dist/src/lib/route-config-factory.d.cts +13 -0
- package/dist/src/lib/route-config-factory.d.ts +13 -0
- package/dist/src/lib/route-config-factory.js +37 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +17 -0
- package/dist/src/lib/tokensUsdPricesHttpClient/apis.js +16 -0
- package/dist/src/lib/validateAddress.cjs +271 -0
- package/dist/src/lib/validateAddress.d.cts +14 -0
- package/dist/src/lib/validateAddress.d.ts +14 -0
- package/dist/src/lib/validateAddress.js +270 -0
- package/dist/src/sdk.cjs +435 -0
- package/dist/src/sdk.d.cts +231 -0
- package/dist/src/sdk.d.ts +231 -0
- package/dist/src/sdk.js +433 -0
- package/dist/src/shared-types.d.cts +378 -0
- package/dist/src/shared-types.d.ts +378 -0
- package/package.json +62 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RouteEnum } from "../../constants/route-enum.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT, NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
|
|
3
|
+
import { assert, unwrapNearFailoverRpcProvider, utils } from "lampamazaza-internal-utils";
|
|
4
|
+
import { providers } from "near-api-js";
|
|
5
|
+
|
|
6
|
+
//#region src/bridges/direct-bridge/direct-bridge-utils.ts
|
|
7
|
+
function createWithdrawIntentPrimitive(params) {
|
|
8
|
+
if (params.assetId === NEAR_NATIVE_ASSET_ID && params.msg === void 0) return {
|
|
9
|
+
intent: "native_withdraw",
|
|
10
|
+
receiver_id: params.destinationAddress,
|
|
11
|
+
amount: params.amount.toString()
|
|
12
|
+
};
|
|
13
|
+
const { contractId: tokenAccountId, standard } = utils.parseDefuseAssetId(params.assetId);
|
|
14
|
+
assert(standard === "nep141", "Only NEP-141 is supported");
|
|
15
|
+
if (params.msg !== void 0) params.logger?.warn("min_gas is not set for direct-bridge withdrawal with msg, gas consumption is unpredictable");
|
|
16
|
+
return {
|
|
17
|
+
intent: "ft_withdraw",
|
|
18
|
+
token: tokenAccountId,
|
|
19
|
+
receiver_id: params.destinationAddress,
|
|
20
|
+
amount: params.amount.toString(),
|
|
21
|
+
storage_deposit: params.storageDeposit > 0n ? params.storageDeposit.toString() : void 0,
|
|
22
|
+
msg: params.msg,
|
|
23
|
+
min_gas: params.msg == null ? MIN_GAS_AMOUNT : void 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function withdrawalParamsInvariant(params) {
|
|
27
|
+
assert(!params.routeConfig ? true : params.routeConfig.route === RouteEnum.NearWithdrawal, "Bridge is not direct");
|
|
28
|
+
}
|
|
29
|
+
async function accountExistsInNEAR(provider, accountId) {
|
|
30
|
+
try {
|
|
31
|
+
await unwrapNearFailoverRpcProvider(provider).query({
|
|
32
|
+
request_type: "view_account",
|
|
33
|
+
account_id: accountId,
|
|
34
|
+
finality: "final"
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof providers.TypedError && error.type === "AccountDoesNotExist") return false;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { accountExistsInNEAR, createWithdrawIntentPrimitive, withdrawalParamsInvariant };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_errors = require('../../classes/errors.cjs');
|
|
3
|
+
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
4
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
5
|
+
const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
6
|
+
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
7
|
+
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
8
|
+
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
9
|
+
const require_direct_bridge_constants = require('./direct-bridge-constants.cjs');
|
|
10
|
+
const require_direct_bridge_utils = require('./direct-bridge-utils.cjs');
|
|
11
|
+
const require_error = require('./error.cjs');
|
|
12
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
13
|
+
let lru_cache = require("lru-cache");
|
|
14
|
+
|
|
15
|
+
//#region src/bridges/direct-bridge/direct-bridge.ts
|
|
16
|
+
var DirectBridge = class {
|
|
17
|
+
constructor({ envConfig, nearProvider, solverRelayApiKey }) {
|
|
18
|
+
this.route = require_route_enum.RouteEnum.NearWithdrawal;
|
|
19
|
+
this.storageDepositCache = new lru_cache.LRUCache({
|
|
20
|
+
max: 100,
|
|
21
|
+
ttl: 36e5
|
|
22
|
+
});
|
|
23
|
+
this.accountExistenceCache = new lru_cache.LRUCache({
|
|
24
|
+
max: 100,
|
|
25
|
+
ttl: 36e5
|
|
26
|
+
});
|
|
27
|
+
this.envConfig = envConfig;
|
|
28
|
+
this.nearProvider = nearProvider;
|
|
29
|
+
this.solverRelayApiKey = solverRelayApiKey;
|
|
30
|
+
}
|
|
31
|
+
is(routeConfig) {
|
|
32
|
+
return routeConfig.route === require_route_enum.RouteEnum.NearWithdrawal;
|
|
33
|
+
}
|
|
34
|
+
async supports(params) {
|
|
35
|
+
if (params.routeConfig != null && !this.is(params.routeConfig)) return false;
|
|
36
|
+
const isValid = this.parseAssetId(params.assetId) != null;
|
|
37
|
+
if (!isValid && params.routeConfig != null) throw new require_errors.UnsupportedAssetIdError(params.assetId, "`assetId` does not match `routeConfig`.");
|
|
38
|
+
return isValid;
|
|
39
|
+
}
|
|
40
|
+
parseAssetId(assetId) {
|
|
41
|
+
const parsed = require_parse_defuse_asset_id.parseDefuseAssetId(assetId);
|
|
42
|
+
if (parsed.standard === "nep141") return Object.assign(parsed, {
|
|
43
|
+
blockchain: require_caip2.Chains.Near,
|
|
44
|
+
bridgeName: require_bridge_name_enum.BridgeNameEnum.None,
|
|
45
|
+
address: parsed.contractId
|
|
46
|
+
});
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
createWithdrawalIntents(args) {
|
|
50
|
+
require_direct_bridge_utils.withdrawalParamsInvariant(args.withdrawalParams);
|
|
51
|
+
const intents = [];
|
|
52
|
+
if (args.feeEstimation.quote != null) intents.push({
|
|
53
|
+
intent: "token_diff",
|
|
54
|
+
diff: {
|
|
55
|
+
[args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
|
|
56
|
+
[args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
|
|
57
|
+
},
|
|
58
|
+
referral: args.referral
|
|
59
|
+
});
|
|
60
|
+
const intent = require_direct_bridge_utils.createWithdrawIntentPrimitive({
|
|
61
|
+
assetId: args.withdrawalParams.assetId,
|
|
62
|
+
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
63
|
+
amount: args.withdrawalParams.amount,
|
|
64
|
+
storageDeposit: require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.NearWithdrawal, "storageDepositFee"),
|
|
65
|
+
msg: args.withdrawalParams.routeConfig?.msg,
|
|
66
|
+
logger: args.logger
|
|
67
|
+
});
|
|
68
|
+
intents.push(intent);
|
|
69
|
+
return Promise.resolve(intents);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Direct bridge doesn't have withdrawal restrictions.
|
|
73
|
+
*/
|
|
74
|
+
async validateWithdrawal(args) {
|
|
75
|
+
if (require_validateAddress.validateAddress(args.destinationAddress, require_caip2.Chains.Near) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, require_caip2.Chains.Near);
|
|
76
|
+
if (lampamazaza_internal_utils.utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new require_error.DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
|
|
77
|
+
}
|
|
78
|
+
async estimateWithdrawalFee(args) {
|
|
79
|
+
require_direct_bridge_utils.withdrawalParamsInvariant(args.withdrawalParams);
|
|
80
|
+
const { contractId: tokenAccountId, standard } = lampamazaza_internal_utils.utils.parseDefuseAssetId(args.withdrawalParams.assetId);
|
|
81
|
+
(0, lampamazaza_internal_utils.assert)(standard === "nep141", "Only NEP-141 is supported");
|
|
82
|
+
if (args.withdrawalParams.assetId === require_direct_bridge_constants.NEAR_NATIVE_ASSET_ID && args.withdrawalParams.routeConfig?.msg === void 0) return {
|
|
83
|
+
amount: 0n,
|
|
84
|
+
quote: null,
|
|
85
|
+
underlyingFees: { [require_route_enum.RouteEnum.NearWithdrawal]: { storageDepositFee: 0n } }
|
|
86
|
+
};
|
|
87
|
+
const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(tokenAccountId, args.withdrawalParams.destinationAddress);
|
|
88
|
+
if (minStorageBalance <= userStorageBalance) return {
|
|
89
|
+
amount: 0n,
|
|
90
|
+
quote: null,
|
|
91
|
+
underlyingFees: { [require_route_enum.RouteEnum.NearWithdrawal]: { storageDepositFee: 0n } }
|
|
92
|
+
};
|
|
93
|
+
const feeAssetId = require_direct_bridge_constants.NEAR_NATIVE_ASSET_ID;
|
|
94
|
+
const feeAmount = minStorageBalance - userStorageBalance;
|
|
95
|
+
const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await require_estimate_fee.getFeeQuote({
|
|
96
|
+
feeAmount,
|
|
97
|
+
feeAssetId,
|
|
98
|
+
tokenAssetId: args.withdrawalParams.assetId,
|
|
99
|
+
logger: args.logger,
|
|
100
|
+
envConfig: this.envConfig,
|
|
101
|
+
quoteOptions: args.quoteOptions,
|
|
102
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
|
|
106
|
+
quote: feeQuote,
|
|
107
|
+
underlyingFees: { [require_route_enum.RouteEnum.NearWithdrawal]: { storageDepositFee: feeAmount } }
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
112
|
+
*/
|
|
113
|
+
async getCachedStorageDepositValue(contractId, accountId) {
|
|
114
|
+
const key = `${contractId}${accountId}`;
|
|
115
|
+
const cached = this.storageDepositCache.get(key);
|
|
116
|
+
if (cached !== void 0) return cached;
|
|
117
|
+
const result = await Promise.all([(0, lampamazaza_internal_utils.getNearNep141MinStorageBalance)({
|
|
118
|
+
contractId,
|
|
119
|
+
nearProvider: this.nearProvider
|
|
120
|
+
}), (0, lampamazaza_internal_utils.getNearNep141StorageBalance)({
|
|
121
|
+
contractId,
|
|
122
|
+
accountId,
|
|
123
|
+
nearProvider: this.nearProvider
|
|
124
|
+
})]);
|
|
125
|
+
if (result[1] >= result[0]) this.storageDepositCache.set(key, result);
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks account existence to avoid frequent RPC calls.
|
|
130
|
+
*/
|
|
131
|
+
async getCachedAccountExistenceCheck(accountId) {
|
|
132
|
+
const cached = this.accountExistenceCache.get(accountId);
|
|
133
|
+
if (cached !== void 0) return cached;
|
|
134
|
+
const exist = await require_direct_bridge_utils.accountExistsInNEAR(this.nearProvider, accountId);
|
|
135
|
+
if (exist) this.accountExistenceCache.set(accountId, exist);
|
|
136
|
+
return exist;
|
|
137
|
+
}
|
|
138
|
+
createWithdrawalIdentifier(args) {
|
|
139
|
+
return {
|
|
140
|
+
landingChain: require_caip2.Chains.Near,
|
|
141
|
+
index: args.index,
|
|
142
|
+
withdrawalParams: args.withdrawalParams,
|
|
143
|
+
tx: args.tx
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async describeWithdrawal(args) {
|
|
147
|
+
return {
|
|
148
|
+
status: "completed",
|
|
149
|
+
txHash: args.tx.hash
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
exports.DirectBridge = DirectBridge;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { InvalidDestinationAddressForWithdrawalError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
|
+
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
|
+
import { Chains } from "../../lib/caip2.js";
|
|
4
|
+
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
5
|
+
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
6
|
+
import { validateAddress } from "../../lib/validateAddress.js";
|
|
7
|
+
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
8
|
+
import { NEAR_NATIVE_ASSET_ID } from "./direct-bridge-constants.js";
|
|
9
|
+
import { accountExistsInNEAR, createWithdrawIntentPrimitive, withdrawalParamsInvariant } from "./direct-bridge-utils.js";
|
|
10
|
+
import { DestinationExplicitNearAccountDoesntExistError } from "./error.js";
|
|
11
|
+
import { assert, getNearNep141MinStorageBalance, getNearNep141StorageBalance, utils } from "lampamazaza-internal-utils";
|
|
12
|
+
import { LRUCache } from "lru-cache";
|
|
13
|
+
|
|
14
|
+
//#region src/bridges/direct-bridge/direct-bridge.ts
|
|
15
|
+
var DirectBridge = class {
|
|
16
|
+
constructor({ envConfig, nearProvider, solverRelayApiKey }) {
|
|
17
|
+
this.route = RouteEnum.NearWithdrawal;
|
|
18
|
+
this.storageDepositCache = new LRUCache({
|
|
19
|
+
max: 100,
|
|
20
|
+
ttl: 36e5
|
|
21
|
+
});
|
|
22
|
+
this.accountExistenceCache = new LRUCache({
|
|
23
|
+
max: 100,
|
|
24
|
+
ttl: 36e5
|
|
25
|
+
});
|
|
26
|
+
this.envConfig = envConfig;
|
|
27
|
+
this.nearProvider = nearProvider;
|
|
28
|
+
this.solverRelayApiKey = solverRelayApiKey;
|
|
29
|
+
}
|
|
30
|
+
is(routeConfig) {
|
|
31
|
+
return routeConfig.route === RouteEnum.NearWithdrawal;
|
|
32
|
+
}
|
|
33
|
+
async supports(params) {
|
|
34
|
+
if (params.routeConfig != null && !this.is(params.routeConfig)) return false;
|
|
35
|
+
const isValid = this.parseAssetId(params.assetId) != null;
|
|
36
|
+
if (!isValid && params.routeConfig != null) throw new UnsupportedAssetIdError(params.assetId, "`assetId` does not match `routeConfig`.");
|
|
37
|
+
return isValid;
|
|
38
|
+
}
|
|
39
|
+
parseAssetId(assetId) {
|
|
40
|
+
const parsed = parseDefuseAssetId(assetId);
|
|
41
|
+
if (parsed.standard === "nep141") return Object.assign(parsed, {
|
|
42
|
+
blockchain: Chains.Near,
|
|
43
|
+
bridgeName: BridgeNameEnum.None,
|
|
44
|
+
address: parsed.contractId
|
|
45
|
+
});
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
createWithdrawalIntents(args) {
|
|
49
|
+
withdrawalParamsInvariant(args.withdrawalParams);
|
|
50
|
+
const intents = [];
|
|
51
|
+
if (args.feeEstimation.quote != null) intents.push({
|
|
52
|
+
intent: "token_diff",
|
|
53
|
+
diff: {
|
|
54
|
+
[args.feeEstimation.quote.defuse_asset_identifier_in]: `-${args.feeEstimation.quote.amount_in}`,
|
|
55
|
+
[args.feeEstimation.quote.defuse_asset_identifier_out]: args.feeEstimation.quote.amount_out
|
|
56
|
+
},
|
|
57
|
+
referral: args.referral
|
|
58
|
+
});
|
|
59
|
+
const intent = createWithdrawIntentPrimitive({
|
|
60
|
+
assetId: args.withdrawalParams.assetId,
|
|
61
|
+
destinationAddress: args.withdrawalParams.destinationAddress,
|
|
62
|
+
amount: args.withdrawalParams.amount,
|
|
63
|
+
storageDeposit: getUnderlyingFee(args.feeEstimation, RouteEnum.NearWithdrawal, "storageDepositFee"),
|
|
64
|
+
msg: args.withdrawalParams.routeConfig?.msg,
|
|
65
|
+
logger: args.logger
|
|
66
|
+
});
|
|
67
|
+
intents.push(intent);
|
|
68
|
+
return Promise.resolve(intents);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Direct bridge doesn't have withdrawal restrictions.
|
|
72
|
+
*/
|
|
73
|
+
async validateWithdrawal(args) {
|
|
74
|
+
if (validateAddress(args.destinationAddress, Chains.Near) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, Chains.Near);
|
|
75
|
+
if (utils.isImplicitAccount(args.destinationAddress) === false && await this.getCachedAccountExistenceCheck(args.destinationAddress) === false) throw new DestinationExplicitNearAccountDoesntExistError(args.destinationAddress);
|
|
76
|
+
}
|
|
77
|
+
async estimateWithdrawalFee(args) {
|
|
78
|
+
withdrawalParamsInvariant(args.withdrawalParams);
|
|
79
|
+
const { contractId: tokenAccountId, standard } = utils.parseDefuseAssetId(args.withdrawalParams.assetId);
|
|
80
|
+
assert(standard === "nep141", "Only NEP-141 is supported");
|
|
81
|
+
if (args.withdrawalParams.assetId === NEAR_NATIVE_ASSET_ID && args.withdrawalParams.routeConfig?.msg === void 0) return {
|
|
82
|
+
amount: 0n,
|
|
83
|
+
quote: null,
|
|
84
|
+
underlyingFees: { [RouteEnum.NearWithdrawal]: { storageDepositFee: 0n } }
|
|
85
|
+
};
|
|
86
|
+
const [minStorageBalance, userStorageBalance] = await this.getCachedStorageDepositValue(tokenAccountId, args.withdrawalParams.destinationAddress);
|
|
87
|
+
if (minStorageBalance <= userStorageBalance) return {
|
|
88
|
+
amount: 0n,
|
|
89
|
+
quote: null,
|
|
90
|
+
underlyingFees: { [RouteEnum.NearWithdrawal]: { storageDepositFee: 0n } }
|
|
91
|
+
};
|
|
92
|
+
const feeAssetId = NEAR_NATIVE_ASSET_ID;
|
|
93
|
+
const feeAmount = minStorageBalance - userStorageBalance;
|
|
94
|
+
const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await getFeeQuote({
|
|
95
|
+
feeAmount,
|
|
96
|
+
feeAssetId,
|
|
97
|
+
tokenAssetId: args.withdrawalParams.assetId,
|
|
98
|
+
logger: args.logger,
|
|
99
|
+
envConfig: this.envConfig,
|
|
100
|
+
quoteOptions: args.quoteOptions,
|
|
101
|
+
solverRelayApiKey: this.solverRelayApiKey
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
|
|
105
|
+
quote: feeQuote,
|
|
106
|
+
underlyingFees: { [RouteEnum.NearWithdrawal]: { storageDepositFee: feeAmount } }
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets storage deposit for a token to avoid frequent RPC calls.
|
|
111
|
+
*/
|
|
112
|
+
async getCachedStorageDepositValue(contractId, accountId) {
|
|
113
|
+
const key = `${contractId}${accountId}`;
|
|
114
|
+
const cached = this.storageDepositCache.get(key);
|
|
115
|
+
if (cached !== void 0) return cached;
|
|
116
|
+
const result = await Promise.all([getNearNep141MinStorageBalance({
|
|
117
|
+
contractId,
|
|
118
|
+
nearProvider: this.nearProvider
|
|
119
|
+
}), getNearNep141StorageBalance({
|
|
120
|
+
contractId,
|
|
121
|
+
accountId,
|
|
122
|
+
nearProvider: this.nearProvider
|
|
123
|
+
})]);
|
|
124
|
+
if (result[1] >= result[0]) this.storageDepositCache.set(key, result);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Checks account existence to avoid frequent RPC calls.
|
|
129
|
+
*/
|
|
130
|
+
async getCachedAccountExistenceCheck(accountId) {
|
|
131
|
+
const cached = this.accountExistenceCache.get(accountId);
|
|
132
|
+
if (cached !== void 0) return cached;
|
|
133
|
+
const exist = await accountExistsInNEAR(this.nearProvider, accountId);
|
|
134
|
+
if (exist) this.accountExistenceCache.set(accountId, exist);
|
|
135
|
+
return exist;
|
|
136
|
+
}
|
|
137
|
+
createWithdrawalIdentifier(args) {
|
|
138
|
+
return {
|
|
139
|
+
landingChain: Chains.Near,
|
|
140
|
+
index: args.index,
|
|
141
|
+
withdrawalParams: args.withdrawalParams,
|
|
142
|
+
tx: args.tx
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async describeWithdrawal(args) {
|
|
146
|
+
return {
|
|
147
|
+
status: "completed",
|
|
148
|
+
txHash: args.tx.hash
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { DirectBridge };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
3
|
+
|
|
4
|
+
//#region src/bridges/direct-bridge/error.ts
|
|
5
|
+
var DestinationExplicitNearAccountDoesntExistError = class extends lampamazaza_internal_utils.BaseError {
|
|
6
|
+
constructor(accountId) {
|
|
7
|
+
super("Destination explicit NEAR account doesn't exist.", {
|
|
8
|
+
metaMessages: [`Account Id: ${accountId}`],
|
|
9
|
+
name: "DestinationExplicitNearAccountDoesntExistError"
|
|
10
|
+
});
|
|
11
|
+
this.accountId = accountId;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.DestinationExplicitNearAccountDoesntExistError = DestinationExplicitNearAccountDoesntExistError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/direct-bridge/error.d.ts
|
|
4
|
+
type DestinationExplicitNearAccountDoesntExistErrorType = DestinationExplicitNearAccountDoesntExistError & {
|
|
5
|
+
name: "DestinationExplicitNearAccountDoesntExistError";
|
|
6
|
+
};
|
|
7
|
+
declare class DestinationExplicitNearAccountDoesntExistError extends BaseError {
|
|
8
|
+
accountId: string;
|
|
9
|
+
constructor(accountId: string);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/direct-bridge/error.d.ts
|
|
4
|
+
type DestinationExplicitNearAccountDoesntExistErrorType = DestinationExplicitNearAccountDoesntExistError & {
|
|
5
|
+
name: "DestinationExplicitNearAccountDoesntExistError";
|
|
6
|
+
};
|
|
7
|
+
declare class DestinationExplicitNearAccountDoesntExistError extends BaseError {
|
|
8
|
+
accountId: string;
|
|
9
|
+
constructor(accountId: string);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DestinationExplicitNearAccountDoesntExistError, DestinationExplicitNearAccountDoesntExistErrorType };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/direct-bridge/error.ts
|
|
4
|
+
var DestinationExplicitNearAccountDoesntExistError = class extends BaseError {
|
|
5
|
+
constructor(accountId) {
|
|
6
|
+
super("Destination explicit NEAR account doesn't exist.", {
|
|
7
|
+
metaMessages: [`Account Id: ${accountId}`],
|
|
8
|
+
name: "DestinationExplicitNearAccountDoesntExistError"
|
|
9
|
+
});
|
|
10
|
+
this.accountId = accountId;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { DestinationExplicitNearAccountDoesntExistError };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
3
|
+
|
|
4
|
+
//#region src/bridges/hot-bridge/error.ts
|
|
5
|
+
var HotWithdrawalNotFoundError = class extends lampamazaza_internal_utils.BaseError {
|
|
6
|
+
constructor(txHash, index) {
|
|
7
|
+
super("Withdrawal with given index is not found.", {
|
|
8
|
+
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
9
|
+
name: "HotWithdrawalNotFoundError"
|
|
10
|
+
});
|
|
11
|
+
this.txHash = txHash;
|
|
12
|
+
this.index = index;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var HotWithdrawalApiFeeRequestTimeoutError = class extends lampamazaza_internal_utils.BaseError {
|
|
16
|
+
constructor() {
|
|
17
|
+
super("Hot bridge withdrawal fee request timed out.", { name: "HotWithdrawalApiFeeRequestTimeoutError" });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.HotWithdrawalApiFeeRequestTimeoutError = HotWithdrawalApiFeeRequestTimeoutError;
|
|
23
|
+
exports.HotWithdrawalNotFoundError = HotWithdrawalNotFoundError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/hot-bridge/error.d.ts
|
|
4
|
+
type HotWithdrawalNotFoundErrorType = HotWithdrawalNotFoundError & {
|
|
5
|
+
name: "HotWithdrawalNotFoundError";
|
|
6
|
+
};
|
|
7
|
+
declare class HotWithdrawalNotFoundError extends BaseError {
|
|
8
|
+
txHash: string;
|
|
9
|
+
index: number;
|
|
10
|
+
constructor(txHash: string, index: number);
|
|
11
|
+
}
|
|
12
|
+
type HotWithdrawalApiFeeRequestTimeoutErrorType = HotWithdrawalApiFeeRequestTimeoutError & {
|
|
13
|
+
name: "HotWithdrawalApiFeeRequestTimeoutError";
|
|
14
|
+
};
|
|
15
|
+
declare class HotWithdrawalApiFeeRequestTimeoutError extends BaseError {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/hot-bridge/error.d.ts
|
|
4
|
+
type HotWithdrawalNotFoundErrorType = HotWithdrawalNotFoundError & {
|
|
5
|
+
name: "HotWithdrawalNotFoundError";
|
|
6
|
+
};
|
|
7
|
+
declare class HotWithdrawalNotFoundError extends BaseError {
|
|
8
|
+
txHash: string;
|
|
9
|
+
index: number;
|
|
10
|
+
constructor(txHash: string, index: number);
|
|
11
|
+
}
|
|
12
|
+
type HotWithdrawalApiFeeRequestTimeoutErrorType = HotWithdrawalApiFeeRequestTimeoutError & {
|
|
13
|
+
name: "HotWithdrawalApiFeeRequestTimeoutError";
|
|
14
|
+
};
|
|
15
|
+
declare class HotWithdrawalApiFeeRequestTimeoutError extends BaseError {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalApiFeeRequestTimeoutErrorType, HotWithdrawalNotFoundError, HotWithdrawalNotFoundErrorType };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/hot-bridge/error.ts
|
|
4
|
+
var HotWithdrawalNotFoundError = class extends BaseError {
|
|
5
|
+
constructor(txHash, index) {
|
|
6
|
+
super("Withdrawal with given index is not found.", {
|
|
7
|
+
metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
|
|
8
|
+
name: "HotWithdrawalNotFoundError"
|
|
9
|
+
});
|
|
10
|
+
this.txHash = txHash;
|
|
11
|
+
this.index = index;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var HotWithdrawalApiFeeRequestTimeoutError = class extends BaseError {
|
|
15
|
+
constructor() {
|
|
16
|
+
super("Hot bridge withdrawal fee request timed out.", { name: "HotWithdrawalApiFeeRequestTimeoutError" });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { HotWithdrawalApiFeeRequestTimeoutError, HotWithdrawalNotFoundError };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/hot-bridge/hot-bridge-chains.ts
|
|
4
|
+
const HotBridgeChains = [
|
|
5
|
+
require_caip2.Chains.Polygon,
|
|
6
|
+
require_caip2.Chains.BNB,
|
|
7
|
+
require_caip2.Chains.TON,
|
|
8
|
+
require_caip2.Chains.Optimism,
|
|
9
|
+
require_caip2.Chains.Avalanche,
|
|
10
|
+
require_caip2.Chains.Monad,
|
|
11
|
+
require_caip2.Chains.Stellar,
|
|
12
|
+
require_caip2.Chains.LayerX,
|
|
13
|
+
require_caip2.Chains.Adi,
|
|
14
|
+
require_caip2.Chains.Scroll,
|
|
15
|
+
require_caip2.Chains.Plasma
|
|
16
|
+
];
|
|
17
|
+
const HotBridgeEVMChains = HotBridgeChains.filter((a) => a.startsWith("eip155:"));
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.HotBridgeChains = HotBridgeChains;
|
|
21
|
+
exports.HotBridgeEVMChains = HotBridgeEVMChains;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/bridges/hot-bridge/hot-bridge-chains.d.ts
|
|
2
|
+
type HotBridgeChain = (typeof HotBridgeChains)[number];
|
|
3
|
+
type HotBridgeEVMChain = Extract<HotBridgeChain, `eip155:${string}`>;
|
|
4
|
+
declare const HotBridgeChains: ("eip155:10" | "eip155:56" | "eip155:137" | "eip155:143" | "eip155:196" | "eip155:36900" | "eip155:43114" | "tvm:-239" | "stellar:pubnet" | "eip155:9745" | "eip155:534352")[];
|
|
5
|
+
//#endregion
|
|
6
|
+
export { HotBridgeEVMChain };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/bridges/hot-bridge/hot-bridge-chains.d.ts
|
|
2
|
+
type HotBridgeChain = (typeof HotBridgeChains)[number];
|
|
3
|
+
type HotBridgeEVMChain = Extract<HotBridgeChain, `eip155:${string}`>;
|
|
4
|
+
declare const HotBridgeChains: ("eip155:10" | "eip155:56" | "eip155:137" | "eip155:143" | "eip155:196" | "eip155:36900" | "eip155:43114" | "tvm:-239" | "stellar:pubnet" | "eip155:9745" | "eip155:534352")[];
|
|
5
|
+
//#endregion
|
|
6
|
+
export { HotBridgeEVMChain };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Chains } from "../../lib/caip2.js";
|
|
2
|
+
|
|
3
|
+
//#region src/bridges/hot-bridge/hot-bridge-chains.ts
|
|
4
|
+
const HotBridgeChains = [
|
|
5
|
+
Chains.Polygon,
|
|
6
|
+
Chains.BNB,
|
|
7
|
+
Chains.TON,
|
|
8
|
+
Chains.Optimism,
|
|
9
|
+
Chains.Avalanche,
|
|
10
|
+
Chains.Monad,
|
|
11
|
+
Chains.Stellar,
|
|
12
|
+
Chains.LayerX,
|
|
13
|
+
Chains.Adi,
|
|
14
|
+
Chains.Scroll,
|
|
15
|
+
Chains.Plasma
|
|
16
|
+
];
|
|
17
|
+
const HotBridgeEVMChains = HotBridgeChains.filter((a) => a.startsWith("eip155:"));
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { HotBridgeChains, HotBridgeEVMChains };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/bridges/hot-bridge/hot-bridge-constants.ts
|
|
3
|
+
const HotWithdrawStatus = {
|
|
4
|
+
Completed: "COMPLETED",
|
|
5
|
+
Canceled: "CANCELED"
|
|
6
|
+
};
|
|
7
|
+
const MIN_GAS_AMOUNT = "91300000000000";
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.HotWithdrawStatus = HotWithdrawStatus;
|
|
11
|
+
exports.MIN_GAS_AMOUNT = MIN_GAS_AMOUNT;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
|
+
const require_hot_bridge_chains = require('./hot-bridge-chains.cjs');
|
|
4
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
5
|
+
let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
|
|
6
|
+
|
|
7
|
+
//#region src/bridges/hot-bridge/hot-bridge-utils.ts
|
|
8
|
+
const MONAD_MAINNET_NETWORK_ID = 143;
|
|
9
|
+
const ADI_NETWORK_ID = 36900;
|
|
10
|
+
const PLASMA_NETWORK_ID = 9745;
|
|
11
|
+
const nativeTokenMapping = {
|
|
12
|
+
[require_caip2.Chains.BNB]: "nep245:v2_1.omni.hot.tg:56_11111111111111111111",
|
|
13
|
+
[require_caip2.Chains.Polygon]: "nep245:v2_1.omni.hot.tg:137_11111111111111111111",
|
|
14
|
+
[require_caip2.Chains.Monad]: "nep245:v2_1.omni.hot.tg:143_11111111111111111111",
|
|
15
|
+
[require_caip2.Chains.TON]: "nep245:v2_1.omni.hot.tg:1117_",
|
|
16
|
+
[require_caip2.Chains.Optimism]: "nep245:v2_1.omni.hot.tg:10_11111111111111111111",
|
|
17
|
+
[require_caip2.Chains.Avalanche]: "nep245:v2_1.omni.hot.tg:43114_11111111111111111111",
|
|
18
|
+
[require_caip2.Chains.Stellar]: "nep245:v2_1.omni.hot.tg:1100_111bzQBB5v7AhLyPMDwS8uJgQV24KaAPXtwyVWu2KXbbfQU6NXRCz",
|
|
19
|
+
[require_caip2.Chains.LayerX]: "nep245:v2_1.omni.hot.tg:196_11111111111111111111",
|
|
20
|
+
[require_caip2.Chains.Adi]: "nep245:v2_1.omni.hot.tg:36900_11111111111111111111",
|
|
21
|
+
[require_caip2.Chains.Scroll]: "nep245:v2_1.omni.hot.tg:534352_11111111111111111111",
|
|
22
|
+
[require_caip2.Chains.Plasma]: "nep245:v2_1.omni.hot.tg:9745_11111111111111111111"
|
|
23
|
+
};
|
|
24
|
+
const caip2NetworkIdMapping = {
|
|
25
|
+
[require_caip2.Chains.BNB]: _hot_labs_omni_sdk.Network.Bnb,
|
|
26
|
+
[require_caip2.Chains.Polygon]: _hot_labs_omni_sdk.Network.Polygon,
|
|
27
|
+
[require_caip2.Chains.Monad]: MONAD_MAINNET_NETWORK_ID,
|
|
28
|
+
[require_caip2.Chains.TON]: _hot_labs_omni_sdk.Network.Ton,
|
|
29
|
+
[require_caip2.Chains.Optimism]: _hot_labs_omni_sdk.Network.Optimism,
|
|
30
|
+
[require_caip2.Chains.Avalanche]: _hot_labs_omni_sdk.Network.Avalanche,
|
|
31
|
+
[require_caip2.Chains.Stellar]: _hot_labs_omni_sdk.Network.Stellar,
|
|
32
|
+
[require_caip2.Chains.LayerX]: _hot_labs_omni_sdk.Network.Xlayer,
|
|
33
|
+
[require_caip2.Chains.Adi]: ADI_NETWORK_ID,
|
|
34
|
+
[require_caip2.Chains.Scroll]: _hot_labs_omni_sdk.Network.Scroll,
|
|
35
|
+
[require_caip2.Chains.Plasma]: PLASMA_NETWORK_ID
|
|
36
|
+
};
|
|
37
|
+
const networkIdCAIP2Mapping = Object.fromEntries(Object.entries(caip2NetworkIdMapping).map(([k, v]) => [v, k]));
|
|
38
|
+
function getFeeAssetIdForChain(caip2) {
|
|
39
|
+
return nativeTokenMapping[caip2];
|
|
40
|
+
}
|
|
41
|
+
function toHotNetworkId(caip2) {
|
|
42
|
+
hotBlockchainInvariant(caip2);
|
|
43
|
+
return caip2NetworkIdMapping[caip2];
|
|
44
|
+
}
|
|
45
|
+
function hotNetworkIdToCAIP2(network) {
|
|
46
|
+
const mappedChain = networkIdCAIP2Mapping[network];
|
|
47
|
+
if (mappedChain != null) return mappedChain;
|
|
48
|
+
throw new Error(`Unsupported HOT Bridge chain = ${network}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* HOT returns hexified raw bytes. So we need to return more friendly/common string.
|
|
52
|
+
*/
|
|
53
|
+
function formatTxHash(txHash, caip2) {
|
|
54
|
+
if (caip2.startsWith("eip155:")) return `0x${txHash}`;
|
|
55
|
+
return txHash;
|
|
56
|
+
}
|
|
57
|
+
function hotBlockchainInvariant(blockchain) {
|
|
58
|
+
(0, lampamazaza_internal_utils.assert)(require_hot_bridge_chains.HotBridgeChains.includes(blockchain), `${blockchain} is not a valid HOT Bridge blockchain. Supported values: ${require_hot_bridge_chains.HotBridgeChains.join()}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.formatTxHash = formatTxHash;
|
|
63
|
+
exports.getFeeAssetIdForChain = getFeeAssetIdForChain;
|
|
64
|
+
exports.hotBlockchainInvariant = hotBlockchainInvariant;
|
|
65
|
+
exports.hotNetworkIdToCAIP2 = hotNetworkIdToCAIP2;
|
|
66
|
+
exports.toHotNetworkId = toHotNetworkId;
|