@allbridge/bridge-core-sdk 3.26.0-alpha.8 → 3.26.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +3 -4
- package/dist/src/chains/chain.enums.js +2 -3
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +6 -6
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +0 -1
- package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
- package/dist/src/client/core-api/core-api.model.d.ts +0 -1
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/services/bridge/index.js +0 -16
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +0 -1
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +1 -3
- package/dist/src/services/bridge/utils.js +15 -72
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +0 -16
- 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 -6
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/token/index.js +0 -16
- package/dist/src/services/token/index.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 -4
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +0 -4
- 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/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +2 -5
- package/dist/src/services/bridge/alg/index.d.ts +0 -15
- package/dist/src/services/bridge/alg/index.js +0 -151
- package/dist/src/services/bridge/alg/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 -141
- package/dist/src/services/liquidity-pool/alg/index.js.map +0 -1
- package/dist/src/services/models/alg/BridgeClient.d.ts +0 -2718
- package/dist/src/services/models/alg/BridgeClient.js +0 -2633
- package/dist/src/services/models/alg/BridgeClient.js.map +0 -1
- package/dist/src/services/models/alg/PoolClient.d.ts +0 -2265
- package/dist/src/services/models/alg/PoolClient.js +0 -2176
- package/dist/src/services/models/alg/PoolClient.js.map +0 -1
- package/dist/src/services/token/alg/index.d.ts +0 -17
- package/dist/src/services/token/alg/index.js +0 -46
- package/dist/src/services/token/alg/index.js.map +0 -1
- package/dist/src/services/utils/alg/index.d.ts +0 -17
- package/dist/src/services/utils/alg/index.js +0 -81
- package/dist/src/services/utils/alg/index.js.map +0 -1
- package/dist/src/utils/alg/index.d.ts +0 -21
- package/dist/src/utils/alg/index.js +0 -76
- package/dist/src/utils/alg/index.js.map +0 -1
|
@@ -1,151 +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 BridgeClient_1 = require("../../models/alg/BridgeClient");
|
|
33
|
-
const alg_1 = require("../../utils/alg");
|
|
34
|
-
const models_2 = require("../models");
|
|
35
|
-
const utils_1 = require("../utils");
|
|
36
|
-
class AlgBridgeService extends models_2.ChainBridgeService {
|
|
37
|
-
algorand;
|
|
38
|
-
api;
|
|
39
|
-
chainType = chain_enums_1.ChainType.ALG;
|
|
40
|
-
constructor(algorand, api) {
|
|
41
|
-
super();
|
|
42
|
-
this.algorand = algorand;
|
|
43
|
-
this.api = api;
|
|
44
|
-
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")));
|
|
45
|
-
}
|
|
46
|
-
send(_params) {
|
|
47
|
-
throw new exceptions_1.MethodNotSupportedError();
|
|
48
|
-
}
|
|
49
|
-
async buildRawTransactionSend(params) {
|
|
50
|
-
const txSendParams = await (0, utils_1.prepareTxSendParams)(this.chainType, params, this.api);
|
|
51
|
-
if (!params.sourceToken.bridgeId) {
|
|
52
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
53
|
-
}
|
|
54
|
-
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
55
|
-
const bridge = this.getBridge(bridgeId);
|
|
56
|
-
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
57
|
-
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
58
|
-
const destinationChainId = txSendParams.toChainId;
|
|
59
|
-
const recipient = txSendParams.toAccountAddress;
|
|
60
|
-
const receiveToken = txSendParams.toTokenAddress;
|
|
61
|
-
const nonce = (0, utils_1.getNonce)();
|
|
62
|
-
const amount = BigInt(txSendParams.amount);
|
|
63
|
-
let totalFee = BigInt(txSendParams.fee);
|
|
64
|
-
if (txSendParams.extraGas) {
|
|
65
|
-
totalFee = totalFee + BigInt(txSendParams.extraGas);
|
|
66
|
-
}
|
|
67
|
-
const isPayWithStable = txSendParams.gasFeePaymentMethod === models_1.FeePaymentMethod.WITH_STABLECOIN;
|
|
68
|
-
const composer = this.algorand.newGroup();
|
|
69
|
-
let feeTokenAmount;
|
|
70
|
-
let totalAmount;
|
|
71
|
-
if (isPayWithStable) {
|
|
72
|
-
feeTokenAmount = totalFee;
|
|
73
|
-
totalAmount = amount + feeTokenAmount;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
composer.addPayment({
|
|
77
|
-
sender,
|
|
78
|
-
receiver: bridge.appAddress,
|
|
79
|
-
amount: amount_1.AlgoAmount.MicroAlgo(totalFee),
|
|
80
|
-
});
|
|
81
|
-
feeTokenAmount = 0n;
|
|
82
|
-
totalAmount = amount;
|
|
83
|
-
}
|
|
84
|
-
composer
|
|
85
|
-
.addAssetTransfer({
|
|
86
|
-
assetId: tokenId,
|
|
87
|
-
amount: totalAmount,
|
|
88
|
-
sender,
|
|
89
|
-
receiver: bridge.appAddress,
|
|
90
|
-
})
|
|
91
|
-
.addAppCallMethodCall(await bridge.params.swapAndBridge({
|
|
92
|
-
args: {
|
|
93
|
-
tokenId,
|
|
94
|
-
recipient,
|
|
95
|
-
destinationChainId,
|
|
96
|
-
receiveToken,
|
|
97
|
-
nonce,
|
|
98
|
-
feeTokenAmount,
|
|
99
|
-
},
|
|
100
|
-
sender,
|
|
101
|
-
extraFee: (0, alg_1.feeForInner)(isPayWithStable ? 9 : 8),
|
|
102
|
-
}));
|
|
103
|
-
(0, alg_1.addBudgetNoops)({
|
|
104
|
-
composer,
|
|
105
|
-
appId: bridgeId,
|
|
106
|
-
sender,
|
|
107
|
-
count: isPayWithStable ? 3 : 2,
|
|
108
|
-
});
|
|
109
|
-
const { transactions } = await composer.buildTransactions();
|
|
110
|
-
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
111
|
-
}
|
|
112
|
-
async buildRawTransactionSwap(params) {
|
|
113
|
-
const txSwapParams = (0, utils_1.prepareTxSwapParams)(this.chainType, params);
|
|
114
|
-
const sender = algosdk_1.Address.fromString(params.fromAccountAddress);
|
|
115
|
-
const recipient = params.toAccountAddress;
|
|
116
|
-
const tokenId = BigInt(params.sourceToken.tokenAddress);
|
|
117
|
-
const receiveTokenId = BigInt(params.destinationToken.tokenAddress);
|
|
118
|
-
const receiveAmountMin = BigInt(txSwapParams.minimumReceiveAmount);
|
|
119
|
-
const amount = BigInt(params.amount);
|
|
120
|
-
if (!params.sourceToken.bridgeId) {
|
|
121
|
-
throw new exceptions_1.SdkError("ALG sourceToken must contain 'bridgeId'");
|
|
122
|
-
}
|
|
123
|
-
const bridgeId = BigInt(params.sourceToken.bridgeId);
|
|
124
|
-
const bridge = this.getBridge(bridgeId);
|
|
125
|
-
const composer = this.algorand.newGroup();
|
|
126
|
-
composer.addAssetTransfer({
|
|
127
|
-
assetId: tokenId,
|
|
128
|
-
amount: amount,
|
|
129
|
-
sender,
|
|
130
|
-
receiver: bridge.appAddress,
|
|
131
|
-
});
|
|
132
|
-
composer.addAppCallMethodCall(await bridge.params.swap({
|
|
133
|
-
args: { tokenId, recipient, receiveTokenId, receiveAmountMin },
|
|
134
|
-
sender,
|
|
135
|
-
extraFee: (0, alg_1.feeForInner)(4),
|
|
136
|
-
}));
|
|
137
|
-
(0, alg_1.addBudgetNoops)({
|
|
138
|
-
composer,
|
|
139
|
-
appId: bridgeId,
|
|
140
|
-
sender,
|
|
141
|
-
count: 1,
|
|
142
|
-
});
|
|
143
|
-
const { transactions } = await composer.buildTransactions();
|
|
144
|
-
return (0, alg_1.populateAndEncodeTxs)(transactions, sender, this.algorand.client.algod);
|
|
145
|
-
}
|
|
146
|
-
getBridge(appId) {
|
|
147
|
-
return this.algorand.client.getTypedAppClientById(BridgeClient_1.BridgeClient, { appId });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.AlgBridgeService = AlgBridgeService;
|
|
151
|
-
//# 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;AAEnD,gEAA6D;AAC7D,yCAAoF;AACpF,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,GA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AAU;SAC5B,CAAC,CAAC;QACH,QAAQ,CAAC,oBAAoB,CAC3B,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE;YAC9D,MAAM;YACN,QAAQ,EAAE,IAAA,iBAAW,EAAC,CAAC,CAAC;SACzB,CAAC,CACH,CAAC;QACF,IAAA,oBAAc,EAAC;YACb,QAAQ;YACR,KAAK,EAAE,QAAQ;YACf,MAAM;YACN,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QAC5D,OAAO,IAAA,0BAAoB,EAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAEO,SAAS,CAAC,KAAa;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,2BAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AArID,4CAqIC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { AlgoAmount } from \"@algorandfoundation/algokit-utils/types/amount\";\nimport algosdk, { Address } from \"algosdk\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeClient } from \"../../models/alg/BridgeClient\";\nimport { addBudgetNoops, feeForInner, populateAndEncodeTxs } from \"../../utils/alg\";\nimport { ChainBridgeService, SendParams, SwapParams } from \"../models\";\nimport { getNonce, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\n\nexport class AlgBridgeService extends ChainBridgeService {\n chainType: ChainType.ALG = ChainType.ALG;\n\n constructor(\n public algorand: AlgorandClient,\n public api: AllbridgeCoreClient\n ) {\n super();\n algorand.setDefaultSigner(\n algosdk.makeBasicAccountTransactionSigner(\n algosdk.mnemonicToSecretKey(\n \"tunnel gym elevator pulse motor evolve release orange culture make sister approve winter chair armor grocery distance festival tiger holiday dish wisdom region absorb secret\"\n )\n )\n );\n }\n\n send(_params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n const sender = Address.fromString(params.fromAccountAddress);\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const destinationChainId = txSendParams.toChainId;\n const recipient = txSendParams.toAccountAddress;\n const receiveToken = txSendParams.toTokenAddress;\n const nonce = getNonce();\n const amount = BigInt(txSendParams.amount);\n\n let totalFee = BigInt(txSendParams.fee);\n if (txSendParams.extraGas) {\n totalFee = totalFee + BigInt(txSendParams.extraGas);\n }\n const isPayWithStable = txSendParams.gasFeePaymentMethod === FeePaymentMethod.WITH_STABLECOIN;\n\n const composer = this.algorand.newGroup();\n\n let feeTokenAmount: bigint;\n let totalAmount: bigint;\n if (isPayWithStable) {\n feeTokenAmount = totalFee;\n totalAmount = amount + feeTokenAmount;\n } else {\n composer.addPayment({\n sender,\n receiver: bridge.appAddress,\n amount: AlgoAmount.MicroAlgo(totalFee),\n });\n feeTokenAmount = 0n;\n totalAmount = amount;\n }\n composer\n .addAssetTransfer({\n assetId: tokenId,\n amount: totalAmount,\n sender,\n receiver: bridge.appAddress,\n })\n .addAppCallMethodCall(\n await bridge.params.swapAndBridge({\n args: {\n tokenId,\n recipient,\n destinationChainId,\n receiveToken,\n nonce,\n feeTokenAmount,\n },\n sender,\n extraFee: feeForInner(isPayWithStable ? 9 : 8),\n })\n );\n addBudgetNoops({\n composer,\n appId: bridgeId,\n sender,\n count: isPayWithStable ? 3 : 2,\n });\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n\n const sender = Address.fromString(params.fromAccountAddress);\n const recipient = params.toAccountAddress;\n const tokenId = BigInt(params.sourceToken.tokenAddress);\n const receiveTokenId = BigInt(params.destinationToken.tokenAddress);\n const receiveAmountMin = BigInt(txSwapParams.minimumReceiveAmount);\n const amount = BigInt(params.amount);\n\n if (!params.sourceToken.bridgeId) {\n throw new SdkError(\"ALG sourceToken must contain 'bridgeId'\");\n }\n const bridgeId = BigInt(params.sourceToken.bridgeId);\n const bridge = this.getBridge(bridgeId);\n\n const composer = this.algorand.newGroup();\n composer.addAssetTransfer({\n assetId: tokenId,\n amount: amount,\n sender,\n receiver: bridge.appAddress,\n });\n composer.addAppCallMethodCall(\n await bridge.params.swap({\n args: { tokenId, recipient, receiveTokenId, receiveAmountMin },\n sender,\n extraFee: feeForInner(4),\n })\n );\n addBudgetNoops({\n composer,\n appId: bridgeId,\n sender,\n count: 1,\n });\n const { transactions } = await composer.buildTransactions();\n return populateAndEncodeTxs(transactions, sender, this.algorand.client.algod);\n }\n\n private getBridge(appId: bigint): BridgeClient {\n return this.algorand.client.getTypedAppClientById(BridgeClient, { appId });\n }\n}\n"]}
|
|
@@ -1,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,141 +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
|
-
}
|
|
21
|
-
async buildRawTransactionClaimRewards(params) {
|
|
22
|
-
const userAccount = params.accountAddress;
|
|
23
|
-
const assetId = BigInt(params.token.tokenAddress);
|
|
24
|
-
const poolId = BigInt(params.token.poolAddress);
|
|
25
|
-
const pool = this.getPool(poolId);
|
|
26
|
-
const composer = this.algorand.newGroup();
|
|
27
|
-
composer.addAppCallMethodCall(await pool.params.claimRewards({
|
|
28
|
-
args: [],
|
|
29
|
-
sender: userAccount,
|
|
30
|
-
extraFee: (0, alg_1.feeForInner)(1),
|
|
31
|
-
assetReferences: [assetId],
|
|
32
|
-
}));
|
|
33
|
-
let { transactions } = await composer.buildTransactions();
|
|
34
|
-
transactions = (0, algosdk_1.assignGroupID)(transactions);
|
|
35
|
-
return (0, alg_1.encodeTxs)(...transactions);
|
|
36
|
-
}
|
|
37
|
-
async buildRawTransactionDeposit(params) {
|
|
38
|
-
const userAccount = params.accountAddress;
|
|
39
|
-
const amount = BigInt(params.amount);
|
|
40
|
-
const assetId = BigInt(params.token.tokenAddress);
|
|
41
|
-
const poolId = BigInt(params.token.poolAddress);
|
|
42
|
-
const pool = this.getPool(poolId);
|
|
43
|
-
const isOptedIn = await (0, alg_1.checkAppOptIn)(poolId, userAccount, this.algorand);
|
|
44
|
-
const composer = this.algorand.newGroup();
|
|
45
|
-
if (!isOptedIn) {
|
|
46
|
-
composer.addAppCallMethodCall(await pool.params.optIn.optInToApplication({ args: [], sender: userAccount }));
|
|
47
|
-
}
|
|
48
|
-
composer.addAssetTransfer({
|
|
49
|
-
assetId: assetId,
|
|
50
|
-
amount: amount,
|
|
51
|
-
sender: userAccount,
|
|
52
|
-
receiver: pool.appAddress,
|
|
53
|
-
});
|
|
54
|
-
composer.addAppCallMethodCall(await pool.params.deposit({ args: [], sender: userAccount, extraFee: (0, alg_1.feeForInner)(1) }));
|
|
55
|
-
(0, alg_1.addBudgetNoops)({
|
|
56
|
-
composer,
|
|
57
|
-
appId: poolId,
|
|
58
|
-
sender: userAccount,
|
|
59
|
-
count: 4,
|
|
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
|
-
extraFee: (0, alg_1.feeForInner)(2),
|
|
76
|
-
assetReferences: [assetId],
|
|
77
|
-
}));
|
|
78
|
-
(0, alg_1.addBudgetNoops)({
|
|
79
|
-
composer,
|
|
80
|
-
appId: poolId,
|
|
81
|
-
sender: userAccount,
|
|
82
|
-
count: 4,
|
|
83
|
-
});
|
|
84
|
-
let { transactions } = await composer.buildTransactions();
|
|
85
|
-
transactions = (0, algosdk_1.assignGroupID)(transactions);
|
|
86
|
-
return (0, alg_1.encodeTxs)(...transactions);
|
|
87
|
-
}
|
|
88
|
-
async getPoolInfoFromChain(token) {
|
|
89
|
-
const pool = this.getPool(BigInt(token.poolAddress));
|
|
90
|
-
const all = await pool.state.global.getAll();
|
|
91
|
-
const aValue = all.a?.toString();
|
|
92
|
-
const dValue = all.d?.toString();
|
|
93
|
-
const tokenBalance = all.tokenBalance?.toString();
|
|
94
|
-
const vUsdBalance = all.vUsdBalance?.toString();
|
|
95
|
-
const totalLpAmount = all.totalSupply?.toString();
|
|
96
|
-
const accRewardPerShareP = (0, algosdk_1.bytesToBigInt)(all.accRewardPerShareP?.asByteArray() ?? Uint8Array.from([])).toString();
|
|
97
|
-
if (aValue && dValue && tokenBalance && vUsdBalance && totalLpAmount && accRewardPerShareP) {
|
|
98
|
-
const imbalance = (0, calculation_1.calculatePoolInfoImbalance)({ tokenBalance, vUsdBalance });
|
|
99
|
-
return {
|
|
100
|
-
aValue,
|
|
101
|
-
dValue,
|
|
102
|
-
tokenBalance,
|
|
103
|
-
vUsdBalance,
|
|
104
|
-
totalLpAmount,
|
|
105
|
-
accRewardPerShareP,
|
|
106
|
-
p: this.P,
|
|
107
|
-
imbalance,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
throw new exceptions_1.SdkError("Unable to pool info from chain");
|
|
111
|
-
}
|
|
112
|
-
async getUserBalanceInfo(accountAddress, token) {
|
|
113
|
-
const appId = BigInt(token.poolAddress);
|
|
114
|
-
const pool = this.getPool(appId);
|
|
115
|
-
try {
|
|
116
|
-
const { balance, userRewardDebt } = await pool.state.local(accountAddress).getAll();
|
|
117
|
-
if (balance !== undefined && userRewardDebt !== undefined) {
|
|
118
|
-
return new models_1.UserBalance({
|
|
119
|
-
lpAmount: balance.toString(),
|
|
120
|
-
rewardDebt: userRewardDebt.toString(),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (ignoreError) {
|
|
125
|
-
const info = await this.algorand.account.getInformation(accountAddress);
|
|
126
|
-
const localStates = info.appsLocalState;
|
|
127
|
-
if (localStates) {
|
|
128
|
-
const isOptedIn = localStates.find(({ id: id }) => id === appId);
|
|
129
|
-
if (!isOptedIn) {
|
|
130
|
-
return new models_1.UserBalance({ lpAmount: "0", rewardDebt: "0" });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
throw new exceptions_1.SdkError("Unable to get user balance");
|
|
135
|
-
}
|
|
136
|
-
getPool(appId) {
|
|
137
|
-
return this.algorand.client.getTypedAppClientById(PoolClient_1.PoolClient, { appId });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.AlgPoolService = AlgPoolService;
|
|
141
|
-
//# sourceMappingURL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IAC3E,CAAC;CACF;AAjJD,wCAiJC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { assignGroupID, bytesToBigInt } 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 { addBudgetNoops, 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 }\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 composer = this.algorand.newGroup();\n\n if (!isOptedIn) {\n composer.addAppCallMethodCall(await pool.params.optIn.optInToApplication({ args: [], sender: userAccount }));\n }\n\n composer.addAssetTransfer({\n assetId: assetId,\n amount: amount,\n sender: userAccount,\n receiver: pool.appAddress,\n });\n composer.addAppCallMethodCall(\n await pool.params.deposit({ args: [], sender: userAccount, extraFee: feeForInner(1) })\n );\n addBudgetNoops({\n composer,\n appId: poolId,\n sender: userAccount,\n count: 4,\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 extraFee: feeForInner(2),\n assetReferences: [assetId],\n })\n );\n addBudgetNoops({\n composer,\n appId: poolId,\n sender: userAccount,\n count: 4,\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"]}
|