@allbridge/bridge-core-sdk 3.27.0-beta.1 → 3.27.0-beta.3
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 +2 -2
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +4 -4
- 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 +31 -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 +12 -2
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +6 -0
- 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.js +52 -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 +10 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +11 -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.js +23 -14
- package/dist/src/services/bridge/stx/index.js.map +1 -1
- 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.js +69 -8
- package/dist/src/services/bridge/utils.js.map +1 -1
- 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/token/index.js +2 -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/tokens-info/tokens-info.model.d.ts +17 -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 +1 -1
|
@@ -29,11 +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");
|
|
33
34
|
const PaddingUtilClient_1 = require("../../models/alg/PaddingUtilClient");
|
|
34
35
|
const alg_1 = require("../../utils/alg");
|
|
35
36
|
const models_2 = require("../models");
|
|
36
|
-
const
|
|
37
|
+
const utils_2 = require("../utils");
|
|
37
38
|
class AlgBridgeService extends models_2.ChainBridgeService {
|
|
38
39
|
algorand;
|
|
39
40
|
api;
|
|
@@ -48,7 +49,7 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
48
49
|
throw new exceptions_1.MethodNotSupportedError();
|
|
49
50
|
}
|
|
50
51
|
async buildRawTransactionSend(params) {
|
|
51
|
-
const txSendParams = await (0,
|
|
52
|
+
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
52
53
|
if (!params.sourceToken.bridgeId) {
|
|
53
54
|
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
54
55
|
}
|
|
@@ -64,13 +65,12 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
64
65
|
const destinationChainId = txSendParams.toChainId;
|
|
65
66
|
const recipient = txSendParams.toAccountAddress;
|
|
66
67
|
const receiveToken = txSendParams.toTokenAddress;
|
|
67
|
-
const nonce = (0,
|
|
68
|
+
const nonce = (0, utils_2.getNonce)();
|
|
68
69
|
const amount = BigInt(txSendParams.amount);
|
|
69
70
|
let totalFee = BigInt(txSendParams.fee);
|
|
70
71
|
if (txSendParams.extraGas) {
|
|
71
72
|
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
72
73
|
}
|
|
73
|
-
const isPayWithStable = txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN;
|
|
74
74
|
const composer = this.algorand.newGroup();
|
|
75
75
|
const assetTransferTx = await this.algorand.createTransaction.assetTransfer({
|
|
76
76
|
amount,
|
|
@@ -78,44 +78,53 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
78
78
|
receiver: bridge.appAddress,
|
|
79
79
|
sender,
|
|
80
80
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}
|
|
119
128
|
}
|
|
120
129
|
const paddingTx = await this.algorand.createTransaction.appCall({
|
|
121
130
|
appId: paddingUtil.appId,
|
|
@@ -127,7 +136,7 @@ class AlgBridgeService extends models_2.ChainBridgeService {
|
|
|
127
136
|
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
128
137
|
}
|
|
129
138
|
async buildRawTransactionSwap(params) {
|
|
130
|
-
const txSwapParams = (0,
|
|
139
|
+
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
131
140
|
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
132
141
|
const recipient = params.toAccountAddress;
|
|
133
142
|
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
@@ -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,0EAAuE;AACvE,yCAAqF;AACrF,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;IAED,IAAI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AAQ,CAAC,oBAAoB,CAC3B,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE;YACpG,MAAM;YACN,QAAQ,EAAE,IAAA,iBAAW,EAAC,CAAC,CAAC;SACzB,CAAC,CACH,CAAC;QACF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC;YAC9D,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,MAAM;SACP,CAAC,CAAC;QACH,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;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;AA1KD,4CA0KC","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 { 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 const isPayWithStable = txSendParams.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN;\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 if (isPayWithStable) {\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 } else {\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 }\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"]}
|
|
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;AACnD,gDAAmD;AAEnD,gEAA6D;AAC7D,0EAAuE;AACvE,yCAAqF;AACrF,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,C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C,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":";;;;;;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;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AC,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;A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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;
|
|
@@ -42,7 +42,7 @@ class DefaultBridgeService {
|
|
|
42
42
|
else {
|
|
43
43
|
params = a;
|
|
44
44
|
}
|
|
45
|
-
const spender = getSpender(params.token, params.messenger);
|
|
45
|
+
const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);
|
|
46
46
|
return await this.tokenService.getAllowance({ ...params, spender }, provider);
|
|
47
47
|
}
|
|
48
48
|
async checkAllowance(a, b) {
|
|
@@ -55,11 +55,11 @@ class DefaultBridgeService {
|
|
|
55
55
|
else {
|
|
56
56
|
params = a;
|
|
57
57
|
}
|
|
58
|
-
const spender = getSpender(params.token, params.messenger);
|
|
58
|
+
const spender = getSpender(params.token, params.messenger, params.gasFeePaymentMethod);
|
|
59
59
|
return this.tokenService.checkAllowance({ ...params, spender }, provider);
|
|
60
60
|
}
|
|
61
61
|
async approve(provider, approveData) {
|
|
62
|
-
const spender = getSpender(approveData.token, approveData.messenger);
|
|
62
|
+
const spender = getSpender(approveData.token, approveData.messenger, approveData.gasFeePaymentMethod);
|
|
63
63
|
return this.tokenService.approve(provider, { ...approveData, spender });
|
|
64
64
|
}
|
|
65
65
|
async send(provider, params) {
|
|
@@ -69,7 +69,13 @@ class DefaultBridgeService {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
exports.DefaultBridgeService = DefaultBridgeService;
|
|
72
|
-
function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE) {
|
|
72
|
+
function getSpender(token, messenger = core_api_model_1.Messenger.ALLBRIDGE, gasFeePaymentMethod = index_1.FeePaymentMethod.WITH_NATIVE_CURRENCY) {
|
|
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
|
+
}
|
|
73
79
|
switch (messenger) {
|
|
74
80
|
case core_api_model_1.Messenger.CCTP:
|
|
75
81
|
if (token.cctpAddress) {
|