@allbridge/bridge-core-sdk 3.27.0-beta.7 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +1 -6
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +1 -6
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -6
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +2 -12
- package/dist/src/chains/chain.enums.js +0 -10
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +0 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +0 -1
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +0 -33
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +2 -14
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +0 -1
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +4 -12
- package/dist/src/index.js +11 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +4 -12
- package/dist/src/models/index.js +0 -4
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +0 -1
- package/dist/src/services/bridge/evm/index.js +33 -103
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +4 -31
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +4 -13
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +28 -36
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/sui/index.js +138 -166
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +70 -98
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +1 -5
- package/dist/src/services/bridge/utils.js +23 -164
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +0 -21
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/sui/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
- package/dist/src/services/models/index.d.ts +5 -7
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/token/index.js +2 -23
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/services/token/models/token.model.d.ts +4 -4
- package/dist/src/services/token/models/token.model.js.map +1 -1
- package/dist/src/services/token/sui/index.js.map +1 -1
- package/dist/src/services/utils/trx/index.js.map +1 -1
- package/dist/src/services/yield/index.js +0 -8
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +0 -25
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/src/utils/index.js +0 -3
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/utils.d.ts +0 -2
- package/dist/src/utils/utils.js +0 -11
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +2 -9
- package/dist/src/services/bridge/alg/index.d.ts +0 -16
- package/dist/src/services/bridge/alg/index.js +0 -191
- package/dist/src/services/bridge/alg/index.js.map +0 -1
- package/dist/src/services/bridge/stx/index.d.ts +0 -16
- package/dist/src/services/bridge/stx/index.js +0 -136
- package/dist/src/services/bridge/stx/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/alg/index.d.ts +0 -19
- package/dist/src/services/liquidity-pool/alg/index.js +0 -135
- package/dist/src/services/liquidity-pool/alg/index.js.map +0 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +0 -21
- package/dist/src/services/liquidity-pool/stx/index.js +0 -141
- package/dist/src/services/liquidity-pool/stx/index.js.map +0 -1
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +0 -203
- package/dist/src/services/models/abi/PayerWithAbr.js +0 -266
- package/dist/src/services/models/abi/PayerWithAbr.js.map +0 -1
- package/dist/src/services/models/alg/BridgeClient.d.ts +0 -2751
- package/dist/src/services/models/alg/BridgeClient.js +0 -2685
- package/dist/src/services/models/alg/BridgeClient.js.map +0 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +0 -654
- package/dist/src/services/models/alg/PaddingUtilClient.js +0 -425
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +0 -1
- package/dist/src/services/models/alg/PoolClient.d.ts +0 -2276
- package/dist/src/services/models/alg/PoolClient.js +0 -2195
- package/dist/src/services/models/alg/PoolClient.js.map +0 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +0 -657
- package/dist/src/services/models/stx/clarigen-types.js +0 -2296
- package/dist/src/services/models/stx/clarigen-types.js.map +0 -1
- package/dist/src/services/token/alg/index.d.ts +0 -17
- package/dist/src/services/token/alg/index.js +0 -47
- package/dist/src/services/token/alg/index.js.map +0 -1
- package/dist/src/services/token/stx/index.d.ts +0 -20
- package/dist/src/services/token/stx/index.js +0 -59
- package/dist/src/services/token/stx/index.js.map +0 -1
- package/dist/src/services/utils/alg/index.d.ts +0 -9
- package/dist/src/services/utils/alg/index.js +0 -74
- package/dist/src/services/utils/alg/index.js.map +0 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +0 -2
- package/dist/src/services/utils/stx/get-token-name.js +0 -15
- package/dist/src/services/utils/stx/get-token-name.js.map +0 -1
- package/dist/src/services/utils/stx/post-conditions.d.ts +0 -3
- package/dist/src/services/utils/stx/post-conditions.js +0 -27
- package/dist/src/services/utils/stx/post-conditions.js.map +0 -1
- package/dist/src/utils/alg/index.d.ts +0 -21
- package/dist/src/utils/alg/index.js +0 -71
- package/dist/src/utils/alg/index.js.map +0 -1
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.AlgBridgeService = void 0;
|
|
27
|
-
const amount_1 = require("@algorandfoundation/algokit-utils/types/amount");
|
|
28
|
-
const algosdk_1 = __importStar(require("algosdk"));
|
|
29
|
-
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
30
|
-
const exceptions_1 = require("../../../exceptions");
|
|
31
|
-
const models_1 = require("../../../models");
|
|
32
|
-
const utils_1 = require("../../../utils/utils");
|
|
33
|
-
const BridgeClient_1 = require("../../models/alg/BridgeClient");
|
|
34
|
-
const PaddingUtilClient_1 = require("../../models/alg/PaddingUtilClient");
|
|
35
|
-
const alg_1 = require("../../utils/alg");
|
|
36
|
-
const models_2 = require("../models");
|
|
37
|
-
const utils_2 = require("../utils");
|
|
38
|
-
class AlgBridgeService extends models_2.ChainBridgeService {
|
|
39
|
-
algorand;
|
|
40
|
-
api;
|
|
41
|
-
chainType = chain_enums_1.ChainType.ALG;
|
|
42
|
-
constructor(algorand, api) {
|
|
43
|
-
super();
|
|
44
|
-
this.algorand = algorand;
|
|
45
|
-
this.api = api;
|
|
46
|
-
algorand.setDefaultSigner(algosdk_1.default.makeBasicAccountTransactionSigner(algosdk_1.default.mnemonicToSecretKey("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")));
|
|
47
|
-
algorand.setDefaultValidityWindow(100);
|
|
48
|
-
}
|
|
49
|
-
send(_params) {
|
|
50
|
-
throw new exceptions_1.MethodNotSupportedError();
|
|
51
|
-
}
|
|
52
|
-
async buildRawTransactionSend(params) {
|
|
53
|
-
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
54
|
-
if (!params.sourceToken.bridgeId) {
|
|
55
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
56
|
-
}
|
|
57
|
-
if (!params.sourceToken.paddingUtilId) {
|
|
58
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'paddingUtilId'");
|
|
59
|
-
}
|
|
60
|
-
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
61
|
-
const bridge = this.getBridge(bridgeId);
|
|
62
|
-
const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);
|
|
63
|
-
const paddingUtil = this.getPaddingUtil(paddingUtilId);
|
|
64
|
-
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
65
|
-
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
66
|
-
const destinationChainId = txSendParams.toChainId;
|
|
67
|
-
const recipient = txSendParams.toAccountAddress;
|
|
68
|
-
const receiveToken = txSendParams.toTokenAddress;
|
|
69
|
-
const nonce = (0, utils_2.getNonce)();
|
|
70
|
-
const amount = BigInt(txSendParams.amount);
|
|
71
|
-
let totalFee = BigInt(txSendParams.fee);
|
|
72
|
-
if (txSendParams.extraGas) {
|
|
73
|
-
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
74
|
-
}
|
|
75
|
-
const composer = this.algorand.newGroup();
|
|
76
|
-
const assetTransferTx = await this.algorand.createTransaction.assetTransfer({
|
|
77
|
-
amount,
|
|
78
|
-
assetId: tokenId,
|
|
79
|
-
receiver: bridge.appAddress,
|
|
80
|
-
sender,
|
|
81
|
-
});
|
|
82
|
-
switch (txSendParams.gasFeePaymentMethod) {
|
|
83
|
-
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
84
|
-
const paymentTx = await this.algorand.createTransaction.payment({
|
|
85
|
-
amount: amount_1.AlgoAmount.MicroAlgo(totalFee),
|
|
86
|
-
receiver: bridge.appAddress,
|
|
87
|
-
sender,
|
|
88
|
-
});
|
|
89
|
-
composer.addAppCallMethodCall(await bridge.params.swapAndBridge({
|
|
90
|
-
args: {
|
|
91
|
-
paymentRef: paymentTx,
|
|
92
|
-
assetTransferRef: assetTransferTx,
|
|
93
|
-
recipient,
|
|
94
|
-
destinationChainId,
|
|
95
|
-
receiveToken,
|
|
96
|
-
nonce,
|
|
97
|
-
},
|
|
98
|
-
sender,
|
|
99
|
-
extraFee: (0, alg_1.feeForInner)(8),
|
|
100
|
-
}));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
104
|
-
composer.addAppCallMethodCall(await bridge.params.swapAndBridgeWithStable({
|
|
105
|
-
args: {
|
|
106
|
-
assetTransferRef: assetTransferTx,
|
|
107
|
-
recipient,
|
|
108
|
-
destinationChainId,
|
|
109
|
-
receiveToken,
|
|
110
|
-
nonce,
|
|
111
|
-
feeTokenAmount: totalFee,
|
|
112
|
-
},
|
|
113
|
-
sender,
|
|
114
|
-
extraFee: (0, alg_1.feeForInner)(9),
|
|
115
|
-
}));
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
119
|
-
throw new exceptions_1.SdkError("ALG bridge does not support ARB0 payment method");
|
|
120
|
-
default: {
|
|
121
|
-
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const paddingTx1 = await this.algorand.createTransaction.appCall({
|
|
125
|
-
appId: paddingUtil.appId,
|
|
126
|
-
sender,
|
|
127
|
-
note: "padding1",
|
|
128
|
-
});
|
|
129
|
-
composer.addTransaction(paddingTx1);
|
|
130
|
-
const paddingTx2 = await this.algorand.createTransaction.appCall({
|
|
131
|
-
appId: paddingUtil.appId,
|
|
132
|
-
sender,
|
|
133
|
-
note: "padding2",
|
|
134
|
-
});
|
|
135
|
-
composer.addTransaction(paddingTx2);
|
|
136
|
-
const { transactions } = await composer.buildTransactions();
|
|
137
|
-
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
138
|
-
}
|
|
139
|
-
async buildRawTransactionSwap(params) {
|
|
140
|
-
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
141
|
-
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
142
|
-
const recipient = params.toAccountAddress;
|
|
143
|
-
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
144
|
-
const receiveTokenId = BigInt(params.destinationToken.tokenAddress);
|
|
145
|
-
const receiveAmountMin = BigInt(txSwapParams.minimumReceiveAmount);
|
|
146
|
-
const amount = BigInt(txSwapParams.amount);
|
|
147
|
-
if (!params.sourceToken.bridgeId) {
|
|
148
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
149
|
-
}
|
|
150
|
-
if (!params.sourceToken.paddingUtilId) {
|
|
151
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'paddingUtilId'");
|
|
152
|
-
}
|
|
153
|
-
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
154
|
-
const bridge = this.getBridge(bridgeId);
|
|
155
|
-
const paddingUtilId = BigInt(params.sourceToken.paddingUtilId);
|
|
156
|
-
const paddingUtil = this.getPaddingUtil(paddingUtilId);
|
|
157
|
-
const composer = this.algorand.newGroup();
|
|
158
|
-
if (params.fromAccountAddress === recipient) {
|
|
159
|
-
const optIn = await (0, alg_1.checkAssetOptIn)(receiveTokenId, recipient, this.algorand);
|
|
160
|
-
if (!optIn) {
|
|
161
|
-
composer.addAssetOptIn({ sender: sender, assetId: receiveTokenId });
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const assetTransfer = this.algorand.createTransaction.assetTransfer({
|
|
165
|
-
assetId: tokenId,
|
|
166
|
-
amount: amount,
|
|
167
|
-
sender,
|
|
168
|
-
receiver: bridge.appAddress,
|
|
169
|
-
});
|
|
170
|
-
composer.addAppCallMethodCall(await bridge.params.swap({
|
|
171
|
-
args: { assetTransferRef: assetTransfer, recipient, receiveAsset: receiveTokenId, receiveAmountMin },
|
|
172
|
-
sender,
|
|
173
|
-
extraFee: (0, alg_1.feeForInner)(4),
|
|
174
|
-
}));
|
|
175
|
-
const paddingTx = await this.algorand.createTransaction.appCall({
|
|
176
|
-
appId: paddingUtil.appId,
|
|
177
|
-
sender,
|
|
178
|
-
});
|
|
179
|
-
composer.addTransaction(paddingTx);
|
|
180
|
-
const { transactions } = await composer.buildTransactions();
|
|
181
|
-
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
182
|
-
}
|
|
183
|
-
getBridge(appId) {
|
|
184
|
-
return this.algorand.client.getTypedAppClientById(BridgeClient_1.BridgeClient, { appId });
|
|
185
|
-
}
|
|
186
|
-
getPaddingUtil(appId) {
|
|
187
|
-
return this.algorand.client.getTypedAppClientById(PaddingUtilClient_1.PaddingUtilClient, { appId });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.AlgBridgeService = AlgBridgeService;
|
|
191
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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;QACF,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,OAAmB;QACtB,MAAM,IAAI,oCAAuB,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,IAAA,2BAAmB,EAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjF,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EA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QAAQ,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;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 algorand.setDefaultValidityWindow(100);\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 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 const paddingTx1 = await this.algorand.createTransaction.appCall({\n appId: paddingUtil.appId,\n sender,\n note: \"padding1\",\n });\n composer.addTransaction(paddingTx1);\n const paddingTx2 = await this.algorand.createTransaction.appCall({\n appId: paddingUtil.appId,\n sender,\n note: \"padding2\",\n });\n composer.addTransaction(paddingTx2);\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,16 +0,0 @@
|
|
|
1
|
-
import { ChainType } from "../../../chains/chain.enums";
|
|
2
|
-
import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
|
|
3
|
-
import { AllbridgeCoreSdkOptions } from "../../../index";
|
|
4
|
-
import { RawStxTransaction, TransactionResponse } from "../../models";
|
|
5
|
-
import { ChainBridgeService, SendParams, SwapParams } from "../models";
|
|
6
|
-
export declare class StxBridgeService extends ChainBridgeService {
|
|
7
|
-
nodeRpcUrl: string;
|
|
8
|
-
params: AllbridgeCoreSdkOptions;
|
|
9
|
-
api: AllbridgeCoreClient;
|
|
10
|
-
chainType: ChainType.STX;
|
|
11
|
-
private client;
|
|
12
|
-
constructor(nodeRpcUrl: string, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
|
|
13
|
-
send(_params: SendParams): Promise<TransactionResponse>;
|
|
14
|
-
buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction>;
|
|
15
|
-
buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction>;
|
|
16
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StxBridgeService = void 0;
|
|
4
|
-
const core_1 = require("@clarigen/core");
|
|
5
|
-
const network_1 = require("@stacks/network");
|
|
6
|
-
const transactions_1 = require("@stacks/transactions");
|
|
7
|
-
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
8
|
-
const exceptions_1 = require("../../../exceptions");
|
|
9
|
-
const models_1 = require("../../../models");
|
|
10
|
-
const utils_1 = require("../../../utils/utils");
|
|
11
|
-
const clarigen_types_1 = require("../../models/stx/clarigen-types");
|
|
12
|
-
const get_token_name_1 = require("../../utils/stx/get-token-name");
|
|
13
|
-
const post_conditions_1 = require("../../utils/stx/post-conditions");
|
|
14
|
-
const models_2 = require("../models");
|
|
15
|
-
const utils_2 = require("../utils");
|
|
16
|
-
class StxBridgeService extends models_2.ChainBridgeService {
|
|
17
|
-
nodeRpcUrl;
|
|
18
|
-
params;
|
|
19
|
-
api;
|
|
20
|
-
chainType = chain_enums_1.ChainType.STX;
|
|
21
|
-
client;
|
|
22
|
-
constructor(nodeRpcUrl, params, api) {
|
|
23
|
-
super();
|
|
24
|
-
this.nodeRpcUrl = nodeRpcUrl;
|
|
25
|
-
this.params = params;
|
|
26
|
-
this.api = api;
|
|
27
|
-
const network = (0, network_1.createNetwork)({
|
|
28
|
-
network: this.params.stxIsTestnet ? "testnet" : "mainnet",
|
|
29
|
-
client: { baseUrl: this.nodeRpcUrl },
|
|
30
|
-
apiKey: this.params.stxHeroApiKey,
|
|
31
|
-
});
|
|
32
|
-
this.client = new core_1.ClarigenClient(network, this.params.stxHeroApiKey);
|
|
33
|
-
}
|
|
34
|
-
send(_params) {
|
|
35
|
-
throw new exceptions_1.MethodNotSupportedError();
|
|
36
|
-
}
|
|
37
|
-
async buildRawTransactionSend(params) {
|
|
38
|
-
const txSendParams = await (0, utils_2.prepareTxSendParams)(this.chainType, params, this.api);
|
|
39
|
-
const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;
|
|
40
|
-
const amount = BigInt(txSendParams.amount);
|
|
41
|
-
const postFungiblePostCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
|
|
42
|
-
const postStxPostCondition = (0, post_conditions_1.getStxPostCondition)(0, "gte", params.sourceToken.bridgeAddress);
|
|
43
|
-
const postConditions = [postFungiblePostCondition, postStxPostCondition];
|
|
44
|
-
let totalFee = BigInt(txSendParams.fee);
|
|
45
|
-
if (txSendParams.extraGas) {
|
|
46
|
-
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
47
|
-
}
|
|
48
|
-
let feeTokenAmount;
|
|
49
|
-
let feeNativeAmount;
|
|
50
|
-
switch (txSendParams.gasFeePaymentMethod) {
|
|
51
|
-
case models_1.FeePaymentMethod.WITH_NATIVE_CURRENCY: {
|
|
52
|
-
feeTokenAmount = 0n;
|
|
53
|
-
feeNativeAmount = totalFee;
|
|
54
|
-
const postUserStxPostCondition = (0, post_conditions_1.getStxPostCondition)(totalFee, "lte", params.fromAccountAddress);
|
|
55
|
-
postConditions.push(postUserStxPostCondition);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case models_1.FeePaymentMethod.WITH_STABLECOIN: {
|
|
59
|
-
feeTokenAmount = totalFee;
|
|
60
|
-
feeNativeAmount = 0n;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case models_1.FeePaymentMethod.WITH_ARB:
|
|
64
|
-
throw new exceptions_1.SdkError("STX bridge does not support ARB0 payment method");
|
|
65
|
-
default: {
|
|
66
|
-
return (0, utils_1.assertNever)(txSendParams.gasFeePaymentMethod, "Unhandled FeePaymentMethod");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const [contractPrincipal] = (0, transactions_1.parseContractId)(bridgeAddress);
|
|
70
|
-
const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
|
|
71
|
-
const { contractAddress, contractName, functionName, functionArgs } = bridge.swapAndBridge({
|
|
72
|
-
ftRef: params.sourceToken.tokenAddress,
|
|
73
|
-
poolRef: params.sourceToken.poolAddress,
|
|
74
|
-
messengerRef: `${contractPrincipal}.messenger`,
|
|
75
|
-
gasOracleRef: `${contractPrincipal}.gas-oracle`,
|
|
76
|
-
amount,
|
|
77
|
-
recipient: Uint8Array.from(toAccountAddress),
|
|
78
|
-
destinationChainId: toChainId,
|
|
79
|
-
receiveToken: Uint8Array.from(toTokenAddress),
|
|
80
|
-
nonce: Uint8Array.from((0, utils_2.getNonce)()),
|
|
81
|
-
messengerId: messenger,
|
|
82
|
-
feeNativeAmount: feeNativeAmount,
|
|
83
|
-
feeTokenAmount: feeTokenAmount,
|
|
84
|
-
});
|
|
85
|
-
const privateKey = (0, transactions_1.makeRandomPrivKey)();
|
|
86
|
-
const publicKey = (0, transactions_1.privateKeyToPublic)(privateKey);
|
|
87
|
-
const txOptions = {
|
|
88
|
-
contractAddress,
|
|
89
|
-
contractName,
|
|
90
|
-
functionName,
|
|
91
|
-
functionArgs,
|
|
92
|
-
publicKey,
|
|
93
|
-
validateWithAbi: true,
|
|
94
|
-
network: this.client.network,
|
|
95
|
-
postConditions,
|
|
96
|
-
postConditionMode: transactions_1.PostConditionMode.Deny,
|
|
97
|
-
};
|
|
98
|
-
const transaction = await (0, transactions_1.makeUnsignedContractCall)(txOptions);
|
|
99
|
-
return transaction.serialize();
|
|
100
|
-
}
|
|
101
|
-
async buildRawTransactionSwap(params) {
|
|
102
|
-
const txSwapParams = (0, utils_2.prepareTxSwapParams)(this.chainType, params);
|
|
103
|
-
const amount = BigInt(txSwapParams.amount);
|
|
104
|
-
const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);
|
|
105
|
-
const bridgeAddress = params.sourceToken.bridgeAddress;
|
|
106
|
-
const bridge = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.bridge, bridgeAddress);
|
|
107
|
-
const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({
|
|
108
|
-
amount,
|
|
109
|
-
sendPoolRef: params.sourceToken.poolAddress,
|
|
110
|
-
sendFtRef: params.sourceToken.tokenAddress,
|
|
111
|
-
receivePoolRef: params.destinationToken.poolAddress,
|
|
112
|
-
receiveFtRef: params.destinationToken.tokenAddress,
|
|
113
|
-
recipient: params.toAccountAddress,
|
|
114
|
-
receiveAmountMin: minimumReceiveAmount,
|
|
115
|
-
});
|
|
116
|
-
const privateKey = (0, transactions_1.makeRandomPrivKey)();
|
|
117
|
-
const publicKey = (0, transactions_1.privateKeyToPublic)(privateKey);
|
|
118
|
-
const postFungibleCondition = (0, post_conditions_1.getFungiblePostCondition)(amount, "lte", params.fromAccountAddress, params.sourceToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.sourceToken));
|
|
119
|
-
const postFungibleMinReceiveCondition = (0, post_conditions_1.getFungiblePostCondition)(minimumReceiveAmount, "gte", params.destinationToken.poolAddress, params.destinationToken.tokenAddress, (0, get_token_name_1.getTokenName)(params.destinationToken));
|
|
120
|
-
const txOptions = {
|
|
121
|
-
contractAddress,
|
|
122
|
-
contractName,
|
|
123
|
-
functionName,
|
|
124
|
-
functionArgs,
|
|
125
|
-
publicKey,
|
|
126
|
-
validateWithAbi: true,
|
|
127
|
-
network: this.client.network,
|
|
128
|
-
postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],
|
|
129
|
-
postConditionMode: transactions_1.PostConditionMode.Deny,
|
|
130
|
-
};
|
|
131
|
-
const transaction = await (0, transactions_1.makeUnsignedContractCall)(txOptions);
|
|
132
|
-
return transaction.serialize();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.StxBridgeService = StxBridgeService;
|
|
136
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/stx/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,6CAAgD;AAChD,uDAQ8B;AAC9B,6DAAwD;AAExD,oDAAwE;AAExE,4CAAmD;AACnD,gDAAmD;AAEnD,oEAA+E;AAC/E,mEAA8D;AAC9D,qEAAgG;AAChG,sCAAuE;AACvE,oCAA8E;AAE9E,MAAa,gBAAiB,SAAQ,2BAAkB;IAM7C;IACA;IACA;IAPT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEjC,MAAM,CAAiB;IAE/B,YACS,UAAkB,EAClB,MAA+B,EAC/B,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;QAG/B,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACzD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;SAClC,CAAC,CAAC;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AAC,gBAAgB,CAAC,WAAW;YACnD,YAAY,EAAE,MAAM,CAAC,gBAAgB,CAAC,YAAY;YAClD,SAAS,EAAE,MAAM,CAAC,gBAAgB;YAClC,gBAAgB,EAAE,oBAAoB;SACvC,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,IAAA,gCAAiB,GAAE,CAAC;QACvC,MAAM,SAAS,GAAG,IAAA,iCAAkB,EAAC,UAAU,CAAC,CAAC;QAEjD,MAAM,qBAAqB,GAAG,IAAA,0CAAwB,EACpD,MAAM,EACN,KAAK,EACL,MAAM,CAAC,kBAAkB,EACzB,MAAM,CAAC,WAAW,CAAC,YAAY,EAC/B,IAAA,6BAAY,EAAC,MAAM,CAAC,WAAW,CAAC,CACjC,CAAC;QAEF,MAAM,+BAA+B,GAAG,IAAA,0CAAwB,EAC9D,oBAAoB,EACpB,KAAK,EACL,MAAM,CAAC,gBAAgB,CAAC,WAAW,EACnC,MAAM,CAAC,gBAAgB,CAAC,YAAY,EACpC,IAAA,6BAAY,EAAC,MAAM,CAAC,gBAAgB,CAAC,CACtC,CAAC;QAEF,MAAM,SAAS,GAAG;YAChB,eAAe;YACf,YAAY;YACZ,YAAY;YACZ,YAAY;YACZ,SAAS;YACT,eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,cAAc,EAAE,CAAC,qBAAqB,EAAE,+BAA+B,CAAC;YACxE,iBAAiB,EAAE,gCAAiB,CAAC,IAAI;SAC1C,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,IAAA,uCAAwB,EAAC,SAAS,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;CACF;AAvJD,4CAuJC","sourcesContent":["import { ClarigenClient, contractFactory } from \"@clarigen/core\";\nimport { createNetwork } from \"@stacks/network\";\nimport {\n ContractIdString,\n makeRandomPrivKey,\n makeUnsignedContractCall,\n parseContractId,\n PostCondition,\n PostConditionMode,\n privateKeyToPublic,\n} from \"@stacks/transactions\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { RawStxTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport { getTokenName } from \"../../utils/stx/get-token-name\";\nimport { getFungiblePostCondition, getStxPostCondition } from \"../../utils/stx/post-conditions\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class StxBridgeService extends ChainBridgeService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawStxTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n const { contractAddress: bridgeAddress, messenger, toChainId, toAccountAddress, toTokenAddress } = txSendParams;\n const amount = BigInt(txSendParams.amount);\n\n const postFungiblePostCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n const postStxPostCondition = getStxPostCondition(0, \"gte\", params.sourceToken.bridgeAddress);\n const postConditions: PostCondition[] = [postFungiblePostCondition, postStxPostCondition];\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n\n let feeTokenAmount: bigint;\n let feeNativeAmount: bigint;\n switch (txSendParams.gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY: {\n feeTokenAmount = 0n;\n feeNativeAmount = totalFee;\n const postUserStxPostCondition = getStxPostCondition(totalFee, \"lte\", params.fromAccountAddress);\n postConditions.push(postUserStxPostCondition);\n break;\n }\n case FeePaymentMethod.WITH_STABLECOIN: {\n feeTokenAmount = totalFee;\n feeNativeAmount = 0n;\n break;\n }\n case FeePaymentMethod.WITH_ARB:\n throw new SdkError(\"STX bridge does not support ARB0 payment method\");\n default: {\n return assertNever(txSendParams.gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n const [contractPrincipal] = parseContractId(bridgeAddress as ContractIdString);\n\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swapAndBridge({\n ftRef: params.sourceToken.tokenAddress,\n poolRef: params.sourceToken.poolAddress,\n messengerRef: `${contractPrincipal}.messenger`,\n gasOracleRef: `${contractPrincipal}.gas-oracle`,\n amount,\n recipient: Uint8Array.from(toAccountAddress),\n destinationChainId: toChainId,\n receiveToken: Uint8Array.from(toTokenAddress),\n nonce: Uint8Array.from(getNonce()),\n messengerId: messenger,\n feeNativeAmount: feeNativeAmount,\n feeTokenAmount: feeTokenAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions,\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawStxTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n const amount = BigInt(txSwapParams.amount);\n const minimumReceiveAmount = BigInt(txSwapParams.minimumReceiveAmount);\n\n const bridgeAddress = params.sourceToken.bridgeAddress;\n const bridge = contractFactory(contracts.bridge, bridgeAddress);\n const { contractAddress, contractName, functionName, functionArgs } = bridge.swap({\n amount,\n sendPoolRef: params.sourceToken.poolAddress,\n sendFtRef: params.sourceToken.tokenAddress,\n receivePoolRef: params.destinationToken.poolAddress,\n receiveFtRef: params.destinationToken.tokenAddress,\n recipient: params.toAccountAddress,\n receiveAmountMin: minimumReceiveAmount,\n });\n\n const privateKey = makeRandomPrivKey();\n const publicKey = privateKeyToPublic(privateKey);\n\n const postFungibleCondition = getFungiblePostCondition(\n amount,\n \"lte\",\n params.fromAccountAddress,\n params.sourceToken.tokenAddress,\n getTokenName(params.sourceToken)\n );\n\n const postFungibleMinReceiveCondition = getFungiblePostCondition(\n minimumReceiveAmount,\n \"gte\",\n params.destinationToken.poolAddress,\n params.destinationToken.tokenAddress,\n getTokenName(params.destinationToken)\n );\n\n const txOptions = {\n contractAddress,\n contractName,\n functionName,\n functionArgs,\n publicKey,\n validateWithAbi: true,\n network: this.client.network,\n postConditions: [postFungibleCondition, postFungibleMinReceiveCondition],\n postConditionMode: PostConditionMode.Deny,\n };\n const transaction = await makeUnsignedContractCall(txOptions);\n return transaction.serialize();\n }\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AlgorandClient } from "@algorandfoundation/algokit-utils";
|
|
2
|
-
import { ChainType } from "../../../chains/chain.enums";
|
|
3
|
-
import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
|
|
4
|
-
import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
|
|
5
|
-
import { RawTransaction } from "../../models";
|
|
6
|
-
import { ChainPoolService, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "../models";
|
|
7
|
-
export declare class AlgPoolService extends ChainPoolService {
|
|
8
|
-
algorand: AlgorandClient;
|
|
9
|
-
api: AllbridgeCoreClient;
|
|
10
|
-
chainType: ChainType.ALG;
|
|
11
|
-
private P;
|
|
12
|
-
constructor(algorand: AlgorandClient, api: AllbridgeCoreClient);
|
|
13
|
-
buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction>;
|
|
14
|
-
buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;
|
|
15
|
-
buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;
|
|
16
|
-
getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo>;
|
|
17
|
-
getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo>;
|
|
18
|
-
private getPool;
|
|
19
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlgPoolService = void 0;
|
|
4
|
-
const algosdk_1 = require("algosdk");
|
|
5
|
-
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
6
|
-
const exceptions_1 = require("../../../exceptions");
|
|
7
|
-
const calculation_1 = require("../../../utils/calculation");
|
|
8
|
-
const PoolClient_1 = require("../../models/alg/PoolClient");
|
|
9
|
-
const alg_1 = require("../../utils/alg");
|
|
10
|
-
const models_1 = require("../models");
|
|
11
|
-
class AlgPoolService extends models_1.ChainPoolService {
|
|
12
|
-
algorand;
|
|
13
|
-
api;
|
|
14
|
-
chainType = chain_enums_1.ChainType.ALG;
|
|
15
|
-
P = 48;
|
|
16
|
-
constructor(algorand, api) {
|
|
17
|
-
super();
|
|
18
|
-
this.algorand = algorand;
|
|
19
|
-
this.api = api;
|
|
20
|
-
algorand.setDefaultValidityWindow(100);
|
|
21
|
-
}
|
|
22
|
-
async buildRawTransactionClaimRewards(params) {
|
|
23
|
-
const userAccount = params.accountAddress;
|
|
24
|
-
const assetId = BigInt(params.token.tokenAddress);
|
|
25
|
-
const poolId = BigInt(params.token.poolAddress);
|
|
26
|
-
const pool = this.getPool(poolId);
|
|
27
|
-
const composer = this.algorand.newGroup();
|
|
28
|
-
composer.addAppCallMethodCall(await pool.params.claimRewards({
|
|
29
|
-
args: [],
|
|
30
|
-
sender: userAccount,
|
|
31
|
-
extraFee: (0, alg_1.feeForInner)(1),
|
|
32
|
-
assetReferences: [assetId],
|
|
33
|
-
}));
|
|
34
|
-
let { transactions } = await composer.buildTransactions();
|
|
35
|
-
transactions = (0, algosdk_1.assignGroupID)(transactions);
|
|
36
|
-
return (0, alg_1.encodeTxs)(...transactions);
|
|
37
|
-
}
|
|
38
|
-
async buildRawTransactionDeposit(params) {
|
|
39
|
-
const userAccount = params.accountAddress;
|
|
40
|
-
const amount = BigInt(params.amount);
|
|
41
|
-
const assetId = BigInt(params.token.tokenAddress);
|
|
42
|
-
const poolId = BigInt(params.token.poolAddress);
|
|
43
|
-
const pool = this.getPool(poolId);
|
|
44
|
-
const isOptedIn = await (0, alg_1.checkAppOptIn)(poolId, userAccount, this.algorand);
|
|
45
|
-
const onComplete = isOptedIn
|
|
46
|
-
? algosdk_1.OnApplicationComplete.NoOpOC
|
|
47
|
-
: algosdk_1.OnApplicationComplete.OptInOC;
|
|
48
|
-
const composer = this.algorand.newGroup();
|
|
49
|
-
const assetTransfer = await this.algorand.createTransaction.assetTransfer({
|
|
50
|
-
assetId: assetId,
|
|
51
|
-
amount: amount,
|
|
52
|
-
sender: userAccount,
|
|
53
|
-
receiver: pool.appAddress,
|
|
54
|
-
});
|
|
55
|
-
composer.addAppCallMethodCall(await pool.params.deposit({
|
|
56
|
-
args: { assetTransferRef: assetTransfer },
|
|
57
|
-
sender: userAccount,
|
|
58
|
-
onComplete: onComplete,
|
|
59
|
-
extraFee: (0, alg_1.feeForInner)(5),
|
|
60
|
-
}));
|
|
61
|
-
let { transactions } = await composer.buildTransactions();
|
|
62
|
-
transactions = (0, algosdk_1.assignGroupID)(transactions);
|
|
63
|
-
return (0, alg_1.encodeTxs)(...transactions);
|
|
64
|
-
}
|
|
65
|
-
async buildRawTransactionWithdraw(params) {
|
|
66
|
-
const userAccount = params.accountAddress;
|
|
67
|
-
const amount = BigInt(params.amount);
|
|
68
|
-
const assetId = BigInt(params.token.tokenAddress);
|
|
69
|
-
const poolId = BigInt(params.token.poolAddress);
|
|
70
|
-
const pool = this.getPool(poolId);
|
|
71
|
-
const composer = this.algorand.newGroup();
|
|
72
|
-
composer.addAppCallMethodCall(await pool.params.withdraw({
|
|
73
|
-
args: { amountLp: amount },
|
|
74
|
-
sender: userAccount,
|
|
75
|
-
assetReferences: [assetId],
|
|
76
|
-
extraFee: (0, alg_1.feeForInner)(7),
|
|
77
|
-
}));
|
|
78
|
-
let { transactions } = await composer.buildTransactions();
|
|
79
|
-
transactions = (0, algosdk_1.assignGroupID)(transactions);
|
|
80
|
-
return (0, alg_1.encodeTxs)(...transactions);
|
|
81
|
-
}
|
|
82
|
-
async getPoolInfoFromChain(token) {
|
|
83
|
-
const pool = this.getPool(BigInt(token.poolAddress));
|
|
84
|
-
const all = await pool.state.global.getAll();
|
|
85
|
-
const aValue = all.a?.toString();
|
|
86
|
-
const dValue = all.d?.toString();
|
|
87
|
-
const tokenBalance = all.tokenBalance?.toString();
|
|
88
|
-
const vUsdBalance = all.vUsdBalance?.toString();
|
|
89
|
-
const totalLpAmount = all.totalSupply?.toString();
|
|
90
|
-
const accRewardPerShareP = (0, algosdk_1.bytesToBigInt)(all.accRewardPerShareP?.asByteArray() ?? Uint8Array.from([])).toString();
|
|
91
|
-
if (aValue && dValue && tokenBalance && vUsdBalance && totalLpAmount && accRewardPerShareP) {
|
|
92
|
-
const imbalance = (0, calculation_1.calculatePoolInfoImbalance)({ tokenBalance, vUsdBalance });
|
|
93
|
-
return {
|
|
94
|
-
aValue,
|
|
95
|
-
dValue,
|
|
96
|
-
tokenBalance,
|
|
97
|
-
vUsdBalance,
|
|
98
|
-
totalLpAmount,
|
|
99
|
-
accRewardPerShareP,
|
|
100
|
-
p: this.P,
|
|
101
|
-
imbalance,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
throw new exceptions_1.SdkError("Unable to pool info from chain");
|
|
105
|
-
}
|
|
106
|
-
async getUserBalanceInfo(accountAddress, token) {
|
|
107
|
-
const appId = BigInt(token.poolAddress);
|
|
108
|
-
const pool = this.getPool(appId);
|
|
109
|
-
try {
|
|
110
|
-
const { balance, userRewardDebt } = await pool.state.local(accountAddress).getAll();
|
|
111
|
-
if (balance !== undefined && userRewardDebt !== undefined) {
|
|
112
|
-
return new models_1.UserBalance({
|
|
113
|
-
lpAmount: balance.toString(),
|
|
114
|
-
rewardDebt: userRewardDebt.toString(),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (ignoreError) {
|
|
119
|
-
const info = await this.algorand.account.getInformation(accountAddress);
|
|
120
|
-
const localStates = info.appsLocalState;
|
|
121
|
-
if (localStates) {
|
|
122
|
-
const isOptedIn = localStates.find(({ id: id }) => id === appId);
|
|
123
|
-
if (!isOptedIn) {
|
|
124
|
-
return new models_1.UserBalance({ lpAmount: "0", rewardDebt: "0" });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw new exceptions_1.SdkError("Unable to get user balance");
|
|
129
|
-
}
|
|
130
|
-
getPool(appId) {
|
|
131
|
-
return this.algorand.client.getTypedAppClientById(PoolClient_1.PoolClient, { appId });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.AlgPoolService = AlgPoolService;
|
|
135
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/alg/index.ts"],"names":[],"mappings":";;;AACA,qCAA8E;AAC9E,6DAAwD;AAExD,oDAA+C;AAE/C,4DAAwE;AAExE,4DAAyD;AACzD,yCAAwE;AACxE,sCAMmB;AAEnB,MAAa,cAAe,SAAQ,yBA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5B,UAAU,EAAE,cAAc,CAAC,QAAQ,EAAE;iBACtC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,WAAW,EAAE,CAAC;YACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;YACxE,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC;YACxC,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;gBACjE,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,OAAO,IAAI,oBAAW,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,IAAI,qBAAQ,CAAC,4BAA4B,CAAC,CAAC;IACnD,CAAC;IAEO,OAAO,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,uBAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;CACF;AA7ID,wCA6IC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { assignGroupID, bytesToBigInt, OnApplicationComplete } from \"algosdk\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { RawTransaction } from \"../../models\";\nimport { PoolClient } from \"../../models/alg/PoolClient\";\nimport { checkAppOptIn, encodeTxs, feeForInner } from \"../../utils/alg\";\nimport {\n ChainPoolService,\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n UserBalance,\n UserBalanceInfo,\n} from \"../models\";\n\nexport class AlgPoolService extends ChainPoolService {\n chainType: ChainType.ALG = ChainType.ALG;\n private P = 48;\n\n constructor(\n public algorand: AlgorandClient,\n public api: AllbridgeCoreClient\n ) {\n super();\n algorand.setDefaultValidityWindow(100);\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const userAccount = params.accountAddress;\n const assetId = BigInt(params.token.tokenAddress);\n const poolId = BigInt(params.token.poolAddress);\n const pool = this.getPool(poolId);\n\n const composer = this.algorand.newGroup();\n composer.addAppCallMethodCall(\n await pool.params.claimRewards({\n args: [],\n sender: userAccount,\n extraFee: feeForInner(1),\n assetReferences: [assetId],\n })\n );\n let { transactions } = await composer.buildTransactions();\n transactions = assignGroupID(transactions);\n return encodeTxs(...transactions);\n }\n\n async buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const userAccount = params.accountAddress;\n const amount = BigInt(params.amount);\n const assetId = BigInt(params.token.tokenAddress);\n const poolId = BigInt(params.token.poolAddress);\n const pool = this.getPool(poolId);\n\n const isOptedIn = await checkAppOptIn(poolId, userAccount, this.algorand);\n\n const onComplete: OnApplicationComplete.OptInOC | OnApplicationComplete.NoOpOC = isOptedIn\n ? OnApplicationComplete.NoOpOC\n : OnApplicationComplete.OptInOC;\n\n const composer = this.algorand.newGroup();\n\n const assetTransfer = await this.algorand.createTransaction.assetTransfer({\n assetId: assetId,\n amount: amount,\n sender: userAccount,\n receiver: pool.appAddress,\n });\n composer.addAppCallMethodCall(\n await pool.params.deposit({\n args: { assetTransferRef: assetTransfer },\n sender: userAccount,\n onComplete: onComplete,\n extraFee: feeForInner(5),\n })\n );\n\n let { transactions } = await composer.buildTransactions();\n transactions = assignGroupID(transactions);\n return encodeTxs(...transactions);\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const userAccount = params.accountAddress;\n const amount = BigInt(params.amount);\n const assetId = BigInt(params.token.tokenAddress);\n const poolId = BigInt(params.token.poolAddress);\n const pool = this.getPool(poolId);\n\n const composer = this.algorand.newGroup();\n composer.addAppCallMethodCall(\n await pool.params.withdraw({\n args: { amountLp: amount },\n sender: userAccount,\n assetReferences: [assetId],\n extraFee: feeForInner(7),\n })\n );\n\n let { transactions } = await composer.buildTransactions();\n transactions = assignGroupID(transactions);\n return encodeTxs(...transactions);\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n const pool = this.getPool(BigInt(token.poolAddress));\n const all = await pool.state.global.getAll();\n const aValue = all.a?.toString();\n const dValue = all.d?.toString();\n const tokenBalance = all.tokenBalance?.toString();\n const vUsdBalance = all.vUsdBalance?.toString();\n const totalLpAmount = all.totalSupply?.toString();\n const accRewardPerShareP = bytesToBigInt(all.accRewardPerShareP?.asByteArray() ?? Uint8Array.from([])).toString();\n if (aValue && dValue && tokenBalance && vUsdBalance && totalLpAmount && accRewardPerShareP) {\n const imbalance = calculatePoolInfoImbalance({ tokenBalance, vUsdBalance });\n return {\n aValue,\n dValue,\n tokenBalance,\n vUsdBalance,\n totalLpAmount,\n accRewardPerShareP,\n p: this.P,\n imbalance,\n };\n }\n throw new SdkError(\"Unable to pool info from chain\");\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n const appId = BigInt(token.poolAddress);\n const pool = this.getPool(appId);\n try {\n const { balance, userRewardDebt } = await pool.state.local(accountAddress).getAll();\n if (balance !== undefined && userRewardDebt !== undefined) {\n return new UserBalance({\n lpAmount: balance.toString(),\n rewardDebt: userRewardDebt.toString(),\n });\n }\n } catch (ignoreError) {\n const info = await this.algorand.account.getInformation(accountAddress);\n const localStates = info.appsLocalState;\n if (localStates) {\n const isOptedIn = localStates.find(({ id: id }) => id === appId);\n if (!isOptedIn) {\n return new UserBalance({ lpAmount: \"0\", rewardDebt: \"0\" });\n }\n }\n }\n throw new SdkError(\"Unable to get user balance\");\n }\n\n private getPool(appId: bigint): PoolClient {\n return this.algorand.client.getTypedAppClientById(PoolClient, { appId });\n }\n}\n"]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChainType } from "../../../chains/chain.enums";
|
|
2
|
-
import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
|
|
3
|
-
import { AllbridgeCoreSdkOptions } from "../../../index";
|
|
4
|
-
import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
|
|
5
|
-
import { RawStxTransaction } from "../../models";
|
|
6
|
-
import { ChainPoolService, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "../models";
|
|
7
|
-
export declare class StxPoolService extends ChainPoolService {
|
|
8
|
-
nodeRpcUrl: string;
|
|
9
|
-
params: AllbridgeCoreSdkOptions;
|
|
10
|
-
api: AllbridgeCoreClient;
|
|
11
|
-
chainType: ChainType.STX;
|
|
12
|
-
private P;
|
|
13
|
-
private A;
|
|
14
|
-
private client;
|
|
15
|
-
constructor(nodeRpcUrl: string, params: AllbridgeCoreSdkOptions, api: AllbridgeCoreClient);
|
|
16
|
-
getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo>;
|
|
17
|
-
getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo>;
|
|
18
|
-
buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawStxTransaction>;
|
|
19
|
-
buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawStxTransaction>;
|
|
20
|
-
buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawStxTransaction>;
|
|
21
|
-
}
|