@allbridge/bridge-core-sdk 3.27.0-alpha.2 → 3.27.0-alpha.20
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 +3 -3
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +7 -2
- package/dist/src/chains/chain.enums.js +5 -0
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +6 -0
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +1 -0
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +32 -0
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +13 -2
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +1 -0
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.js +5 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +12 -4
- package/dist/src/models/index.js +4 -0
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/alg/index.d.ts +1 -0
- package/dist/src/services/bridge/alg/index.js +79 -43
- package/dist/src/services/bridge/alg/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +1 -0
- package/dist/src/services/bridge/evm/index.js +103 -33
- 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 +15 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +12 -4
- 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 +36 -28
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/stx/index.d.ts +16 -0
- package/dist/src/services/bridge/stx/index.js +136 -0
- package/dist/src/services/bridge/stx/index.js.map +1 -0
- package/dist/src/services/bridge/sui/index.js +166 -138
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +98 -70
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +3 -1
- package/dist/src/services/bridge/utils.js +92 -8
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/alg/index.js +10 -17
- package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +5 -0
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +21 -0
- package/dist/src/services/liquidity-pool/stx/index.js +141 -0
- package/dist/src/services/liquidity-pool/stx/index.js.map +1 -0
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
- package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
- package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
- package/dist/src/services/models/alg/BridgeClient.d.ts +158 -133
- package/dist/src/services/models/alg/BridgeClient.js +182 -130
- package/dist/src/services/models/alg/BridgeClient.js.map +1 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +639 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js +425 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +1 -0
- package/dist/src/services/models/alg/PoolClient.d.ts +204 -201
- package/dist/src/services/models/alg/PoolClient.js +234 -215
- package/dist/src/services/models/alg/PoolClient.js.map +1 -1
- package/dist/src/services/models/index.d.ts +2 -1
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +657 -0
- package/dist/src/services/models/stx/clarigen-types.js +2296 -0
- package/dist/src/services/models/stx/clarigen-types.js.map +1 -0
- package/dist/src/services/token/index.js +7 -2
- 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/stx/index.d.ts +20 -0
- package/dist/src/services/token/stx/index.js +59 -0
- package/dist/src/services/token/stx/index.js.map +1 -0
- package/dist/src/services/utils/alg/index.d.ts +1 -10
- package/dist/src/services/utils/alg/index.js +0 -20
- package/dist/src/services/utils/alg/index.js.map +1 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +2 -0
- package/dist/src/services/utils/stx/get-token-name.js +15 -0
- package/dist/src/services/utils/stx/get-token-name.js.map +1 -0
- package/dist/src/services/utils/stx/post-conditions.d.ts +3 -0
- package/dist/src/services/utils/stx/post-conditions.js +27 -0
- package/dist/src/services/utils/stx/post-conditions.js.map +1 -0
- package/dist/src/services/yield/index.js +4 -0
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +21 -0
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/utils.d.ts +2 -0
- package/dist/src/utils/utils.js +11 -0
- 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 +6 -2
package/dist/src/models/index.js
CHANGED
|
@@ -36,6 +36,10 @@ 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";
|
|
39
43
|
})(FeePaymentMethod || (exports.FeePaymentMethod = FeePaymentMethod = {}));
|
|
40
44
|
/**
|
|
41
45
|
* 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;AAaf,2DAAyC;AAEzC,6DAAyF;AAAhF,qHAAA,sBAAsB,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAmCjD,gDAA8B;AAC9B,qDAA+D;AAAtD,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAG/B,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,mDAA+B,CAAA;IAE/B;;OAEG;IACH,kDAA8B,CAAA;IAE9B;;OAEG;IACH,oCAAgB,CAAA;AAClB,CAAC,EAfW,gBAAgB,gCAAhB,gBAAgB,QAe3B;AAqCD;;;;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 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 {\n PoolInfo,\n TokenCoreFields,\n TokenWithChainDetails,\n TransferTime,\n TxCostAmount,\n SuiAddresses,\n MessengerTransferTime,\n ChainDetailsMap,\n ChainDetailsWithTokens,\n} 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 /**\n * The fee is paid with the ABR token.\n */\n WITH_ARB = \"abr\",\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 [FeePaymentMethod.WITH_ARB]?: 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 * Exchange rate\n */\n abrExchangeRate?: 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"]}
|
|
@@ -29,10 +29,12 @@ const algosdk_1 = __importStar(require("algosdk"));
|
|
|
29
29
|
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
30
30
|
const exceptions_1 = require("../../../exceptions");
|
|
31
31
|
const models_1 = require("../../../models");
|
|
32
|
+
const utils_1 = require("../../../utils/utils");
|
|
32
33
|
const BridgeClient_1 = require("../../models/alg/BridgeClient");
|
|
34
|
+
const PaddingUtilClient_1 = require("../../models/alg/PaddingUtilClient");
|
|
33
35
|
const alg_1 = require("../../utils/alg");
|
|
34
36
|
const models_2 = require("../models");
|
|
35
|
-
const
|
|
37
|
+
const utils_2 = require("../utils");
|
|
36
38
|
class AlgBridgeService extends models_2.ChainBridgeService {
|
|
37
39
|
algorand;
|
|
38
40
|
api;
|
|
@@ -47,67 +49,94 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
47
49
|
throw new exceptions_1.MethodNotSupportedError();
|
|
48
50
|
}
|
|
49
51
|
async buildRawTransactionSend(params) {
|
|
50
|
-
const txSendParams = await (0,
|
|
52
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
51
53
|
if (!params.sourceToken.bridgeId) {
|
|
52
54
|
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
53
55
|
}
|
|
56
|
+
if (!params.sourceToken.paddingUtilId) {
|
|
57
|
+
throw new exceptions_1.SdkError("ALG sourceToken must contain 'paddingUtilId'");
|
|
58
|
+
}
|
|
54
59
|
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
55
60
|
const bridge = this.getBridge(bridgeId);
|
|
61
|
+
const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);
|
|
62
|
+
const paddingUtil = this.getPaddingUtil(paddingUtilId);
|
|
56
63
|
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
57
64
|
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
58
65
|
const destinationChainId = txSendParams.toChainId;
|
|
59
66
|
const recipient = txSendParams.toAccountAddress;
|
|
60
67
|
const receiveToken = txSendParams.toTokenAddress;
|
|
61
|
-
const nonce = (0,
|
|
68
|
+
const nonce = (0, utils_2.getNonce)();
|
|
62
69
|
const amount = BigInt(txSendParams.amount);
|
|
63
70
|
let totalFee = BigInt(txSendParams.fee);
|
|
64
71
|
if (txSendParams.extraGas) {
|
|
65
72
|
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
66
73
|
}
|
|
67
|
-
const isPayWithStable = txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN;
|
|
68
74
|
const composer = this.algorand.newGroup();
|
|
69
|
-
|
|
70
|
-
if (isPayWithStable) {
|
|
71
|
-
feeTokenAmount = totalFee;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
composer.addPayment({
|
|
75
|
-
sender,
|
|
76
|
-
receiver: bridge.appAddress,
|
|
77
|
-
amount: amount_1.AlgoAmount.MicroAlgo(totalFee),
|
|
78
|
-
});
|
|
79
|
-
feeTokenAmount = 0n;
|
|
80
|
-
}
|
|
81
|
-
composer
|
|
82
|
-
.addAssetTransfer({
|
|
83
|
-
assetId: tokenId,
|
|
75
|
+
const assetTransferTx = await this.algorand.createTransaction.assetTransfer({
|
|
84
76
|
amount,
|
|
85
|
-
|
|
77
|
+
assetId: tokenId,
|
|
86
78
|
receiver: bridge.appAddress,
|
|
87
|
-
})
|
|
88
|
-
.addAppCallMethodCall(await bridge.params.swapAndBridge({
|
|
89
|
-
args: {
|
|
90
|
-
tokenId,
|
|
91
|
-
recipient,
|
|
92
|
-
destinationChainId,
|
|
93
|
-
receiveToken,
|
|
94
|
-
nonce,
|
|
95
|
-
feeTokenAmount,
|
|
96
|
-
},
|
|
97
79
|
sender,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
80
|
+
});
|
|
81
|
+
switch (txSendParams.gasFeePaymentMethod) {
|
|
82
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
83
|
+
const paymentTx = await this.algorand.createTransaction.payment({
|
|
84
|
+
amount: amount_1.AlgoAmount.MicroAlgo(totalFee),
|
|
85
|
+
receiver: bridge.appAddress,
|
|
86
|
+
sender,
|
|
87
|
+
});
|
|
88
|
+
composer.addAppCallMethodCall(await bridge.params.swapAndBridge({
|
|
89
|
+
args: {
|
|
90
|
+
paymentRef: paymentTx,
|
|
91
|
+
assetTransferRef: assetTransferTx,
|
|
92
|
+
recipient,
|
|
93
|
+
destinationChainId,
|
|
94
|
+
receiveToken,
|
|
95
|
+
nonce,
|
|
96
|
+
},
|
|
97
|
+
sender,
|
|
98
|
+
extraFee: (0, alg_1.feeForInner)(8),
|
|
99
|
+
}));
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
103
|
+
composer.addAppCallMethodCall(await bridge.params.swapAndBridgeWithStable({
|
|
104
|
+
args: {
|
|
105
|
+
assetTransferRef: assetTransferTx,
|
|
106
|
+
recipient,
|
|
107
|
+
destinationChainId,
|
|
108
|
+
receiveToken,
|
|
109
|
+
nonce,
|
|
110
|
+
feeTokenAmount: totalFee,
|
|
111
|
+
},
|
|
112
|
+
sender,
|
|
113
|
+
extraFee: (0, alg_1.feeForInner)(9),
|
|
114
|
+
}));
|
|
115
|
+
const paddingTx = await this.algorand.createTransaction.appCall({
|
|
116
|
+
appId: paddingUtil.appId,
|
|
117
|
+
sender,
|
|
118
|
+
note: "padding_1",
|
|
119
|
+
});
|
|
120
|
+
composer.addTransaction(paddingTx);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
124
|
+
throw new exceptions_1.SdkError("ALG bridge does not support ARB0 payment method");
|
|
125
|
+
default: {
|
|
126
|
+
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const paddingTx = await this.algorand.createTransaction.appCall({
|
|
130
|
+
appId: paddingUtil.appId,
|
|
103
131
|
sender,
|
|
104
|
-
|
|
132
|
+
note: "padding",
|
|
105
133
|
});
|
|
134
|
+
composer.addTransaction(paddingTx);
|
|
106
135
|
const { transactions } = await composer.buildTransactions();
|
|
107
136
|
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
108
137
|
}
|
|
109
138
|
async buildRawTransactionSwap(params) {
|
|
110
|
-
const txSwapParams = (0,
|
|
139
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
111
140
|
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
112
141
|
const recipient = params.toAccountAddress;
|
|
113
142
|
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
@@ -117,8 +146,13 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
117
146
|
if (!params.sourceToken.bridgeId) {
|
|
118
147
|
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
119
148
|
}
|
|
149
|
+
if (!params.sourceToken.paddingUtilId) {
|
|
150
|
+
throw new exceptions_1.SdkError("ALG sourceToken must contain 'paddingUtilId'");
|
|
151
|
+
}
|
|
120
152
|
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
121
153
|
const bridge = this.getBridge(bridgeId);
|
|
154
|
+
const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);
|
|
155
|
+
const paddingUtil = this.getPaddingUtil(paddingUtilId);
|
|
122
156
|
const composer = this.algorand.newGroup();
|
|
123
157
|
if (params.fromAccountAddress === recipient) {
|
|
124
158
|
const optIn = await (0, alg_1.checkAssetOptIn)(receiveTokenId, recipient, this.algorand);
|
|
@@ -126,29 +160,31 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
126
160
|
composer.addAssetOptIn({ sender: sender, assetId: receiveTokenId });
|
|
127
161
|
}
|
|
128
162
|
}
|
|
129
|
-
|
|
163
|
+
const assetTransfer = this.algorand.createTransaction.assetTransfer({
|
|
130
164
|
assetId: tokenId,
|
|
131
165
|
amount: amount,
|
|
132
166
|
sender,
|
|
133
167
|
receiver: bridge.appAddress,
|
|
134
168
|
});
|
|
135
169
|
composer.addAppCallMethodCall(await bridge.params.swap({
|
|
136
|
-
args: {
|
|
170
|
+
args: { assetTransferRef: assetTransfer, recipient, receiveAsset: receiveTokenId, receiveAmountMin },
|
|
137
171
|
sender,
|
|
138
172
|
extraFee: (0, alg_1.feeForInner)(4),
|
|
139
173
|
}));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
appId: bridgeId,
|
|
174
|
+
const paddingTx = await this.algorand.createTransaction.appCall({
|
|
175
|
+
appId: paddingUtil.appId,
|
|
143
176
|
sender,
|
|
144
|
-
count: 1,
|
|
145
177
|
});
|
|
178
|
+
composer.addTransaction(paddingTx);
|
|
146
179
|
const { transactions } = await composer.buildTransactions();
|
|
147
180
|
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
148
181
|
}
|
|
149
182
|
getBridge(appId) {
|
|
150
183
|
return this.algorand.client.getTypedAppClientById(BridgeClient_1.BridgeClient, { appId });
|
|
151
184
|
}
|
|
185
|
+
getPaddingUtil(appId) {
|
|
186
|
+
return this.algorand.client.getTypedAppClientById(PaddingUtilClient_1.PaddingUtilClient, { appId });
|
|
187
|
+
}
|
|
152
188
|
}
|
|
153
189
|
exports.AlgBridgeService = AlgBridgeService;
|
|
154
190
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/alg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2EAA4E;AAC5E,mDAA2C;AAC3C,6DAAwD;AAExD,oDAAwE;AACxE,4CAAmD;AAEnD,gEAA6D;AAC7D,yCAAqG;AACrG,sCAAuE;AACvE,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAI7C;IACA;IAJT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEzC,YACS,QAAwB,EACxB,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHD,aAAQ,GAAR,QAAQ,CAAgB;QACxB,QAAG,GAAH,GAAG,CAAqB;QAG/B,QAAQ,CAAC,gBAAgB,CACvB,iBAAO,CAAC,iCAAiC,CACvC,iBAAO,CAAC,mBAAmB,CACzB,+KAA+K,CAChL,CACF,CACF,CAAC;IACJ,CAAC;I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QAAQ,EAAE,MAAM,CAAC,UAAU;SAC5B,CAAC,CAAC;QACH,QAAQ,CAAC,oBAAoB,CAC3B,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE;YAC9D,MAAM;YACN,QAAQ,EAAE,IAAA,iBAAW,EAAC,CAAC,CAAC;SACzB,CAAC,CACH,CAAC;QACF,IAAA,oBAAc,EAAC;YACb,QAAQ;YACR,KAAK,EAAE,QAAQ;YACf,MAAM;YACN,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QAC5D,OAAO,IAAA,0BAAoB,EAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAEO,SAAS,CAAC,KAAa;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,2BAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AA1ID,4CA0IC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { AlgoAmount } from \"@algorandfoundation/algokit-utils/types/amount\";\nimport algosdk, { Address } from \"algosdk\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeClient } from \"../../models/alg/BridgeClient\";\nimport { addBudgetNoops, checkAssetOptIn, feeForInner, populateAndEncodeTxs } from \"../../utils/alg\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class AlgBridgeService extends ChainBridgeService {\n chainType: ChainType.ALG = ChainType.ALG;\n\n constructor(\n public algorand: AlgorandClient,\n public api: AllbridgeCoreClient\n ) {\n super();\n algorand.setDefaultSigner(\n algosdk.makeBasicAccountTransactionSigner(\n algosdk.mnemonicToSecretKey(\n \"tunnel gym elevator pulse motor evolve release orange culture make sister approve winter chair armor grocery distance festival tiger holiday dish wisdom region absorb secret\"\n )\n )\n );\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n const sender = Address.fromString(params.fromAccountAddress);\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const destinationChainId = txSendParams.toChainId;\n const recipient = txSendParams.toAccountAddress;\n const receiveToken = txSendParams.toTokenAddress;\n const nonce = getNonce();\n const amount = BigInt(txSendParams.amount);\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n const isPayWithStable = txSendParams.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN;\n\n const composer = this.algorand.newGroup();\n\n let feeTokenAmount: bigint;\n if (isPayWithStable) {\n feeTokenAmount = totalFee;\n } else {\n composer.addPayment({\n sender,\n receiver: bridge.appAddress,\n amount: AlgoAmount.MicroAlgo(totalFee),\n });\n feeTokenAmount = 0n;\n }\n composer\n .addAssetTransfer({\n assetId: tokenId,\n amount,\n sender,\n receiver: bridge.appAddress,\n })\n .addAppCallMethodCall(\n await bridge.params.swapAndBridge({\n args: {\n tokenId,\n recipient,\n destinationChainId,\n receiveToken,\n nonce,\n feeTokenAmount,\n },\n sender,\n extraFee: feeForInner(isPayWithStable ? 9 : 8),\n })\n );\n addBudgetNoops({\n composer,\n appId: bridgeId,\n sender,\n count: isPayWithStable ? 3 : 2,\n });\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n\n const sender = Address.fromString(params.fromAccountAddress);\n const recipient = params.toAccountAddress;\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const receiveTokenId = BigInt(params.destinationToken.tokenAddress);\n const receiveAmountMin = BigInt(txSwapParams.minimumReceiveAmount);\n const amount = BigInt(txSwapParams.amount);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n\n const composer = this.algorand.newGroup();\n\n if (params.fromAccountAddress === recipient) {\n const optIn = await checkAssetOptIn(receiveTokenId, recipient, this.algorand);\n if (!optIn) {\n composer.addAssetOptIn({ sender: sender, assetId: receiveTokenId });\n }\n }\n\n composer.addAssetTransfer({\n assetId: tokenId,\n amount: amount,\n sender,\n receiver: bridge.appAddress,\n });\n composer.addAppCallMethodCall(\n await bridge.params.swap({\n args: { tokenId, recipient, receiveTokenId, receiveAmountMin },\n sender,\n extraFee: feeForInner(4),\n })\n );\n addBudgetNoops({\n composer,\n appId: bridgeId,\n sender,\n count: 1,\n });\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n private getBridge(appId: bigint): BridgeClient {\n return this.algorand.client.getTypedAppClientById(BridgeClient, { appId });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/alg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2EAA4E;AAC5E,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;QACnC,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QAC5D,OAAO,IAAA,0BAAoB,EAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAEO,SAAS,CAAC,KAAa;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,2BAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEO,cAAc,CAAC,KAAa;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,qCAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;CACF;AAnLD,4CAmLC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { AlgoAmount } from \"@algorandfoundation/algokit-utils/types/amount\";\nimport algosdk, { Address } from \"algosdk\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeClient } from \"../../models/alg/BridgeClient\";\nimport { PaddingUtilClient } from \"../../models/alg/PaddingUtilClient\";\nimport { checkAssetOptIn, feeForInner, populateAndEncodeTxs } from \"../../utils/alg\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class AlgBridgeService extends ChainBridgeService {\n chainType: ChainType.ALG = ChainType.ALG;\n\n constructor(\n public algorand: AlgorandClient,\n public api: AllbridgeCoreClient\n ) {\n super();\n algorand.setDefaultSigner(\n algosdk.makeBasicAccountTransactionSigner(\n algosdk.mnemonicToSecretKey(\n \"tunnel gym elevator pulse motor evolve release orange culture make sister approve winter chair armor grocery distance festival tiger holiday dish wisdom region absorb secret\"\n )\n )\n );\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n if (!params.sourceToken.paddingUtilId) {\n throw new SdkError(\"ALG sourceToken must contain 'paddingUtilId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);\n const paddingUtil = this.getPaddingUtil(paddingUtilId);\n const sender = Address.fromString(params.fromAccountAddress);\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const destinationChainId = txSendParams.toChainId;\n const recipient = txSendParams.toAccountAddress;\n const receiveToken = txSendParams.toTokenAddress;\n const nonce = getNonce();\n const amount = BigInt(txSendParams.amount);\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n const composer = this.algorand.newGroup();\n\n const assetTransferTx = await this.algorand.createTransaction.assetTransfer({\n amount,\n assetId: tokenId,\n receiver: bridge.appAddress,\n sender,\n });\n\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n const paymentTx = await this.algorand.createTransaction.payment({\n amount: AlgoAmount.MicroAlgo(totalFee),\n receiver: bridge.appAddress,\n sender,\n });\n composer.addAppCallMethodCall(\n await bridge.params.swapAndBridge({\n args: {\n paymentRef: paymentTx,\n assetTransferRef: assetTransferTx,\n recipient,\n destinationChainId,\n receiveToken,\n nonce,\n },\n sender,\n extraFee: feeForInner(8),\n })\n );\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n composer.addAppCallMethodCall(\n await bridge.params.swapAndBridgeWithStable({\n args: {\n assetTransferRef: assetTransferTx,\n recipient,\n destinationChainId,\n receiveToken,\n nonce,\n feeTokenAmount: totalFee,\n },\n sender,\n extraFee: feeForInner(9),\n })\n );\n const paddingTx = await this.algorand.createTransaction.appCall({\n appId: paddingUtil.appId,\n sender,\n note: \"padding_1\",\n });\n composer.addTransaction(paddingTx);\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"ALG bridge does not support ARB0 payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const paddingTx = await this.algorand.createTransaction.appCall({\n appId: paddingUtil.appId,\n sender,\n note: \"padding\",\n });\n composer.addTransaction(paddingTx);\n\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n\n const sender = Address.fromString(params.fromAccountAddress);\n const recipient = params.toAccountAddress;\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const receiveTokenId = BigInt(params.destinationToken.tokenAddress);\n const receiveAmountMin = BigInt(txSwapParams.minimumReceiveAmount);\n const amount = BigInt(txSwapParams.amount);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n if (!params.sourceToken.paddingUtilId) {\n throw new SdkError(\"ALG sourceToken must contain 'paddingUtilId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);\n const paddingUtil = this.getPaddingUtil(paddingUtilId);\n\n const composer = this.algorand.newGroup();\n\n if (params.fromAccountAddress === recipient) {\n const optIn = await checkAssetOptIn(receiveTokenId, recipient, this.algorand);\n if (!optIn) {\n composer.addAssetOptIn({ sender: sender, assetId: receiveTokenId });\n }\n }\n\n const assetTransfer = this.algorand.createTransaction.assetTransfer({\n assetId: tokenId,\n amount: amount,\n sender,\n receiver: bridge.appAddress,\n });\n composer.addAppCallMethodCall(\n await bridge.params.swap({\n args: { assetTransferRef: assetTransfer, recipient, receiveAsset: receiveTokenId, receiveAmountMin },\n sender,\n extraFee: feeForInner(4),\n })\n );\n const paddingTx = await this.algorand.createTransaction.appCall({\n appId: paddingUtil.appId,\n sender,\n });\n composer.addTransaction(paddingTx);\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n private getBridge(appId: bigint): BridgeClient {\n return this.algorand.client.getTypedAppClientById(BridgeClient, { appId });\n }\n\n private getPaddingUtil(appId: bigint): PaddingUtilClient {\n return this.algorand.client.getTypedAppClientById(PaddingUtilClient, { appId });\n }\n}\n"]}
|
|
@@ -5,13 +5,17 @@ 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");
|
|
8
9
|
const models_1 = require("../../../models");
|
|
10
|
+
const calculation_1 = require("../../../utils/calculation");
|
|
11
|
+
const utils_1 = require("../../../utils/utils");
|
|
9
12
|
const Bridge_1 = __importDefault(require("../../models/abi/Bridge"));
|
|
10
13
|
const CctpBridge_1 = __importDefault(require("../../models/abi/CctpBridge"));
|
|
11
14
|
const OftBridge_1 = __importDefault(require("../../models/abi/OftBridge"));
|
|
15
|
+
const PayerWithAbr_1 = __importDefault(require("../../models/abi/PayerWithAbr"));
|
|
12
16
|
const get_cctp_sol_token_recipient_address_1 = require("../get-cctp-sol-token-recipient-address");
|
|
13
17
|
const models_2 = require("../models");
|
|
14
|
-
const
|
|
18
|
+
const utils_2 = require("../utils");
|
|
15
19
|
class EvmBridgeService extends models_2.ChainBridgeService {
|
|
16
20
|
web3;
|
|
17
21
|
api;
|
|
@@ -28,7 +32,7 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
28
32
|
return this.sendRawTransaction(rawTransaction);
|
|
29
33
|
}
|
|
30
34
|
async buildRawTransactionSwap(params) {
|
|
31
|
-
const txSwapParams = (0,
|
|
35
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
32
36
|
return await this.buildRawTransactionSwapFromParams(txSwapParams);
|
|
33
37
|
}
|
|
34
38
|
async buildRawTransactionSwapFromParams(params) {
|
|
@@ -42,15 +46,27 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
48
|
async buildRawTransactionSend(params) {
|
|
45
|
-
const txSendParams = await (0,
|
|
46
|
-
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toChainId, toAccountAddress, toTokenAddress, messenger, fee, gasFeePaymentMethod, extraGas, extraGasDest, } = txSendParams;
|
|
47
|
-
const nonce = "0x" + (0,
|
|
49
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
50
|
+
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toChainId, toAccountAddress, toTokenAddress, messenger, fee, gasFeePaymentMethod, extraGas, extraGasDest, abrExchangeRate, } = txSendParams;
|
|
51
|
+
const nonce = "0x" + (0, utils_2.getNonce)().toString("hex");
|
|
48
52
|
let sendMethod;
|
|
49
53
|
let value;
|
|
50
54
|
let totalFee = fee;
|
|
51
55
|
if (extraGas) {
|
|
52
56
|
totalFee = (0, big_js_1.Big)(totalFee).plus(extraGas).toFixed();
|
|
53
57
|
}
|
|
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
|
+
}
|
|
54
70
|
switch (messenger) {
|
|
55
71
|
case models_1.Messenger.CCTP:
|
|
56
72
|
case models_1.Messenger.CCTP_V2: {
|
|
@@ -69,17 +85,44 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
69
85
|
case models_1.Messenger.WORMHOLE:
|
|
70
86
|
{
|
|
71
87
|
const bridgeContract = this.getBridgeContract(contractAddress);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
switch (gasFeePaymentMethod) {
|
|
89
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
90
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
91
|
+
sendMethod = bridgeContract.methods.swapAndBridge(fromTokenAddress, amount, toAccountAddress, toChainId, toTokenAddress, nonce, messenger, 0);
|
|
92
|
+
value = totalFee;
|
|
93
|
+
break;
|
|
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
|
+
}
|
|
79
103
|
}
|
|
80
104
|
}
|
|
81
105
|
break;
|
|
82
106
|
}
|
|
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
|
+
}
|
|
83
126
|
return Promise.resolve({
|
|
84
127
|
from: fromAccountAddress,
|
|
85
128
|
to: contractAddress,
|
|
@@ -94,23 +137,39 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
94
137
|
let value;
|
|
95
138
|
if (params.destinationToken.chainType === models_1.ChainType.SOLANA) {
|
|
96
139
|
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));
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
switch (gasFeePaymentMethod) {
|
|
141
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
142
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
143
|
+
sendMethod = cctpBridgeContract.methods.bridgeWithWalletAddress(amount, recipient, toAccountAddress, toChainId, 0);
|
|
144
|
+
value = totalFee;
|
|
145
|
+
break;
|
|
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
|
+
}
|
|
104
155
|
}
|
|
105
156
|
}
|
|
106
157
|
else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
158
|
+
switch (gasFeePaymentMethod) {
|
|
159
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
160
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
161
|
+
sendMethod = cctpBridgeContract.methods.bridge(amount, toAccountAddress, toChainId, 0);
|
|
162
|
+
value = totalFee;
|
|
163
|
+
break;
|
|
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
|
+
}
|
|
114
173
|
}
|
|
115
174
|
}
|
|
116
175
|
return { sendMethod, value };
|
|
@@ -120,13 +179,21 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
120
179
|
const oftBridgeContract = this.getOftBridgeContract(contractAddress);
|
|
121
180
|
let sendMethod;
|
|
122
181
|
let value;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
182
|
+
switch (gasFeePaymentMethod) {
|
|
183
|
+
case models_1.FeePaymentMethod.WITH_ARB:
|
|
184
|
+
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
185
|
+
sendMethod = oftBridgeContract.methods.bridge(params.sourceToken.tokenAddress, amount, toAccountAddress, toChainId, 0, extraGasDest ?? "0", "10");
|
|
186
|
+
value = totalFee;
|
|
187
|
+
break;
|
|
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
|
+
}
|
|
130
197
|
}
|
|
131
198
|
return { sendMethod, value };
|
|
132
199
|
}
|
|
@@ -151,6 +218,9 @@ class EvmBridgeService extends models_2.ChainBridgeService {
|
|
|
151
218
|
getOftBridgeContract(contractAddress) {
|
|
152
219
|
return new this.web3.eth.Contract(OftBridge_1.default.abi, contractAddress);
|
|
153
220
|
}
|
|
221
|
+
getAbrPayerContract(contractAddress) {
|
|
222
|
+
return new this.web3.eth.Contract(PayerWithAbr_1.default.abi, contractAddress);
|
|
223
|
+
}
|
|
154
224
|
}
|
|
155
225
|
exports.EvmBridgeService = EvmBridgeService;
|
|
156
226
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/evm/index.ts"],"names":[],"mappings":";;;;;;AA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AW;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
|
+
{"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,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,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,GAAG,MAAM,CAAC;QAEX,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;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C,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;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,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 } from "../../index";
|
|
4
|
+
import { AllbridgeCoreSdkOptions, FeePaymentMethod } 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): string;
|
|
68
|
+
export declare function getSpender(token: TokenWithChainDetails, messenger?: Messenger, gasFeePaymentMethod?: FeePaymentMethod): string;
|
|
69
69
|
export declare function getChainBridgeService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): ChainBridgeService;
|