@allbridge/bridge-core-sdk 3.27.0-beta.6 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +1 -6
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +1 -6
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -6
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +2 -12
- package/dist/src/chains/chain.enums.js +0 -10
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +0 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +0 -1
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +0 -33
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +2 -14
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +0 -1
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +4 -12
- package/dist/src/index.js +11 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +4 -12
- package/dist/src/models/index.js +0 -4
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +0 -1
- package/dist/src/services/bridge/evm/index.js +33 -103
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +4 -31
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +4 -13
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +28 -36
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/sui/index.js +138 -166
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +70 -98
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +1 -5
- package/dist/src/services/bridge/utils.js +23 -164
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +0 -21
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/sui/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
- package/dist/src/services/models/index.d.ts +5 -7
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/token/index.js +2 -23
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/services/token/models/token.model.d.ts +4 -4
- package/dist/src/services/token/models/token.model.js.map +1 -1
- package/dist/src/services/token/sui/index.js.map +1 -1
- package/dist/src/services/utils/trx/index.js.map +1 -1
- package/dist/src/services/yield/index.js +0 -8
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +0 -25
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/src/utils/index.js +0 -3
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/utils.d.ts +0 -2
- package/dist/src/utils/utils.js +0 -11
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +2 -9
- package/dist/src/services/bridge/alg/index.d.ts +0 -16
- package/dist/src/services/bridge/alg/index.js +0 -191
- package/dist/src/services/bridge/alg/index.js.map +0 -1
- package/dist/src/services/bridge/stx/index.d.ts +0 -16
- package/dist/src/services/bridge/stx/index.js +0 -136
- package/dist/src/services/bridge/stx/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/alg/index.d.ts +0 -19
- package/dist/src/services/liquidity-pool/alg/index.js +0 -135
- package/dist/src/services/liquidity-pool/alg/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +0 -21
- package/dist/src/services/liquidity-pool/stx/index.js +0 -141
- package/dist/src/services/liquidity-pool/stx/index.js.map +0 -1
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +0 -203
- package/dist/src/services/models/abi/PayerWithAbr.js +0 -266
- package/dist/src/services/models/abi/PayerWithAbr.js.map +0 -1
- package/dist/src/services/models/alg/BridgeClient.d.ts +0 -2751
- package/dist/src/services/models/alg/BridgeClient.js +0 -2685
- package/dist/src/services/models/alg/BridgeClient.js.map +0 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +0 -654
- package/dist/src/services/models/alg/PaddingUtilClient.js +0 -425
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +0 -1
- package/dist/src/services/models/alg/PoolClient.d.ts +0 -2276
- package/dist/src/services/models/alg/PoolClient.js +0 -2195
- package/dist/src/services/models/alg/PoolClient.js.map +0 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +0 -657
- package/dist/src/services/models/stx/clarigen-types.js +0 -2296
- package/dist/src/services/models/stx/clarigen-types.js.map +0 -1
- package/dist/src/services/token/alg/index.d.ts +0 -17
- package/dist/src/services/token/alg/index.js +0 -47
- package/dist/src/services/token/alg/index.js.map +0 -1
- package/dist/src/services/token/stx/index.d.ts +0 -20
- package/dist/src/services/token/stx/index.js +0 -59
- package/dist/src/services/token/stx/index.js.map +0 -1
- package/dist/src/services/utils/alg/index.d.ts +0 -9
- package/dist/src/services/utils/alg/index.js +0 -74
- package/dist/src/services/utils/alg/index.js.map +0 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +0 -2
- package/dist/src/services/utils/stx/get-token-name.js +0 -15
- package/dist/src/services/utils/stx/get-token-name.js.map +0 -1
- package/dist/src/services/utils/stx/post-conditions.d.ts +0 -3
- package/dist/src/services/utils/stx/post-conditions.js +0 -27
- package/dist/src/services/utils/stx/post-conditions.js.map +0 -1
- package/dist/src/utils/alg/index.d.ts +0 -21
- package/dist/src/utils/alg/index.js +0 -71
- package/dist/src/utils/alg/index.js.map +0 -1
|
@@ -5,15 +5,16 @@ export { LiquidityPoolService } from "../services/liquidity-pool/index";
|
|
|
5
5
|
export { Messenger, TransferStatusResponse, BridgeTransaction, GasBalanceResponse, CheckAddressResponse, AddressStatus, } from "../client/core-api/core-api.model";
|
|
6
6
|
export { RawBridgeTransactionBuilder } from "../services/bridge/raw-bridge-transaction-builder";
|
|
7
7
|
export { RawPoolTransactionBuilder } from "../services/liquidity-pool/raw-pool-transaction-builder";
|
|
8
|
+
export { PoolInfo, TokenWithChainDetails, TransferTime, TxCostAmount, SuiAddresses, MessengerTransferTime, } from "../tokens-info/tokens-info.model";
|
|
8
9
|
export { UserBalanceInfo, UserBalanceInfoDTO, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, ApproveParams as LiquidityPoolsApproveParams, CheckAllowanceParams as LiquidityPoolsCheckAllowanceParams, GetAllowanceParams as LiquidityPoolsGetAllowanceParams, } from "../services/liquidity-pool/models/pool.model";
|
|
9
10
|
export * from "../services/models/index";
|
|
10
11
|
export { YieldService } from "../services/yield/index";
|
|
11
12
|
export { assertYieldIsSupported, isYieldSupported } from "../services/yield/validations";
|
|
12
|
-
export { TokenWithChainDetailsYield, CYDToken, YieldGetAllowanceParams, YieldCheckAllowanceParams, YieldBalanceParams, YieldGetEstimatedAmountOnDepositParams, YieldGetWithdrawProportionAmountParams, YieldWithdrawAmount, YieldApproveParams, YieldDepositParams, YieldWithdrawParams, } from "../services/yield
|
|
13
|
+
export { TokenWithChainDetailsYield, CYDToken, YieldGetAllowanceParams, YieldCheckAllowanceParams, YieldBalanceParams, YieldGetEstimatedAmountOnDepositParams, YieldGetWithdrawProportionAmountParams, YieldWithdrawAmount, YieldApproveParams, YieldDepositParams, YieldWithdrawParams, } from "../services/yield//models/yield.model";
|
|
13
14
|
export { RawYieldTransactionBuilder } from "../services/yield/raw-yield-transaction-builder";
|
|
14
15
|
export { SwapAndBridgeCalculationData, SwapFromVUsdCalcResult, SwapToVUsdCalcResult, } from "../utils/calculation/swap-and-bridge-fee-calc";
|
|
15
16
|
export { SendAmountDetails, AmountImpact } from "../utils/calculation/swap-and-bridge-details";
|
|
16
|
-
export {
|
|
17
|
+
export { ChainDetailsMap, ChainDetailsWithTokens } from "../tokens-info";
|
|
17
18
|
export { Utils } from "../utils";
|
|
18
19
|
export { SrbUtils, TrustLineParams } from "../utils/srb";
|
|
19
20
|
export { SolUtils } from "../utils/sol";
|
|
@@ -28,11 +29,7 @@ export declare enum FeePaymentMethod {
|
|
|
28
29
|
/**
|
|
29
30
|
* The fee is paid with the stablecoin token.
|
|
30
31
|
*/
|
|
31
|
-
WITH_STABLECOIN = "stablecoin"
|
|
32
|
-
/**
|
|
33
|
-
* The fee is paid with the ABR token.
|
|
34
|
-
*/
|
|
35
|
-
WITH_ARB = "abr"
|
|
32
|
+
WITH_STABLECOIN = "stablecoin"
|
|
36
33
|
}
|
|
37
34
|
export interface AmountsAndGasFeeOptions {
|
|
38
35
|
/**
|
|
@@ -61,7 +58,6 @@ type GasFeeOptionsType = {
|
|
|
61
58
|
export interface GasFeeOptions extends GasFeeOptionsType {
|
|
62
59
|
[FeePaymentMethod.WITH_NATIVE_CURRENCY]: AmountFormatted;
|
|
63
60
|
[FeePaymentMethod.WITH_STABLECOIN]?: AmountFormatted;
|
|
64
|
-
[FeePaymentMethod.WITH_ARB]?: AmountFormatted;
|
|
65
61
|
adminFeeShareWithExtras?: string;
|
|
66
62
|
}
|
|
67
63
|
/**
|
|
@@ -132,10 +128,6 @@ export interface ExtraGasMaxLimitResponse {
|
|
|
132
128
|
* Exchange rate
|
|
133
129
|
*/
|
|
134
130
|
exchangeRate: string;
|
|
135
|
-
/**
|
|
136
|
-
* Exchange rate
|
|
137
|
-
*/
|
|
138
|
-
abrExchangeRate?: string;
|
|
139
131
|
/**
|
|
140
132
|
* Source native token price
|
|
141
133
|
*/
|
package/dist/src/models/index.js
CHANGED
|
@@ -36,10 +36,6 @@ var FeePaymentMethod;
|
|
|
36
36
|
* The fee is paid with the stablecoin token.
|
|
37
37
|
*/
|
|
38
38
|
FeePaymentMethod["WITH_STABLECOIN"] = "stablecoin";
|
|
39
|
-
/**
|
|
40
|
-
* The fee is paid with the ABR token.
|
|
41
|
-
*/
|
|
42
|
-
FeePaymentMethod["WITH_ARB"] = "abr";
|
|
43
39
|
})(FeePaymentMethod || (exports.FeePaymentMethod = FeePaymentMethod = {}));
|
|
44
40
|
/**
|
|
45
41
|
* Define the type of amount data<p/>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAaA,oEAO2C;AANzC,2GAAA,SAAS,OAAA;AAKT,+GAAA,aAAa,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAaA,oEAO2C;AANzC,2GAAA,SAAS,OAAA;AAKT,+GAAA,aAAa,OAAA;AAqBf,2DAAyC;AAEzC,6DAAyF;AAAhF,qHAAA,sBAAsB,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAyBjD,gDAA8B;AAC9B,qDAA+D;AAAtD,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAG/B,IAAY,gBAUX;AAVD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,mDAA+B,CAAA;IAE/B;;OAEG;IACH,kDAA8B,CAAA;AAChC,CAAC,EAVW,gBAAgB,gCAAhB,gBAAgB,QAU3B;AAoCD;;;;GAIG;AACH,IAAY,YASX;AATD,WAAY,YAAY;IACtB;;OAEG;IACH,2BAAW,CAAA;IACX;;OAEG;IACH,+BAAe,CAAA;AACjB,CAAC,EATW,YAAY,4BAAZ,YAAY,QASvB","sourcesContent":["export {\n ApproveParams as BridgeApproveParams,\n BaseSendParams,\n CheckAllowanceParams,\n GetAllowanceParams,\n GetTokenBalanceParams,\n SendParams,\n SwapParams,\n GetNativeTokenBalanceParams,\n} from \"../services/bridge/models/bridge.model\";\nexport { BridgeService } from \"../services/bridge/index\";\nexport { CctpParams, CctpDomains } from \"../services/bridge/sol\";\nexport { LiquidityPoolService } from \"../services/liquidity-pool/index\";\nexport {\n Messenger,\n TransferStatusResponse,\n BridgeTransaction,\n GasBalanceResponse,\n CheckAddressResponse,\n AddressStatus,\n} from \"../client/core-api/core-api.model\";\nexport { RawBridgeTransactionBuilder } from \"../services/bridge/raw-bridge-transaction-builder\";\nexport { RawPoolTransactionBuilder } from \"../services/liquidity-pool/raw-pool-transaction-builder\";\nexport {\n PoolInfo,\n TokenWithChainDetails,\n TransferTime,\n TxCostAmount,\n SuiAddresses,\n MessengerTransferTime,\n} from \"../tokens-info/tokens-info.model\";\nexport {\n UserBalanceInfo,\n UserBalanceInfoDTO,\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n ApproveParams as LiquidityPoolsApproveParams,\n CheckAllowanceParams as LiquidityPoolsCheckAllowanceParams,\n GetAllowanceParams as LiquidityPoolsGetAllowanceParams,\n} from \"../services/liquidity-pool/models/pool.model\";\nexport * from \"../services/models/index\";\nexport { YieldService } from \"../services/yield/index\";\nexport { assertYieldIsSupported, isYieldSupported } from \"../services/yield/validations\";\nexport {\n TokenWithChainDetailsYield,\n CYDToken,\n YieldGetAllowanceParams,\n YieldCheckAllowanceParams,\n YieldBalanceParams,\n YieldGetEstimatedAmountOnDepositParams,\n YieldGetWithdrawProportionAmountParams,\n YieldWithdrawAmount,\n YieldApproveParams,\n YieldDepositParams,\n YieldWithdrawParams,\n} from \"../services/yield//models/yield.model\";\nexport { RawYieldTransactionBuilder } from \"../services/yield/raw-yield-transaction-builder\";\nexport {\n SwapAndBridgeCalculationData,\n SwapFromVUsdCalcResult,\n SwapToVUsdCalcResult,\n} from \"../utils/calculation/swap-and-bridge-fee-calc\";\nexport { SendAmountDetails, AmountImpact } from \"../utils/calculation/swap-and-bridge-details\";\nexport { ChainDetailsMap, ChainDetailsWithTokens } from \"../tokens-info\";\nexport { Utils } from \"../utils\";\nexport { SrbUtils, TrustLineParams } from \"../utils/srb\";\nexport { SolUtils } from \"../utils/sol\";\nexport * from \"../exceptions\";\nexport { ChainSymbol, ChainType } from \"../chains/chain.enums\";\nexport { AdditionalBasicChainProperties, BasicChainProperties } from \"../chains/models\";\n\nexport enum FeePaymentMethod {\n /**\n * The fee is paid in the native currency of the source chain.\n */\n WITH_NATIVE_CURRENCY = \"native\",\n\n /**\n * The fee is paid with the stablecoin token.\n */\n WITH_STABLECOIN = \"stablecoin\",\n}\n\nexport interface AmountsAndGasFeeOptions {\n /**\n * The floating point amount of tokens to be sent (not including gas fee).\n */\n amountToSendFloat: string;\n\n /**\n * The floating point amount of tokens to be received.\n */\n amountToBeReceivedFloat: string;\n\n /**\n * Available ways to pay the transfer gas fee and gas fee amount.\n */\n gasFeeOptions: GasFeeOptions;\n}\n\ntype GasFeeOptionsType = {\n [key in FeePaymentMethod]?: AmountFormatted;\n};\n\n/**\n * Describes available options of paying the gas fee and the amount to pay when using the corresponding method.\n *\n * For {@link FeePaymentMethod.WITH_NATIVE_CURRENCY} value contains the amount in the smallest denomination of the source chain currency\n *\n * For {@link FeePaymentMethod.WITH_STABLECOIN} value contains the amount in the smallest denomination of the source token\n */\nexport interface GasFeeOptions extends GasFeeOptionsType {\n [FeePaymentMethod.WITH_NATIVE_CURRENCY]: AmountFormatted;\n [FeePaymentMethod.WITH_STABLECOIN]?: AmountFormatted;\n adminFeeShareWithExtras?: string;\n}\n\n/**\n * Define the type of amount data<p/>\n * Example:<p/>\n * \"1500000\" USDC {@link AmountFormat.INT} = \"1.5\" USDC {@link AmountFormat.FLOAT}, if USDC.decimals = 6\n */\nexport enum AmountFormat {\n /**\n * denominated in the smallest unit of the source token\n */\n INT = \"int\",\n /**\n * denominated in the unit of the source token\n */\n FLOAT = \"float\",\n}\n\n/**\n * Describes the same amount in two variation formats.\n *\n * For {@link AmountFormat.INT} value contains the amount in the smallest denomination\n *\n * For {@link AmountFormat.FLOAT} value contains the amount in tokens denomination\n */\nexport type AmountFormatted = {\n [key in AmountFormat]: string;\n};\n\n/**\n * Describes MAX extra gas value can to be passed when using the corresponding method.\n *\n * For {@link FeePaymentMethod.WITH_NATIVE_CURRENCY} value contains {@link ExtraGasMaxLimit} the amount of the source chain currency\n *\n * For {@link FeePaymentMethod.WITH_STABLECOIN} value contains {@link ExtraGasMaxLimit} the amount of the source token\n */\nexport type ExtraGasMaxLimits = {\n [key in FeePaymentMethod]?: ExtraGasMaxLimit;\n};\n\n/**\n * Describes the same MAX extra gas amount.\n */\nexport type ExtraGasMaxLimit = AmountFormatted;\n\n/**\n * Provide extra gas information\n */\nexport interface ExtraGasMaxLimitResponse {\n /**\n * See {@link ExtraGasMaxLimits}\n */\n extraGasMax: ExtraGasMaxLimits;\n /**\n * Information due to destination chain\n */\n destinationChain: {\n /**\n * gasAmountMax maximum amount you can receive as extra gas on dest chain\n */\n gasAmountMax: ExtraGasMaxLimit;\n /**\n * cost of swap tx on chain\n */\n swap: AmountFormatted;\n /**\n * cost of send tx on chain\n */\n transfer: AmountFormatted;\n };\n /**\n * Exchange rate\n */\n exchangeRate: string;\n /**\n * Source native token price\n */\n sourceNativeTokenPrice: string;\n}\n\n/**\n * Provide pending status information\n */\nexport interface PendingStatusInfoResponse {\n /**\n * Number of pending transactions\n */\n pendingTxs: number;\n /**\n * Total amount of pending transactions\n */\n pendingAmount: AmountFormatted;\n /**\n * The amount of tokens can be received as a result of transfer considering pending transactions\n */\n estimatedAmount: { min: AmountFormatted; max: AmountFormatted };\n}\n"]}
|
|
@@ -5,17 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EvmBridgeService = void 0;
|
|
7
7
|
const big_js_1 = require("big.js");
|
|
8
|
-
const chains_1 = require("../../../chains");
|
|
9
8
|
const models_1 = require("../../../models");
|
|
10
|
-
const calculation_1 = require("../../../utils/calculation");
|
|
11
|
-
const utils_1 = require("../../../utils/utils");
|
|
12
9
|
const Bridge_1 = __importDefault(require("../../models/abi/Bridge"));
|
|
13
10
|
const CctpBridge_1 = __importDefault(require("../../models/abi/CctpBridge"));
|
|
14
11
|
const OftBridge_1 = __importDefault(require("../../models/abi/OftBridge"));
|
|
15
|
-
const PayerWithAbr_1 = __importDefault(require("../../models/abi/PayerWithAbr"));
|
|
16
12
|
const get_cctp_sol_token_recipient_address_1 = require("../get-cctp-sol-token-recipient-address");
|
|
17
13
|
const models_2 = require("../models");
|
|
18
|
-
const
|
|
14
|
+
const utils_1 = require("../utils");
|
|
19
15
|
class EvmBridgeService extends models_2.ChainBridgeService {
|
|
20
16
|
web3;
|
|
21
17
|
api;
|
|
@@ -32,7 +28,7 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
32
28
|
return this.sendRawTransaction(rawTransaction);
|
|
33
29
|
}
|
|
34
30
|
async buildRawTransactionSwap(params) {
|
|
35
|
-
const txSwapParams = (0,
|
|
31
|
+
const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
|
|
36
32
|
return await this.buildRawTransactionSwapFromParams(txSwapParams);
|
|
37
33
|
}
|
|
38
34
|
async buildRawTransactionSwapFromParams(params) {
|
|
@@ -46,27 +42,15 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
44
|
async buildRawTransactionSend(params) {
|
|
49
|
-
const txSendParams = await (0,
|
|
50
|
-
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toChainId, toAccountAddress, toTokenAddress, messenger, fee, gasFeePaymentMethod, extraGas, extraGasDest,
|
|
51
|
-
const nonce = "0x" + (0,
|
|
45
|
+
const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
|
|
46
|
+
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toChainId, toAccountAddress, toTokenAddress, messenger, fee, gasFeePaymentMethod, extraGas, extraGasDest, } = txSendParams;
|
|
47
|
+
const nonce = "0x" + (0, utils_1.getNonce)().toString("hex");
|
|
52
48
|
let sendMethod;
|
|
53
49
|
let value;
|
|
54
50
|
let totalFee = fee;
|
|
55
51
|
if (extraGas) {
|
|
56
52
|
totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
|
|
57
53
|
}
|
|
58
|
-
let totalFeeInAbr;
|
|
59
|
-
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_ARB) {
|
|
60
|
-
if (!abrExchangeRate) {
|
|
61
|
-
throw new models_1.SdkError("Cannot find 'abrExchangeRate' for ARB0 payment method");
|
|
62
|
-
}
|
|
63
|
-
if (!params.sourceToken.abrPayer) {
|
|
64
|
-
throw new models_1.SdkError("Source token must contain 'abrPayer' for ARB0 payment method");
|
|
65
|
-
}
|
|
66
|
-
totalFeeInAbr = totalFee;
|
|
67
|
-
const totalFeeInNativeRaw = (0, big_js_1.Big)(totalFee).div(abrExchangeRate);
|
|
68
|
-
totalFee = (0, calculation_1.convertAmountPrecision)(totalFeeInNativeRaw, params.sourceToken.abrPayer.abrToken.decimals, chains_1.Chains.getChainDecimalsByType(params.sourceToken.chainType)).toFixed();
|
|
69
|
-
}
|
|
70
54
|
switch (messenger) {
|
|
71
55
|
case models_1.Messenger.CCTP:
|
|
72
56
|
case models_1.Messenger.CCTP_V2: {
|
|
@@ -85,44 +69,17 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
85
69
|
case models_1.Messenger.WORMHOLE:
|
|
86
70
|
{
|
|
87
71
|
const bridgeContract = this.getBridgeContract(contractAddress);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
96
|
-
sendMethod = bridgeContract.methods.swapAndBridge(fromTokenAddress, amount, toAccountAddress, toChainId, toTokenAddress, nonce, messenger, totalFee);
|
|
97
|
-
value = "0";
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
default: {
|
|
101
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
102
|
-
}
|
|
72
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
73
|
+
sendMethod = bridgeContract.methods.swapAndBridge(fromTokenAddress, amount, toAccountAddress, toChainId, toTokenAddress, nonce, messenger, totalFee);
|
|
74
|
+
value = "0";
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
sendMethod = bridgeContract.methods.swapAndBridge(fromTokenAddress, amount, toAccountAddress, toChainId, toTokenAddress, nonce, messenger, 0);
|
|
78
|
+
value = totalFee;
|
|
103
79
|
}
|
|
104
80
|
}
|
|
105
81
|
break;
|
|
106
82
|
}
|
|
107
|
-
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_ARB) {
|
|
108
|
-
if (!params.sourceToken.abrPayer) {
|
|
109
|
-
throw new models_1.SdkError("Source token must contain 'abrPayer' for ARB0 payment method");
|
|
110
|
-
}
|
|
111
|
-
const abrPayerAddress = params.sourceToken.abrPayer.payerAddress;
|
|
112
|
-
if (!totalFeeInAbr) {
|
|
113
|
-
throw new models_1.SdkError("Failed to calculate totalFeeInAbr");
|
|
114
|
-
}
|
|
115
|
-
const abrPayerContract = this.getAbrPayerContract(abrPayerAddress);
|
|
116
|
-
const abi = sendMethod.encodeABI();
|
|
117
|
-
const withoutSelector = "0x" + abi.slice(10);
|
|
118
|
-
sendMethod = abrPayerContract.methods.transferTokensAndCallTarget(params.sourceToken.tokenAddress, amount, totalFeeInAbr, messenger, withoutSelector);
|
|
119
|
-
return Promise.resolve({
|
|
120
|
-
from: fromAccountAddress,
|
|
121
|
-
to: abrPayerAddress,
|
|
122
|
-
value: "0",
|
|
123
|
-
data: sendMethod.encodeABI(),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
83
|
return Promise.resolve({
|
|
127
84
|
from: fromAccountAddress,
|
|
128
85
|
to: contractAddress,
|
|
@@ -137,39 +94,23 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
137
94
|
let value;
|
|
138
95
|
if (params.destinationToken.chainType === models_1.ChainType.SOLANA) {
|
|
139
96
|
const recipient = await (0, get_cctp_sol_token_recipient_address_1.getCctpSolTokenRecipientAddress)(this.chainType, params.toAccountAddress, params.destinationToken.tokenAddress, this.nodeRpcUrlsConfig.getNodeRpcUrl(models_1.ChainSymbol.SOL));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
148
|
-
sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(amount, recipient, toAccountAddress, toChainId, totalFee);
|
|
149
|
-
value = "0";
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
default: {
|
|
153
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
154
|
-
}
|
|
97
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
98
|
+
sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(amount, recipient, toAccountAddress, toChainId, totalFee);
|
|
99
|
+
value = "0";
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(amount, recipient, toAccountAddress, toChainId, 0);
|
|
103
|
+
value = totalFee;
|
|
155
104
|
}
|
|
156
105
|
}
|
|
157
106
|
else {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
166
|
-
sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);
|
|
167
|
-
value = "0";
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
default: {
|
|
171
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
172
|
-
}
|
|
107
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
108
|
+
sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);
|
|
109
|
+
value = "0";
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);
|
|
113
|
+
value = totalFee;
|
|
173
114
|
}
|
|
174
115
|
}
|
|
175
116
|
return { sendMethod, value };
|
|
@@ -179,21 +120,13 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
179
120
|
const oftBridgeContract = this.getOftBridgeContract(contractAddress);
|
|
180
121
|
let sendMethod;
|
|
181
122
|
let value;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
190
|
-
sendMethod = oftBridgeContract.methods.bridge(params.sourceToken.tokenAddress, amount, toAccountAddress, toChainId, totalFee, extraGasDest ?? "0", "10");
|
|
191
|
-
value = "0";
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
default: {
|
|
195
|
-
return (0, utils_1.assertNever)(gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
196
|
-
}
|
|
123
|
+
if (gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN) {
|
|
124
|
+
sendMethod = oftBridgeContract.methods.bridge(params.sourceToken.tokenAddress, amount, toAccountAddress, toChainId, totalFee, extraGasDest ?? "0", "10");
|
|
125
|
+
value = "0";
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
sendMethod = oftBridgeContract.methods.bridge(params.sourceToken.tokenAddress, amount, toAccountAddress, toChainId, 0, extraGasDest ?? "0", "10");
|
|
129
|
+
value = totalFee;
|
|
197
130
|
}
|
|
198
131
|
return { sendMethod, value };
|
|
199
132
|
}
|
|
@@ -218,9 +151,6 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
218
151
|
getOftBridgeContract(contractAddress) {
|
|
219
152
|
return new this.web3.eth.Contract(OftBridge_1.default.abi, contractAddress);
|
|
220
153
|
}
|
|
221
|
-
getAbrPayerContract(contractAddress) {
|
|
222
|
-
return new this.web3.eth.Contract(PayerWithAbr_1.default.abi, contractAddress);
|
|
223
|
-
}
|
|
224
154
|
}
|
|
225
155
|
exports.EvmBridgeService = EvmBridgeService;
|
|
226
156
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/evm/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6B;AAI7B,4CAAyC;AAEzC,4CASyB;AACzB,4DAAoE;AACpE,gDAAmD;AAGnD,qEAA6C;AAC7C,6EAAqD;AACrD,2EAAmD;AACnD,iFAAyD;AACzD,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAI7C;IACA;IACC;IALV,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,IAAmB,EACnB,GAAwB,EACvB,iBAAoC;QAE5C,KAAK,EAAE,CAAC;QAJD,SAAI,GAAJ,IAAI,CAAe;QACnB,QAAG,GAAH,GAAG,CAAqB;QACvB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAG9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAA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,QAAQ,CAAC,oBAAU,CAAC,GAAG,EAAE,eAAe,CAAoC,CAAC;IACxG,CAAC;IAEO,oBAAoB,CAAC,eAAuB;QAClD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAS,CAAC,GAAG,EAAE,eAAe,CAAmC,CAAC;IACtG,CAAC;IAEO,mBAAmB,CAAC,eAAuB;QACjD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,sBAAY,CAAC,GAAG,EAAE,eAAe,CAAsC,CAAC;IAC5G,CAAC;CACF;AAlVD,4CAkVC","sourcesContent":["import { Big } from \"big.js\";\nimport BN from \"bn.js\";\nimport { Contract, Transaction as Web3Transaction } from \"web3\";\nimport { PayableMethodObject } from \"web3-eth-contract\";\nimport { Chains } from \"../../../chains\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n EssentialWeb3,\n FeePaymentMethod,\n Messenger,\n SdkError,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { convertAmountPrecision } from \"../../../utils/calculation\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport Bridge from \"../../models/abi/Bridge\";\nimport CctpBridge from \"../../models/abi/CctpBridge\";\nimport OftBridge from \"../../models/abi/OftBridge\";\nimport PayerWithAbr from \"../../models/abi/PayerWithAbr\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsEvm, TxSwapParamsEvm } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class EvmBridgeService extends ChainBridgeService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionSend(params);\n return this.sendRawTransaction(rawTransaction);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsEvm): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const bridgeContract = this.getBridgeContract(contractAddress);\n\n const swapMethod = bridgeContract.methods.swap(\n amount,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n data: swapMethod.encodeABI(),\n });\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n abrExchangeRate,\n } = txSendParams;\n\n const nonce = \"0x\" + getNonce().toString(\"hex\");\n let sendMethod: PayableMethodObject;\n let value: string;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n let totalFeeInAbr: string | undefined;\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (!abrExchangeRate) {\n throw new SdkError(\"Cannot find 'abrExchangeRate' for ARB0 payment method\");\n }\n if (!params.sourceToken.abrPayer) {\n throw new SdkError(\"Source token must contain 'abrPayer' for ARB0 payment method\");\n }\n totalFeeInAbr = totalFee;\n const totalFeeInNativeRaw = Big(totalFee).div(abrExchangeRate);\n totalFee = convertAmountPrecision(\n totalFeeInNativeRaw,\n params.sourceToken.abrPayer.abrToken.decimals,\n Chains.getChainDecimalsByType(params.sourceToken.chainType)\n ).toFixed();\n }\n\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const cctp = await this.buildRawTransactionCctpSend(params, txSendParams, totalFee);\n sendMethod = cctp.sendMethod;\n value = cctp.value;\n break;\n }\n case Messenger.OFT: {\n const oft = this.buildRawTransactionOftSend(params, txSendParams, totalFee, extraGasDest);\n sendMethod = oft.sendMethod;\n value = oft.value;\n break;\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n {\n const bridgeContract = this.getBridgeContract(contractAddress);\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n 0\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n totalFee\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n }\n break;\n }\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (!params.sourceToken.abrPayer) {\n throw new SdkError(\"Source token must contain 'abrPayer' for ARB0 payment method\");\n }\n\n const abrPayerAddress = params.sourceToken.abrPayer.payerAddress;\n\n if (!totalFeeInAbr) {\n throw new SdkError(\"Failed to calculate totalFeeInAbr\");\n }\n const abrPayerContract = this.getAbrPayerContract(abrPayerAddress);\n\n const abi = sendMethod.encodeABI();\n const withoutSelector = \"0x\" + abi.slice(10);\n sendMethod = abrPayerContract.methods.transferTokensAndCallTarget(\n params.sourceToken.tokenAddress,\n amount,\n totalFeeInAbr,\n messenger,\n withoutSelector\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: abrPayerAddress,\n value: \"0\",\n data: sendMethod.encodeABI(),\n });\n }\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n value: value,\n data: sendMethod.encodeABI(),\n });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string\n ): Promise<{\n sendMethod: PayableMethodObject;\n value: string;\n }> {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const cctpBridgeContract = this.getCctpBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipient = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n 0\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n totalFee\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n } else {\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n }\n return { sendMethod, value };\n }\n\n private buildRawTransactionOftSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string,\n extraGasDest?: string\n ): {\n sendMethod: PayableMethodObject;\n value: string;\n } {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const oftBridgeContract = this.getOftBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_ARB:\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n 0,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = totalFee;\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n totalFee,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = \"0\";\n break;\n }\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return { sendMethod, value };\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction) {\n const estimateGas = await this.web3.eth.estimateGas(rawTransaction as Web3Transaction);\n\n // @ts-expect-error DISABLE SITE SUGGESTED GAS FEE IN METAMASK\n // prettier-ignore\n const feeOptions: { maxPriorityFeePerGas?: number | string | BN; maxFeePerGas?: number | string | BN } = { maxPriorityFeePerGas: null, maxFeePerGas: null };\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...(rawTransaction as object),\n gas: estimateGas,\n ...feeOptions,\n } as Web3Transaction);\n return { txId: transactionHash.toString() };\n }\n\n private getBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(Bridge.abi, contractAddress) as Contract<typeof Bridge.abi>;\n }\n\n private getCctpBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(CctpBridge.abi, contractAddress) as Contract<typeof CctpBridge.abi>;\n }\n\n private getOftBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(OftBridge.abi, contractAddress) as Contract<typeof OftBridge.abi>;\n }\n\n private getAbrPayerContract(contractAddress: string) {\n return new this.web3.eth.Contract(PayerWithAbr.abi, contractAddress) as Contract<typeof PayerWithAbr.abi>;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/evm/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6B;AAK7B,4CAQyB;AAGzB,qEAA6C;AAC7C,6EAAqD;AACrD,2EAAmD;AACnD,kGAA0F;AAC1F,sCAA6F;AAC7F,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAI7C;IACA;IACC;IALV,SAAS,GAAkB,kBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,IAAmB,EACnB,GAAwB,EACvB,iBAAoC;QAE5C,KAAK,EAAE,CAAC;QAJD,SAAI,GAAJ,IAAI,CAAe;QACnB,QAAG,GAAH,GAAG,CAAqB;QACvB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAG9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAkB;QAC3B,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACjE,OAAO,MAAM,IAAI,CAAC,iCAAiC,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,iCAAiC,CAAC,MAAuB;QAC7D,MAAM,EACJ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C;IAEO,KAAK,CAAC,kBAAkB,CAAC,cAA8B;QAC7D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,cAAiC,CAAC,CAAC;QAEvF,8DAA8D;QAC9D,kBAAkB;QAClB,MAAM,UAAU,GAAyF,EAAE,oBAAoB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;QAC5J,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC;YAC9D,GAAI,cAAyB;YAC7B,GAAG,EAAE,WAAW;YAChB,GAAG,UAAU;SACK,CAAC,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC9C,CAAC;IAEO,iBAAiB,CAAC,eAAuB;QAC/C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAM,CAAC,GAAG,EAAE,eAAe,CAAgC,CAAC;IAChG,CAAC;IAEO,qBAAqB,CAAC,eAAuB;QACnD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,oBAAU,CAAC,GAAG,EAAE,eAAe,CAAoC,CAAC;IACxG,CAAC;IAEO,oBAAoB,CAAC,eAAuB;QAClD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAS,CAAC,GAAG,EAAE,eAAe,CAAmC,CAAC;IACtG,CAAC;CACF;AA1PD,4CA0PC","sourcesContent":["import { Big } from \"big.js\";\nimport BN from \"bn.js\";\nimport { Contract, Transaction as Web3Transaction } from \"web3\";\nimport { PayableMethodObject } from \"web3-eth-contract\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport {\n ChainSymbol,\n ChainType,\n EssentialWeb3,\n FeePaymentMethod,\n Messenger,\n SwapParams,\n TransactionResponse,\n} from \"../../../models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport Bridge from \"../../models/abi/Bridge\";\nimport CctpBridge from \"../../models/abi/CctpBridge\";\nimport OftBridge from \"../../models/abi/OftBridge\";\nimport { getCctpSolTokenRecipientAddress } from \"../get-cctp-sol-token-recipient-address\";\nimport { ChainBridgeService, SendParams, TxSendParamsEvm, TxSwapParamsEvm } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class EvmBridgeService extends ChainBridgeService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig\n ) {\n super();\n }\n\n async send(params: SendParams): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionSend(params);\n return this.sendRawTransaction(rawTransaction);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsEvm): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n\n const bridgeContract = this.getBridgeContract(contractAddress);\n\n const swapMethod = bridgeContract.methods.swap(\n amount,\n fromTokenAddress,\n toTokenAddress,\n toAccountAddress,\n minimumReceiveAmount\n );\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n data: swapMethod.encodeABI(),\n });\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n messenger,\n fee,\n gasFeePaymentMethod,\n extraGas,\n extraGasDest,\n } = txSendParams;\n\n const nonce = \"0x\" + getNonce().toString(\"hex\");\n let sendMethod: PayableMethodObject;\n let value: string;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n\n switch (messenger) {\n case Messenger.CCTP:\n case Messenger.CCTP_V2: {\n const cctp = await this.buildRawTransactionCctpSend(params, txSendParams, totalFee);\n sendMethod = cctp.sendMethod;\n value = cctp.value;\n break;\n }\n case Messenger.OFT: {\n const oft = this.buildRawTransactionOftSend(params, txSendParams, totalFee, extraGasDest);\n sendMethod = oft.sendMethod;\n value = oft.value;\n break;\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n {\n const bridgeContract = this.getBridgeContract(contractAddress);\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n totalFee\n );\n value = \"0\";\n } else {\n sendMethod = bridgeContract.methods.swapAndBridge(\n fromTokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n toTokenAddress,\n nonce,\n messenger,\n 0\n );\n value = totalFee;\n }\n }\n break;\n }\n\n return Promise.resolve({\n from: fromAccountAddress,\n to: contractAddress,\n value: value,\n data: sendMethod.encodeABI(),\n });\n }\n\n private async buildRawTransactionCctpSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string\n ): Promise<{\n sendMethod: PayableMethodObject;\n value: string;\n }> {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const cctpBridgeContract = this.getCctpBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (params.destinationToken.chainType === ChainType.SOLANA) {\n const recipient = await getCctpSolTokenRecipientAddress(\n this.chainType,\n params.toAccountAddress,\n params.destinationToken.tokenAddress,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL)\n );\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n totalFee\n );\n value = \"0\";\n } else {\n sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(\n amount,\n recipient,\n toAccountAddress,\n toChainId,\n 0\n );\n value = totalFee;\n }\n } else {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, totalFee);\n value = \"0\";\n } else {\n sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);\n value = totalFee;\n }\n }\n return { sendMethod, value };\n }\n\n private buildRawTransactionOftSend(\n params: SendParams,\n txSendParams: TxSendParamsEvm,\n totalFee: string,\n extraGasDest?: string\n ): {\n sendMethod: PayableMethodObject;\n value: string;\n } {\n const { amount, contractAddress, toChainId, toAccountAddress, gasFeePaymentMethod } = txSendParams;\n\n const oftBridgeContract = this.getOftBridgeContract(contractAddress);\n let sendMethod: PayableMethodObject;\n let value: string;\n\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN) {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n totalFee,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = \"0\";\n } else {\n sendMethod = oftBridgeContract.methods.bridge(\n params.sourceToken.tokenAddress,\n amount,\n toAccountAddress,\n toChainId,\n 0,\n extraGasDest ?? \"0\",\n \"10\"\n );\n value = totalFee;\n }\n\n return { sendMethod, value };\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction) {\n const estimateGas = await this.web3.eth.estimateGas(rawTransaction as Web3Transaction);\n\n // @ts-expect-error DISABLE SITE SUGGESTED GAS FEE IN METAMASK\n // prettier-ignore\n const feeOptions: { maxPriorityFeePerGas?: number | string | BN; maxFeePerGas?: number | string | BN } = { maxPriorityFeePerGas: null, maxFeePerGas: null };\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...(rawTransaction as object),\n gas: estimateGas,\n ...feeOptions,\n } as Web3Transaction);\n return { txId: transactionHash.toString() };\n }\n\n private getBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(Bridge.abi, contractAddress) as Contract<typeof Bridge.abi>;\n }\n\n private getCctpBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(CctpBridge.abi, contractAddress) as Contract<typeof CctpBridge.abi>;\n }\n\n private getOftBridgeContract(contractAddress: string) {\n return new this.web3.eth.Contract(OftBridge.abi, contractAddress) as Contract<typeof OftBridge.abi>;\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeRpcUrlsConfig } from "..";
|
|
2
2
|
import { Messenger } from "../../client/core-api/core-api.model";
|
|
3
3
|
import { AllbridgeCoreClient } from "../../client/core-api/core-client-base";
|
|
4
|
-
import { AllbridgeCoreSdkOptions
|
|
4
|
+
import { AllbridgeCoreSdkOptions } from "../../index";
|
|
5
5
|
import { TokenWithChainDetails } from "../../tokens-info";
|
|
6
6
|
import { Provider, TransactionResponse } from "../models";
|
|
7
7
|
import { TokenService } from "../token";
|
|
@@ -65,5 +65,5 @@ export declare class DefaultBridgeService implements BridgeService {
|
|
|
65
65
|
approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;
|
|
66
66
|
send(provider: Provider, params: SendParams): Promise<TransactionResponse>;
|
|
67
67
|
}
|
|
68
|
-
export declare function getSpender(token: TokenWithChainDetails, messenger?: Messenger
|
|
68
|
+
export declare function getSpender(token: TokenWithChainDetails, messenger?: Messenger): string;
|
|
69
69
|
export declare function getChainBridgeService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): ChainBridgeService;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DefaultBridgeService = void 0;
|
|
4
4
|
exports.getSpender = getSpender;
|
|
5
5
|
exports.getChainBridgeService = getChainBridgeService;
|
|
6
|
-
const algokit_utils_1 = require("@algorandfoundation/algokit-utils");
|
|
7
6
|
const tronweb_1 = require("tronweb");
|
|
8
7
|
const web3_1 = require("web3");
|
|
9
8
|
const chains_1 = require("../../chains");
|
|
@@ -11,12 +10,10 @@ const core_api_model_1 = require("../../client/core-api/core-api.model");
|
|
|
11
10
|
const exceptions_1 = require("../../exceptions");
|
|
12
11
|
const index_1 = require("../../index");
|
|
13
12
|
const utils_1 = require("../../utils/utils");
|
|
14
|
-
const alg_1 = require("./alg");
|
|
15
13
|
const evm_1 = require("./evm");
|
|
16
14
|
const raw_bridge_transaction_builder_1 = require("./raw-bridge-transaction-builder");
|
|
17
15
|
const sol_1 = require("./sol");
|
|
18
16
|
const srb_1 = require("./srb");
|
|
19
|
-
const stx_1 = require("./stx");
|
|
20
17
|
const sui_1 = require("./sui");
|
|
21
18
|
const trx_1 = require("./trx");
|
|
22
19
|
class DefaultBridgeService {
|
|
@@ -42,7 +39,7 @@ class DefaultBridgeService {
|
|
|
42
39
|
else {
|
|
43
40
|
params = a;
|
|
44
41
|
}
|
|
45
|
-
const spender = getSpender(params.token, params.messenger
|
|
42
|
+
const spender = getSpender(params.token, params.messenger);
|
|
46
43
|
return await this.tokenService.getAllowance({ ...params, spender }, provider);
|
|
47
44
|
}
|
|
48
45
|
async checkAllowance(a, b) {
|
|
@@ -55,11 +52,11 @@ class DefaultBridgeService {
|
|
|
55
52
|
else {
|
|
56
53
|
params = a;
|
|
57
54
|
}
|
|
58
|
-
const spender = getSpender(params.token, params.messenger
|
|
55
|
+
const spender = getSpender(params.token, params.messenger);
|
|
59
56
|
return this.tokenService.checkAllowance({ ...params, spender }, provider);
|
|
60
57
|
}
|
|
61
58
|
async approve(provider, approveData) {
|
|
62
|
-
const spender = getSpender(approveData.token, approveData.messenger
|
|
59
|
+
const spender = getSpender(approveData.token, approveData.messenger);
|
|
63
60
|
return this.tokenService.approve(provider, { ...approveData, spender });
|
|
64
61
|
}
|
|
65
62
|
async send(provider, params) {
|
|
@@ -69,13 +66,7 @@ class DefaultBridgeService {
|
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
exports.DefaultBridgeService = DefaultBridgeService;
|
|
72
|
-
function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE
|
|
73
|
-
if (gasFeePaymentMethod === index_1.FeePaymentMethod.WITH_ARB) {
|
|
74
|
-
if (token.abrPayer) {
|
|
75
|
-
return token.abrPayer.payerAddress;
|
|
76
|
-
}
|
|
77
|
-
throw new exceptions_1.SdkError("Token must contain 'abrPayer' for ARB0 payment method");
|
|
78
|
-
}
|
|
69
|
+
function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE) {
|
|
79
70
|
switch (messenger) {
|
|
80
71
|
case core_api_model_1.Messenger.CCTP:
|
|
81
72
|
if (token.cctpAddress) {
|
|
@@ -145,24 +136,6 @@ function getChainBridgeService(chainSymbol, api, nodeRpcUrlsConfig, params, prov
|
|
|
145
136
|
case index_1.ChainType.SUI: {
|
|
146
137
|
return new sui_1.SuiBridgeService(nodeRpcUrlsConfig, api);
|
|
147
138
|
}
|
|
148
|
-
case index_1.ChainType.ALG: {
|
|
149
|
-
if (provider) {
|
|
150
|
-
const algod = provider;
|
|
151
|
-
const algorand = algokit_utils_1.AlgorandClient.fromClients({ algod });
|
|
152
|
-
return new alg_1.AlgBridgeService(algorand, api);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);
|
|
156
|
-
const algorand = algokit_utils_1.AlgorandClient.fromConfig({
|
|
157
|
-
algodConfig: { server: nodeRpcUrl },
|
|
158
|
-
});
|
|
159
|
-
return new alg_1.AlgBridgeService(algorand, api);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
case index_1.ChainType.STX: {
|
|
163
|
-
const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);
|
|
164
|
-
return new stx_1.StxBridgeService(nodeRpcUrl, params, api);
|
|
165
|
-
}
|
|
166
139
|
}
|
|
167
140
|
}
|
|
168
141
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAqIA,gCAkCC;AAED,sDAuEC;AAhPD,qEAAmE;AAEnE,qCAAkC;AAClC,+BAA4B;AAE5B,yCAAsC;AACtC,yEAAiE;AAEjE,iDAAiG;AACjG,uCAA+G;AAE/G,6CAAiF;AAGjF,+BAAyC;AACzC,+BAAyC;AAEzC,qFAAmH;AACnH,+BAA4C;AAC5C,+BAAyC;AACzC,+BAAyC;AACzC,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,CAA8B;IAEjD,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,mEAAkC,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3G,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,CAAgC,EAAE,CAAsB;QACzE,IAAI,QAA8B,CAAC;QACnC,IAAI,MAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAuB,CAAC;QACnC,CAAC;QACD,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;YAChE,OAAO,IAAI,sBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { Algodv2 } from \"algosdk\";\nimport { TronWeb } from \"tronweb\";\nimport { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError, SdkError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3, FeePaymentMethod } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { AlgBridgeService } from \"./alg\";\nimport { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { StxBridgeService } from \"./stx\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).send(params);\n }\n}\n\nexport function getSpender(\n token: TokenWithChainDetails,\n messenger: Messenger = Messenger.ALLBRIDGE,\n gasFeePaymentMethod: FeePaymentMethod = FeePaymentMethod.WITH_NATIVE_CURRENCY\n): string {\n if (gasFeePaymentMethod === FeePaymentMethod.WITH_ARB) {\n if (token.abrPayer) {\n return token.abrPayer.payerAddress;\n }\n throw new SdkError(\"Token must contain 'abrPayer' for ARB0 payment method\");\n }\n switch (messenger) {\n case Messenger.CCTP:\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n case Messenger.CCTP_V2:\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n case Messenger.OFT:\n if (token.oftBridgeAddress) {\n return token.oftBridgeAddress;\n } else {\n throw new OFTDoesNotSupportedError(\"Such route does not support OFT protocol\");\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n\nexport function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainBridgeService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronBridgeService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new TronBridgeService(\n new TronWeb({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n case ChainType.ALG: {\n if (provider) {\n const algod = provider as Algodv2;\n const algorand = AlgorandClient.fromClients({ algod });\n return new AlgBridgeService(algorand, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const algorand = AlgorandClient.fromConfig({\n algodConfig: { server: nodeRpcUrl },\n });\n return new AlgBridgeService(algorand, api);\n }\n }\n case ChainType.STX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new StxBridgeService(nodeRpcUrl, params, api);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/bridge/index.ts"],"names":[],"mappings":";;;AAiIA,gCAwBC;AAED,sDAsDC;AAjND,qCAAkC;AAClC,+BAA4B;AAE5B,yCAAsC;AACtC,yEAAiE;AAEjE,iDAAuF;AACvF,uCAA6F;AAE7F,6CAAiF;AAGjF,+BAAyC;AAEzC,qFAAmH;AACnH,+BAA4C;AAC5C,+BAAyC;AACzC,+BAAyC;AACzC,+BAA0C;AAuD1C,MAAa,oBAAoB;IAIrB;IACA;IACA;IACA;IANH,YAAY,CAA8B;IAEjD,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAAqB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,mEAAkC,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3G,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,CAAgC,EAAE,CAAsB;QACzE,IAAI,QAA8B,CAAC;QACnC,IAAI,MAA0B,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC;YACN,QAAQ,GAAG,CAAa,CAAC;YACzB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,CAAuB,CAAC;QACnC,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,C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} from \"tronweb\";\nimport { Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { Messenger } from \"../../client/core-api/core-api.model\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { CCTPDoesNotSupportedError, OFTDoesNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType, EssentialWeb3 } from \"../../index\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { EvmBridgeService } from \"./evm\";\nimport { ApproveParams, ChainBridgeService, CheckAllowanceParams, GetAllowanceParams, SendParams } from \"./models\";\nimport { DefaultRawBridgeTransactionBuilder, RawBridgeTransactionBuilder } from \"./raw-bridge-transaction-builder\";\nimport { SolanaBridgeService } from \"./sol\";\nimport { SrbBridgeService } from \"./srb\";\nimport { SuiBridgeService } from \"./sui\";\nimport { TronBridgeService } from \"./trx\";\n\nexport interface BridgeService {\n rawTxBuilder: RawBridgeTransactionBuilder;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved to be sent by the bridge\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough to make a transfer\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawBridgeTransactionBuilder.send}<p>\n * Send tokens through the ChainBridgeService\n * @param provider - will be used to access the network\n * @param params\n */\n send(provider: Provider, params: SendParams): Promise<TransactionResponse>;\n}\n\nexport class DefaultBridgeService implements BridgeService {\n public rawTxBuilder: RawBridgeTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n let provider: Provider | undefined;\n let params: GetAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as GetAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return await this.tokenService.getAllowance({ ...params, spender }, provider);\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n let provider: Provider | undefined;\n let params: CheckAllowanceParams;\n if (b) {\n provider = a as Provider;\n params = b;\n } else {\n params = a as CheckAllowanceParams;\n }\n const spender = getSpender(params.token, params.messenger);\n return this.tokenService.checkAllowance({ ...params, spender }, provider);\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n const spender = getSpender(approveData.token, approveData.messenger);\n return this.tokenService.approve(provider, { ...approveData, spender });\n }\n\n async send(provider: Provider, params: SendParams): Promise<TransactionResponse> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.sourceToken.decimals);\n return getChainBridgeService(\n params.sourceToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).send(params);\n }\n}\n\nexport function getSpender(token: TokenWithChainDetails, messenger: Messenger = Messenger.ALLBRIDGE): string {\n switch (messenger) {\n case Messenger.CCTP:\n if (token.cctpAddress) {\n return token.cctpAddress;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP protocol\");\n }\n case Messenger.CCTP_V2:\n if (token.cctpV2Address) {\n return token.cctpV2Address;\n } else {\n throw new CCTPDoesNotSupportedError(\"Such route does not support CCTP V2 protocol\");\n }\n case Messenger.OFT:\n if (token.oftBridgeAddress) {\n return token.oftBridgeAddress;\n } else {\n throw new OFTDoesNotSupportedError(\"Such route does not support OFT protocol\");\n }\n case Messenger.ALLBRIDGE:\n case Messenger.WORMHOLE:\n return token.bridgeAddress;\n }\n}\n\nexport function getChainBridgeService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainBridgeService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmBridgeService(provider as EssentialWeb3, api, nodeRpcUrlsConfig);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new EvmBridgeService(new Web3(nodeRpcUrl), api, nodeRpcUrlsConfig);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronBridgeService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new TronBridgeService(\n new TronWeb({\n fullHost: nodeRpcUrl,\n solidityNode: nodeRpcUrl,\n eventServer: nodeRpcUrl,\n }),\n api\n );\n }\n }\n case ChainType.SOLANA: {\n return new SolanaBridgeService(\n nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL),\n {\n wormholeMessengerProgramId: params.wormholeMessengerProgramId,\n solanaLookUpTable: params.solanaLookUpTable,\n cctpParams: params.cctpParams,\n jupiterParams: {\n jupiterUrl: params.jupiterUrl,\n jupiterApiKeyHeader: params.jupiterApiKeyHeader,\n jupiterMaxAccounts: params.jupiterMaxAccounts,\n },\n },\n api\n );\n }\n case ChainType.SRB: {\n return new SrbBridgeService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiBridgeService(nodeRpcUrlsConfig, api);\n }\n }\n}\n"]}
|