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,76 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
3
|
+
const require_poa_constants = require('./poa-constants.cjs');
|
|
4
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
5
|
+
|
|
6
|
+
//#region src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
7
|
+
function createWithdrawIntentPrimitive(params) {
|
|
8
|
+
const { contractId: tokenAccountId } = lampamazaza_internal_utils.utils.parseDefuseAssetId(params.assetId);
|
|
9
|
+
return {
|
|
10
|
+
intent: "ft_withdraw",
|
|
11
|
+
token: tokenAccountId,
|
|
12
|
+
receiver_id: tokenAccountId,
|
|
13
|
+
amount: params.amount.toString(),
|
|
14
|
+
memo: createWithdrawMemo({
|
|
15
|
+
receiverAddress: params.destinationAddress,
|
|
16
|
+
xrpMemo: params.destinationMemo
|
|
17
|
+
}),
|
|
18
|
+
min_gas: require_poa_constants.MIN_GAS_AMOUNT
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createWithdrawMemo({ receiverAddress, xrpMemo }) {
|
|
22
|
+
const memo = ["WITHDRAW_TO", receiverAddress.toLowerCase().startsWith("bitcoincash:") ? receiverAddress.slice(12) : receiverAddress];
|
|
23
|
+
if (xrpMemo != null && xrpMemo !== "") memo.push(xrpMemo);
|
|
24
|
+
return memo.join(":");
|
|
25
|
+
}
|
|
26
|
+
const caip2Mapping = {
|
|
27
|
+
[require_caip2.Chains.Ethereum]: "eth:1",
|
|
28
|
+
[require_caip2.Chains.Base]: "eth:8453",
|
|
29
|
+
[require_caip2.Chains.Arbitrum]: "eth:42161",
|
|
30
|
+
[require_caip2.Chains.Bitcoin]: "btc:mainnet",
|
|
31
|
+
[require_caip2.Chains.BitcoinCash]: "bch:mainnet",
|
|
32
|
+
[require_caip2.Chains.Solana]: "sol:mainnet",
|
|
33
|
+
[require_caip2.Chains.Dogecoin]: "doge:mainnet",
|
|
34
|
+
[require_caip2.Chains.XRPL]: "xrp:mainnet",
|
|
35
|
+
[require_caip2.Chains.Zcash]: "zec:mainnet",
|
|
36
|
+
[require_caip2.Chains.Gnosis]: "eth:100",
|
|
37
|
+
[require_caip2.Chains.Berachain]: "eth:80094",
|
|
38
|
+
[require_caip2.Chains.Tron]: "tron:mainnet",
|
|
39
|
+
[require_caip2.Chains.Sui]: "sui:mainnet",
|
|
40
|
+
[require_caip2.Chains.Aptos]: "aptos:mainnet",
|
|
41
|
+
[require_caip2.Chains.Cardano]: "cardano:mainnet",
|
|
42
|
+
[require_caip2.Chains.Litecoin]: "ltc:mainnet",
|
|
43
|
+
[require_caip2.Chains.Starknet]: "starknet:mainnet"
|
|
44
|
+
};
|
|
45
|
+
function toPoaNetwork(caip2) {
|
|
46
|
+
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
47
|
+
return caip2Mapping[caip2];
|
|
48
|
+
}
|
|
49
|
+
const tokenPrefixMapping = {
|
|
50
|
+
eth: require_caip2.Chains.Ethereum,
|
|
51
|
+
base: require_caip2.Chains.Base,
|
|
52
|
+
arb: require_caip2.Chains.Arbitrum,
|
|
53
|
+
btc: require_caip2.Chains.Bitcoin,
|
|
54
|
+
bch: require_caip2.Chains.BitcoinCash,
|
|
55
|
+
sol: require_caip2.Chains.Solana,
|
|
56
|
+
doge: require_caip2.Chains.Dogecoin,
|
|
57
|
+
xrp: require_caip2.Chains.XRPL,
|
|
58
|
+
zec: require_caip2.Chains.Zcash,
|
|
59
|
+
gnosis: require_caip2.Chains.Gnosis,
|
|
60
|
+
bera: require_caip2.Chains.Berachain,
|
|
61
|
+
tron: require_caip2.Chains.Tron,
|
|
62
|
+
sui: require_caip2.Chains.Sui,
|
|
63
|
+
aptos: require_caip2.Chains.Aptos,
|
|
64
|
+
cardano: require_caip2.Chains.Cardano,
|
|
65
|
+
ltc: require_caip2.Chains.Litecoin,
|
|
66
|
+
starknet: require_caip2.Chains.Starknet
|
|
67
|
+
};
|
|
68
|
+
function contractIdToCaip2(contractId) {
|
|
69
|
+
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
|
70
|
+
throw new Error(`Unsupported POA Bridge contractId = ${contractId}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.contractIdToCaip2 = contractIdToCaip2;
|
|
75
|
+
exports.createWithdrawIntentPrimitive = createWithdrawIntentPrimitive;
|
|
76
|
+
exports.toPoaNetwork = toPoaNetwork;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Chains } from "../../lib/caip2.js";
|
|
2
|
+
import { MIN_GAS_AMOUNT } from "./poa-constants.js";
|
|
3
|
+
import { utils } from "lampamazaza-internal-utils";
|
|
4
|
+
|
|
5
|
+
//#region src/bridges/poa-bridge/poa-bridge-utils.ts
|
|
6
|
+
function createWithdrawIntentPrimitive(params) {
|
|
7
|
+
const { contractId: tokenAccountId } = utils.parseDefuseAssetId(params.assetId);
|
|
8
|
+
return {
|
|
9
|
+
intent: "ft_withdraw",
|
|
10
|
+
token: tokenAccountId,
|
|
11
|
+
receiver_id: tokenAccountId,
|
|
12
|
+
amount: params.amount.toString(),
|
|
13
|
+
memo: createWithdrawMemo({
|
|
14
|
+
receiverAddress: params.destinationAddress,
|
|
15
|
+
xrpMemo: params.destinationMemo
|
|
16
|
+
}),
|
|
17
|
+
min_gas: MIN_GAS_AMOUNT
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createWithdrawMemo({ receiverAddress, xrpMemo }) {
|
|
21
|
+
const memo = ["WITHDRAW_TO", receiverAddress.toLowerCase().startsWith("bitcoincash:") ? receiverAddress.slice(12) : receiverAddress];
|
|
22
|
+
if (xrpMemo != null && xrpMemo !== "") memo.push(xrpMemo);
|
|
23
|
+
return memo.join(":");
|
|
24
|
+
}
|
|
25
|
+
const caip2Mapping = {
|
|
26
|
+
[Chains.Ethereum]: "eth:1",
|
|
27
|
+
[Chains.Base]: "eth:8453",
|
|
28
|
+
[Chains.Arbitrum]: "eth:42161",
|
|
29
|
+
[Chains.Bitcoin]: "btc:mainnet",
|
|
30
|
+
[Chains.BitcoinCash]: "bch:mainnet",
|
|
31
|
+
[Chains.Solana]: "sol:mainnet",
|
|
32
|
+
[Chains.Dogecoin]: "doge:mainnet",
|
|
33
|
+
[Chains.XRPL]: "xrp:mainnet",
|
|
34
|
+
[Chains.Zcash]: "zec:mainnet",
|
|
35
|
+
[Chains.Gnosis]: "eth:100",
|
|
36
|
+
[Chains.Berachain]: "eth:80094",
|
|
37
|
+
[Chains.Tron]: "tron:mainnet",
|
|
38
|
+
[Chains.Sui]: "sui:mainnet",
|
|
39
|
+
[Chains.Aptos]: "aptos:mainnet",
|
|
40
|
+
[Chains.Cardano]: "cardano:mainnet",
|
|
41
|
+
[Chains.Litecoin]: "ltc:mainnet",
|
|
42
|
+
[Chains.Starknet]: "starknet:mainnet"
|
|
43
|
+
};
|
|
44
|
+
function toPoaNetwork(caip2) {
|
|
45
|
+
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
46
|
+
return caip2Mapping[caip2];
|
|
47
|
+
}
|
|
48
|
+
const tokenPrefixMapping = {
|
|
49
|
+
eth: Chains.Ethereum,
|
|
50
|
+
base: Chains.Base,
|
|
51
|
+
arb: Chains.Arbitrum,
|
|
52
|
+
btc: Chains.Bitcoin,
|
|
53
|
+
bch: Chains.BitcoinCash,
|
|
54
|
+
sol: Chains.Solana,
|
|
55
|
+
doge: Chains.Dogecoin,
|
|
56
|
+
xrp: Chains.XRPL,
|
|
57
|
+
zec: Chains.Zcash,
|
|
58
|
+
gnosis: Chains.Gnosis,
|
|
59
|
+
bera: Chains.Berachain,
|
|
60
|
+
tron: Chains.Tron,
|
|
61
|
+
sui: Chains.Sui,
|
|
62
|
+
aptos: Chains.Aptos,
|
|
63
|
+
cardano: Chains.Cardano,
|
|
64
|
+
ltc: Chains.Litecoin,
|
|
65
|
+
starknet: Chains.Starknet
|
|
66
|
+
};
|
|
67
|
+
function contractIdToCaip2(contractId) {
|
|
68
|
+
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
|
69
|
+
throw new Error(`Unsupported POA Bridge contractId = ${contractId}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { contractIdToCaip2, createWithdrawIntentPrimitive, toPoaNetwork };
|
|
@@ -0,0 +1,175 @@
|
|
|
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_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
5
|
+
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
6
|
+
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
7
|
+
const require_bridge_name_enum = require('../../constants/bridge-name-enum.cjs');
|
|
8
|
+
const require_poa_tokens_routable_through_omni_bridge = require('../../constants/poa-tokens-routable-through-omni-bridge.cjs');
|
|
9
|
+
const require_poa_bridge_utils = require('./poa-bridge-utils.cjs');
|
|
10
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
11
|
+
let _isaacs_ttlcache = require("@isaacs/ttlcache");
|
|
12
|
+
_isaacs_ttlcache = require_rolldown_runtime.__toESM(_isaacs_ttlcache);
|
|
13
|
+
|
|
14
|
+
//#region src/bridges/poa-bridge/poa-bridge.ts
|
|
15
|
+
var PoaBridge = class {
|
|
16
|
+
constructor({ envConfig, routeMigratedPoaTokensThroughOmniBridge }) {
|
|
17
|
+
this.route = require_route_enum.RouteEnum.PoaBridge;
|
|
18
|
+
this.supportedTokensCache = new _isaacs_ttlcache.default({ ttl: 30 * 1e3 });
|
|
19
|
+
this.envConfig = envConfig;
|
|
20
|
+
this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
|
|
21
|
+
}
|
|
22
|
+
getPoaBridgeBaseURL() {
|
|
23
|
+
if (!this.envConfig.poaBridgeBaseURL) throw new Error("POA Bridge is not available in this environment: poaBridgeBaseURL is not configured");
|
|
24
|
+
return this.envConfig.poaBridgeBaseURL;
|
|
25
|
+
}
|
|
26
|
+
is(routeConfig) {
|
|
27
|
+
return routeConfig.route === require_route_enum.RouteEnum.PoaBridge;
|
|
28
|
+
}
|
|
29
|
+
async supports(params) {
|
|
30
|
+
if (params.routeConfig != null && !this.is(params.routeConfig)) return false;
|
|
31
|
+
const assetInfo = this.parseAssetId(params.assetId);
|
|
32
|
+
const isValid = assetInfo != null;
|
|
33
|
+
if (!isValid && params.routeConfig != null) throw new require_errors.UnsupportedAssetIdError(params.assetId, "`assetId` does not match `routeConfig`.");
|
|
34
|
+
if (this.routeMigratedPoaTokensThroughOmniBridge && assetInfo != null && require_poa_tokens_routable_through_omni_bridge.POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE[assetInfo.contractId] !== void 0 && params.routeConfig === void 0) return false;
|
|
35
|
+
return isValid;
|
|
36
|
+
}
|
|
37
|
+
parseAssetId(assetId) {
|
|
38
|
+
if (!this.envConfig.poaTokenFactoryContractID) return null;
|
|
39
|
+
const parsed = require_parse_defuse_asset_id.parseDefuseAssetId(assetId);
|
|
40
|
+
if (!parsed.contractId.endsWith(`.${this.envConfig.poaTokenFactoryContractID}`)) return null;
|
|
41
|
+
let blockchain;
|
|
42
|
+
try {
|
|
43
|
+
blockchain = require_poa_bridge_utils.contractIdToCaip2(parsed.contractId);
|
|
44
|
+
} catch {
|
|
45
|
+
throw new require_errors.UnsupportedAssetIdError(assetId, "Asset belongs to unknown blockchain.");
|
|
46
|
+
}
|
|
47
|
+
return Object.assign(parsed, {
|
|
48
|
+
blockchain,
|
|
49
|
+
bridgeName: require_bridge_name_enum.BridgeNameEnum.Poa,
|
|
50
|
+
address: ""
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
createWithdrawalIntents(args) {
|
|
54
|
+
const relayerFee = require_estimate_fee.getUnderlyingFee(args.feeEstimation, require_route_enum.RouteEnum.PoaBridge, "relayerFee");
|
|
55
|
+
(0, lampamazaza_internal_utils.assert)(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
|
|
56
|
+
const intent = require_poa_bridge_utils.createWithdrawIntentPrimitive({
|
|
57
|
+
...args.withdrawalParams,
|
|
58
|
+
amount: args.withdrawalParams.amount + relayerFee,
|
|
59
|
+
destinationMemo: args.withdrawalParams.destinationMemo
|
|
60
|
+
});
|
|
61
|
+
return Promise.resolve([intent]);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Validates minimum withdrawal amount for POA bridge tokens.
|
|
65
|
+
* Checks the bridge's supported tokens API to ensure the withdrawal amount
|
|
66
|
+
* meets the minimum required amount for the specific token and blockchain.
|
|
67
|
+
* @throws {MinWithdrawalAmountError} If the amount is below the minimum required
|
|
68
|
+
*/
|
|
69
|
+
async validateWithdrawal(args) {
|
|
70
|
+
const assetInfo = this.parseAssetId(args.assetId);
|
|
71
|
+
(0, lampamazaza_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
72
|
+
if (require_validateAddress.validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new require_errors.InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
73
|
+
const { tokens } = await this.getCachedSupportedTokens([require_poa_bridge_utils.toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
74
|
+
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
75
|
+
if (tokenInfo != null) {
|
|
76
|
+
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
77
|
+
if (args.amount < minWithdrawalAmount) throw new require_errors.MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async estimateWithdrawalFee(args) {
|
|
81
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
82
|
+
(0, lampamazaza_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
83
|
+
const estimation = await lampamazaza_internal_utils.poaBridge.httpClient.getWithdrawalEstimate({
|
|
84
|
+
token: lampamazaza_internal_utils.utils.getTokenAccountId(args.withdrawalParams.assetId),
|
|
85
|
+
address: args.withdrawalParams.destinationAddress,
|
|
86
|
+
chain: require_poa_bridge_utils.toPoaNetwork(assetInfo.blockchain)
|
|
87
|
+
}, {
|
|
88
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
89
|
+
logger: args.logger
|
|
90
|
+
});
|
|
91
|
+
const relayerFee = BigInt(estimation.withdrawalFee);
|
|
92
|
+
(0, lampamazaza_internal_utils.assert)(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
|
|
93
|
+
return {
|
|
94
|
+
amount: relayerFee,
|
|
95
|
+
quote: null,
|
|
96
|
+
underlyingFees: { [require_route_enum.RouteEnum.PoaBridge]: { relayerFee } }
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
createWithdrawalIdentifier(args) {
|
|
100
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
101
|
+
(0, lampamazaza_internal_utils.assert)(assetInfo != null, "Asset is not supported");
|
|
102
|
+
return {
|
|
103
|
+
landingChain: assetInfo.blockchain,
|
|
104
|
+
index: args.index,
|
|
105
|
+
withdrawalParams: args.withdrawalParams,
|
|
106
|
+
tx: args.tx
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async describeWithdrawal(args) {
|
|
110
|
+
const withdrawal = findMatchingWithdrawal((await this.getWithdrawalStatusWithRetry(args)).withdrawals, args.withdrawalParams.assetId);
|
|
111
|
+
if (withdrawal == null) return { status: "pending" };
|
|
112
|
+
if (withdrawal.status === "PENDING") return { status: "pending" };
|
|
113
|
+
if (withdrawal.status === "COMPLETED") return {
|
|
114
|
+
status: "completed",
|
|
115
|
+
txHash: withdrawal.data.transfer_tx_hash
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
status: "failed",
|
|
119
|
+
reason: withdrawal.status
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async getWithdrawalStatusWithRetry(args) {
|
|
123
|
+
const startTime = Date.now();
|
|
124
|
+
while (true) try {
|
|
125
|
+
return await lampamazaza_internal_utils.poaBridge.httpClient.getWithdrawalStatus({ withdrawal_hash: args.tx.hash }, {
|
|
126
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
127
|
+
logger: args.logger
|
|
128
|
+
});
|
|
129
|
+
} catch (err) {
|
|
130
|
+
if (!isWithdrawalNotFoundError(err)) throw err;
|
|
131
|
+
if (Date.now() - startTime >= NOT_FOUND_RETRY_TIMEOUT_MS) return { withdrawals: [] };
|
|
132
|
+
args.logger?.warn("Withdrawal not indexed yet, retrying...");
|
|
133
|
+
await sleep(NOT_FOUND_RETRY_INTERVAL_MS);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gets supported tokens with caching to avoid frequent API calls.
|
|
138
|
+
* Cache expires after 30 seconds using TTL cache.
|
|
139
|
+
*/
|
|
140
|
+
async getCachedSupportedTokens(chains, logger) {
|
|
141
|
+
const cacheKey = chains.sort().join(",");
|
|
142
|
+
const cached = this.supportedTokensCache.get(cacheKey);
|
|
143
|
+
if (cached != null) return cached;
|
|
144
|
+
const data = await lampamazaza_internal_utils.poaBridge.httpClient.getSupportedTokens({ chains }, {
|
|
145
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
146
|
+
logger
|
|
147
|
+
});
|
|
148
|
+
this.supportedTokensCache.set(cacheKey, data);
|
|
149
|
+
return data;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Finds a withdrawal matching the given assetId.
|
|
154
|
+
*
|
|
155
|
+
* NOTE: Currently only matches by assetId. This means multiple withdrawals
|
|
156
|
+
* of the same token in a single transaction are not supported.
|
|
157
|
+
* POA API doesn't currently support this case either. When support is added,
|
|
158
|
+
* matching could be done by sorting both API results and withdrawal params by
|
|
159
|
+
* amount (fees are equal for same token, so relative ordering is preserved).
|
|
160
|
+
*/
|
|
161
|
+
function findMatchingWithdrawal(withdrawals, assetId) {
|
|
162
|
+
return withdrawals.find((w) => `nep141:${w.data.near_token_id}` === assetId);
|
|
163
|
+
}
|
|
164
|
+
const NOT_FOUND_RETRY_TIMEOUT_MS = 3 * 1e3;
|
|
165
|
+
const NOT_FOUND_RETRY_INTERVAL_MS = 1e3;
|
|
166
|
+
const RPC_ERR_MSG_WITHDRAWALS_NOT_FOUND = "Withdrawals not found";
|
|
167
|
+
function isWithdrawalNotFoundError(err) {
|
|
168
|
+
return err instanceof lampamazaza_internal_utils.RpcRequestError && err.details === RPC_ERR_MSG_WITHDRAWALS_NOT_FOUND;
|
|
169
|
+
}
|
|
170
|
+
function sleep(ms) {
|
|
171
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
exports.PoaBridge = PoaBridge;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
|
+
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
|
+
import { getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
4
|
+
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
5
|
+
import { validateAddress } from "../../lib/validateAddress.js";
|
|
6
|
+
import { BridgeNameEnum } from "../../constants/bridge-name-enum.js";
|
|
7
|
+
import { POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE } from "../../constants/poa-tokens-routable-through-omni-bridge.js";
|
|
8
|
+
import { contractIdToCaip2, createWithdrawIntentPrimitive, toPoaNetwork } from "./poa-bridge-utils.js";
|
|
9
|
+
import { RpcRequestError, assert, poaBridge, utils } from "lampamazaza-internal-utils";
|
|
10
|
+
import TTLCache from "@isaacs/ttlcache";
|
|
11
|
+
|
|
12
|
+
//#region src/bridges/poa-bridge/poa-bridge.ts
|
|
13
|
+
var PoaBridge = class {
|
|
14
|
+
constructor({ envConfig, routeMigratedPoaTokensThroughOmniBridge }) {
|
|
15
|
+
this.route = RouteEnum.PoaBridge;
|
|
16
|
+
this.supportedTokensCache = new TTLCache({ ttl: 30 * 1e3 });
|
|
17
|
+
this.envConfig = envConfig;
|
|
18
|
+
this.routeMigratedPoaTokensThroughOmniBridge = routeMigratedPoaTokensThroughOmniBridge ?? false;
|
|
19
|
+
}
|
|
20
|
+
getPoaBridgeBaseURL() {
|
|
21
|
+
if (!this.envConfig.poaBridgeBaseURL) throw new Error("POA Bridge is not available in this environment: poaBridgeBaseURL is not configured");
|
|
22
|
+
return this.envConfig.poaBridgeBaseURL;
|
|
23
|
+
}
|
|
24
|
+
is(routeConfig) {
|
|
25
|
+
return routeConfig.route === RouteEnum.PoaBridge;
|
|
26
|
+
}
|
|
27
|
+
async supports(params) {
|
|
28
|
+
if (params.routeConfig != null && !this.is(params.routeConfig)) return false;
|
|
29
|
+
const assetInfo = this.parseAssetId(params.assetId);
|
|
30
|
+
const isValid = assetInfo != null;
|
|
31
|
+
if (!isValid && params.routeConfig != null) throw new UnsupportedAssetIdError(params.assetId, "`assetId` does not match `routeConfig`.");
|
|
32
|
+
if (this.routeMigratedPoaTokensThroughOmniBridge && assetInfo != null && POA_TOKENS_ROUTABLE_THROUGH_OMNI_BRIDGE[assetInfo.contractId] !== void 0 && params.routeConfig === void 0) return false;
|
|
33
|
+
return isValid;
|
|
34
|
+
}
|
|
35
|
+
parseAssetId(assetId) {
|
|
36
|
+
if (!this.envConfig.poaTokenFactoryContractID) return null;
|
|
37
|
+
const parsed = parseDefuseAssetId(assetId);
|
|
38
|
+
if (!parsed.contractId.endsWith(`.${this.envConfig.poaTokenFactoryContractID}`)) return null;
|
|
39
|
+
let blockchain;
|
|
40
|
+
try {
|
|
41
|
+
blockchain = contractIdToCaip2(parsed.contractId);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new UnsupportedAssetIdError(assetId, "Asset belongs to unknown blockchain.");
|
|
44
|
+
}
|
|
45
|
+
return Object.assign(parsed, {
|
|
46
|
+
blockchain,
|
|
47
|
+
bridgeName: BridgeNameEnum.Poa,
|
|
48
|
+
address: ""
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
createWithdrawalIntents(args) {
|
|
52
|
+
const relayerFee = getUnderlyingFee(args.feeEstimation, RouteEnum.PoaBridge, "relayerFee");
|
|
53
|
+
assert(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
|
|
54
|
+
const intent = createWithdrawIntentPrimitive({
|
|
55
|
+
...args.withdrawalParams,
|
|
56
|
+
amount: args.withdrawalParams.amount + relayerFee,
|
|
57
|
+
destinationMemo: args.withdrawalParams.destinationMemo
|
|
58
|
+
});
|
|
59
|
+
return Promise.resolve([intent]);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Validates minimum withdrawal amount for POA bridge tokens.
|
|
63
|
+
* Checks the bridge's supported tokens API to ensure the withdrawal amount
|
|
64
|
+
* meets the minimum required amount for the specific token and blockchain.
|
|
65
|
+
* @throws {MinWithdrawalAmountError} If the amount is below the minimum required
|
|
66
|
+
*/
|
|
67
|
+
async validateWithdrawal(args) {
|
|
68
|
+
const assetInfo = this.parseAssetId(args.assetId);
|
|
69
|
+
assert(assetInfo != null, "Asset is not supported");
|
|
70
|
+
if (validateAddress(args.destinationAddress, assetInfo.blockchain) === false) throw new InvalidDestinationAddressForWithdrawalError(args.destinationAddress, assetInfo.blockchain);
|
|
71
|
+
const { tokens } = await this.getCachedSupportedTokens([toPoaNetwork(assetInfo.blockchain)], args.logger);
|
|
72
|
+
const tokenInfo = tokens.find((token) => token.intents_token_id === args.assetId);
|
|
73
|
+
if (tokenInfo != null) {
|
|
74
|
+
const minWithdrawalAmount = BigInt(tokenInfo.min_withdrawal_amount);
|
|
75
|
+
if (args.amount < minWithdrawalAmount) throw new MinWithdrawalAmountError(minWithdrawalAmount, args.amount, args.assetId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async estimateWithdrawalFee(args) {
|
|
79
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
80
|
+
assert(assetInfo != null, "Asset is not supported");
|
|
81
|
+
const estimation = await poaBridge.httpClient.getWithdrawalEstimate({
|
|
82
|
+
token: utils.getTokenAccountId(args.withdrawalParams.assetId),
|
|
83
|
+
address: args.withdrawalParams.destinationAddress,
|
|
84
|
+
chain: toPoaNetwork(assetInfo.blockchain)
|
|
85
|
+
}, {
|
|
86
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
87
|
+
logger: args.logger
|
|
88
|
+
});
|
|
89
|
+
const relayerFee = BigInt(estimation.withdrawalFee);
|
|
90
|
+
assert(relayerFee > 0n, `Invalid POA bridge relayer fee: expected > 0, got ${relayerFee}`);
|
|
91
|
+
return {
|
|
92
|
+
amount: relayerFee,
|
|
93
|
+
quote: null,
|
|
94
|
+
underlyingFees: { [RouteEnum.PoaBridge]: { relayerFee } }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
createWithdrawalIdentifier(args) {
|
|
98
|
+
const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
|
|
99
|
+
assert(assetInfo != null, "Asset is not supported");
|
|
100
|
+
return {
|
|
101
|
+
landingChain: assetInfo.blockchain,
|
|
102
|
+
index: args.index,
|
|
103
|
+
withdrawalParams: args.withdrawalParams,
|
|
104
|
+
tx: args.tx
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async describeWithdrawal(args) {
|
|
108
|
+
const withdrawal = findMatchingWithdrawal((await this.getWithdrawalStatusWithRetry(args)).withdrawals, args.withdrawalParams.assetId);
|
|
109
|
+
if (withdrawal == null) return { status: "pending" };
|
|
110
|
+
if (withdrawal.status === "PENDING") return { status: "pending" };
|
|
111
|
+
if (withdrawal.status === "COMPLETED") return {
|
|
112
|
+
status: "completed",
|
|
113
|
+
txHash: withdrawal.data.transfer_tx_hash
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
status: "failed",
|
|
117
|
+
reason: withdrawal.status
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async getWithdrawalStatusWithRetry(args) {
|
|
121
|
+
const startTime = Date.now();
|
|
122
|
+
while (true) try {
|
|
123
|
+
return await poaBridge.httpClient.getWithdrawalStatus({ withdrawal_hash: args.tx.hash }, {
|
|
124
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
125
|
+
logger: args.logger
|
|
126
|
+
});
|
|
127
|
+
} catch (err) {
|
|
128
|
+
if (!isWithdrawalNotFoundError(err)) throw err;
|
|
129
|
+
if (Date.now() - startTime >= NOT_FOUND_RETRY_TIMEOUT_MS) return { withdrawals: [] };
|
|
130
|
+
args.logger?.warn("Withdrawal not indexed yet, retrying...");
|
|
131
|
+
await sleep(NOT_FOUND_RETRY_INTERVAL_MS);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets supported tokens with caching to avoid frequent API calls.
|
|
136
|
+
* Cache expires after 30 seconds using TTL cache.
|
|
137
|
+
*/
|
|
138
|
+
async getCachedSupportedTokens(chains, logger) {
|
|
139
|
+
const cacheKey = chains.sort().join(",");
|
|
140
|
+
const cached = this.supportedTokensCache.get(cacheKey);
|
|
141
|
+
if (cached != null) return cached;
|
|
142
|
+
const data = await poaBridge.httpClient.getSupportedTokens({ chains }, {
|
|
143
|
+
baseURL: this.getPoaBridgeBaseURL(),
|
|
144
|
+
logger
|
|
145
|
+
});
|
|
146
|
+
this.supportedTokensCache.set(cacheKey, data);
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Finds a withdrawal matching the given assetId.
|
|
152
|
+
*
|
|
153
|
+
* NOTE: Currently only matches by assetId. This means multiple withdrawals
|
|
154
|
+
* of the same token in a single transaction are not supported.
|
|
155
|
+
* POA API doesn't currently support this case either. When support is added,
|
|
156
|
+
* matching could be done by sorting both API results and withdrawal params by
|
|
157
|
+
* amount (fees are equal for same token, so relative ordering is preserved).
|
|
158
|
+
*/
|
|
159
|
+
function findMatchingWithdrawal(withdrawals, assetId) {
|
|
160
|
+
return withdrawals.find((w) => `nep141:${w.data.near_token_id}` === assetId);
|
|
161
|
+
}
|
|
162
|
+
const NOT_FOUND_RETRY_TIMEOUT_MS = 3 * 1e3;
|
|
163
|
+
const NOT_FOUND_RETRY_INTERVAL_MS = 1e3;
|
|
164
|
+
const RPC_ERR_MSG_WITHDRAWALS_NOT_FOUND = "Withdrawals not found";
|
|
165
|
+
function isWithdrawalNotFoundError(err) {
|
|
166
|
+
return err instanceof RpcRequestError && err.details === RPC_ERR_MSG_WITHDRAWALS_NOT_FOUND;
|
|
167
|
+
}
|
|
168
|
+
function sleep(ms) {
|
|
169
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
export { PoaBridge };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let lampamazaza_internal_utils = require("lampamazaza-internal-utils");
|
|
3
|
+
|
|
4
|
+
//#region src/classes/errors.ts
|
|
5
|
+
var FeeExceedsAmountError = class extends lampamazaza_internal_utils.BaseError {
|
|
6
|
+
constructor(feeEstimation, amount) {
|
|
7
|
+
super("Amount too small to pay fee.", {
|
|
8
|
+
metaMessages: [`Required fee: ${feeEstimation.amount}`, `Withdrawal amount: ${amount}`],
|
|
9
|
+
name: "FeeExceedsAmountError"
|
|
10
|
+
});
|
|
11
|
+
this.feeEstimation = feeEstimation;
|
|
12
|
+
this.amount = amount;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var MinWithdrawalAmountError = class extends lampamazaza_internal_utils.BaseError {
|
|
16
|
+
constructor(minAmount, requestedAmount, assetId) {
|
|
17
|
+
super("Withdrawal amount is below minimum required by the bridge.", {
|
|
18
|
+
metaMessages: [
|
|
19
|
+
`Asset ID: ${assetId}`,
|
|
20
|
+
`Minimum amount: ${minAmount}`,
|
|
21
|
+
`Requested amount: ${requestedAmount}`
|
|
22
|
+
],
|
|
23
|
+
name: "MinWithdrawalAmountError"
|
|
24
|
+
});
|
|
25
|
+
this.minAmount = minAmount;
|
|
26
|
+
this.requestedAmount = requestedAmount;
|
|
27
|
+
this.assetId = assetId;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var UnsupportedDestinationMemoError = class extends lampamazaza_internal_utils.BaseError {
|
|
31
|
+
constructor(blockchain, assetId) {
|
|
32
|
+
super("Destination memo is not supported for this blockchain.", {
|
|
33
|
+
details: "Destination memo is only supported for XRP Ledger withdrawals.",
|
|
34
|
+
metaMessages: [`Blockchain: ${blockchain}`, `Asset ID: ${assetId}`],
|
|
35
|
+
name: "UnsupportedDestinationMemoError"
|
|
36
|
+
});
|
|
37
|
+
this.blockchain = blockchain;
|
|
38
|
+
this.assetId = assetId;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var TrustlineNotFoundError = class extends lampamazaza_internal_utils.BaseError {
|
|
42
|
+
constructor(destinationAddress, assetId, blockchain, tokenAddress) {
|
|
43
|
+
super("Destination address does not have a trustline for this asset.", {
|
|
44
|
+
details: "The destination address must establish a trustline before receiving this asset.",
|
|
45
|
+
metaMessages: [
|
|
46
|
+
`Blockchain: ${blockchain}`,
|
|
47
|
+
`Asset ID: ${assetId}`,
|
|
48
|
+
`Destination address: ${destinationAddress}`,
|
|
49
|
+
`Token address: ${tokenAddress}`
|
|
50
|
+
],
|
|
51
|
+
name: "TrustlineNotFoundError"
|
|
52
|
+
});
|
|
53
|
+
this.destinationAddress = destinationAddress;
|
|
54
|
+
this.assetId = assetId;
|
|
55
|
+
this.blockchain = blockchain;
|
|
56
|
+
this.tokenAddress = tokenAddress;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var UnsupportedAssetIdError = class extends lampamazaza_internal_utils.BaseError {
|
|
60
|
+
constructor(assetId, details) {
|
|
61
|
+
super("Asset ID is not supported.", {
|
|
62
|
+
details,
|
|
63
|
+
metaMessages: [`Asset ID: ${assetId}`],
|
|
64
|
+
name: "UnsupportedAssetIdError"
|
|
65
|
+
});
|
|
66
|
+
this.assetId = assetId;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var InvalidDestinationAddressForWithdrawalError = class extends lampamazaza_internal_utils.BaseError {
|
|
70
|
+
constructor(destinationAddress, destinationChain) {
|
|
71
|
+
super(`Invalid destination address.`, {
|
|
72
|
+
metaMessages: [`Destination address: ${destinationAddress}`, `Destination chain: ${destinationChain}`],
|
|
73
|
+
name: "InvalidDestinationAddressForWithdrawalError",
|
|
74
|
+
details: `Destination address ${destinationAddress} is not valid for withdrawal to ${destinationChain}.`
|
|
75
|
+
});
|
|
76
|
+
this.destinationAddress = destinationAddress;
|
|
77
|
+
this.destinationChain = destinationChain;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.FeeExceedsAmountError = FeeExceedsAmountError;
|
|
83
|
+
exports.InvalidDestinationAddressForWithdrawalError = InvalidDestinationAddressForWithdrawalError;
|
|
84
|
+
exports.MinWithdrawalAmountError = MinWithdrawalAmountError;
|
|
85
|
+
exports.TrustlineNotFoundError = TrustlineNotFoundError;
|
|
86
|
+
exports.UnsupportedAssetIdError = UnsupportedAssetIdError;
|
|
87
|
+
exports.UnsupportedDestinationMemoError = UnsupportedDestinationMemoError;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FeeEstimation } from "../shared-types.cjs";
|
|
2
|
+
import { BaseError } from "lampamazaza-internal-utils";
|
|
3
|
+
|
|
4
|
+
//#region src/classes/errors.d.ts
|
|
5
|
+
type FeeExceedsAmountErrorType = FeeExceedsAmountError & {
|
|
6
|
+
name: "FeeExceedsAmountError";
|
|
7
|
+
};
|
|
8
|
+
declare class FeeExceedsAmountError extends BaseError {
|
|
9
|
+
feeEstimation: FeeEstimation;
|
|
10
|
+
amount: bigint;
|
|
11
|
+
constructor(feeEstimation: FeeEstimation, amount: bigint);
|
|
12
|
+
}
|
|
13
|
+
type MinWithdrawalAmountErrorType = MinWithdrawalAmountError & {
|
|
14
|
+
name: "MinWithdrawalAmountError";
|
|
15
|
+
};
|
|
16
|
+
declare class MinWithdrawalAmountError extends BaseError {
|
|
17
|
+
minAmount: bigint;
|
|
18
|
+
requestedAmount: bigint;
|
|
19
|
+
assetId: string;
|
|
20
|
+
constructor(minAmount: bigint, requestedAmount: bigint, assetId: string);
|
|
21
|
+
}
|
|
22
|
+
type UnsupportedDestinationMemoErrorType = UnsupportedDestinationMemoError & {
|
|
23
|
+
name: "UnsupportedDestinationMemoError";
|
|
24
|
+
};
|
|
25
|
+
declare class UnsupportedDestinationMemoError extends BaseError {
|
|
26
|
+
blockchain: string;
|
|
27
|
+
assetId: string;
|
|
28
|
+
constructor(blockchain: string, assetId: string);
|
|
29
|
+
}
|
|
30
|
+
type TrustlineNotFoundErrorType = TrustlineNotFoundError & {
|
|
31
|
+
name: "TrustlineNotFoundError";
|
|
32
|
+
};
|
|
33
|
+
declare class TrustlineNotFoundError extends BaseError {
|
|
34
|
+
destinationAddress: string;
|
|
35
|
+
assetId: string;
|
|
36
|
+
blockchain: string;
|
|
37
|
+
tokenAddress: string;
|
|
38
|
+
constructor(destinationAddress: string, assetId: string, blockchain: string, tokenAddress: string);
|
|
39
|
+
}
|
|
40
|
+
type UnsupportedAssetIdErrorType = UnsupportedAssetIdError & {
|
|
41
|
+
name: "UnsupportedAssetIdError";
|
|
42
|
+
};
|
|
43
|
+
declare class UnsupportedAssetIdError extends BaseError {
|
|
44
|
+
assetId: string;
|
|
45
|
+
constructor(assetId: string, details: string);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { FeeExceedsAmountError, FeeExceedsAmountErrorType, MinWithdrawalAmountError, MinWithdrawalAmountErrorType, TrustlineNotFoundError, TrustlineNotFoundErrorType, UnsupportedAssetIdError, UnsupportedAssetIdErrorType, UnsupportedDestinationMemoError, UnsupportedDestinationMemoErrorType };
|