@allbridge/bridge-core-sdk 3.32.1 → 3.33.0-alpha.2
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-caching.d.ts +2 -0
- package/dist/src/client/core-api/api-client-caching.js +2 -0
- package/dist/src/client/core-api/api-client-caching.js.map +1 -1
- package/dist/src/client/core-api/api-client.d.ts +5 -0
- package/dist/src/client/core-api/api-client.js +2 -0
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.d.ts +15 -0
- package/dist/src/client/core-api/core-api-mapper.js +15 -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 +30 -0
- package/dist/src/client/core-api/core-api.model.js +4 -0
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/client/core-api/core-client-base.d.ts +9 -0
- package/dist/src/client/core-api/core-client-base.js +3 -0
- package/dist/src/client/core-api/core-client-base.js.map +1 -1
- package/dist/src/client/core-api/core-client-filtered.d.ts +16 -0
- package/dist/src/client/core-api/core-client-filtered.js +4 -0
- package/dist/src/client/core-api/core-client-filtered.js.map +1 -1
- package/dist/src/client/core-api/core-client-pool-info-caching.d.ts +13 -0
- package/dist/src/client/core-api/core-client-pool-info-caching.js +7 -0
- package/dist/src/client/core-api/core-client-pool-info-caching.js.map +1 -1
- package/dist/src/exceptions/exceptions.d.ts +4 -0
- package/dist/src/exceptions/exceptions.js +4 -0
- package/dist/src/exceptions/exceptions.js.map +1 -1
- package/dist/src/index.d.ts +48 -30
- package/dist/src/index.js +17 -86
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +2 -1
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/bridge/alg/index.d.ts +1 -0
- package/dist/src/services/bridge/alg/index.js +1 -0
- package/dist/src/services/bridge/alg/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +2 -0
- package/dist/src/services/bridge/evm/index.js +2 -0
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +4 -2
- package/dist/src/services/bridge/index.js +7 -45
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.d.ts +1 -0
- package/dist/src/services/bridge/models/bridge.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +14 -6
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.d.ts +6 -0
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +3 -2
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/sol/bridge-tx-service.d.ts +3 -1
- package/dist/src/services/bridge/sol/bridge-tx-service.js +4 -0
- package/dist/src/services/bridge/sol/bridge-tx-service.js.map +1 -1
- package/dist/src/services/bridge/sol/index.d.ts +3 -1
- package/dist/src/services/bridge/sol/index.js +1 -0
- package/dist/src/services/bridge/sol/index.js.map +1 -1
- package/dist/src/services/bridge/sol/payer-with-token-service.js +3 -0
- package/dist/src/services/bridge/sol/payer-with-token-service.js.map +1 -1
- package/dist/src/services/bridge/spender.d.ts +4 -0
- package/dist/src/services/bridge/spender.js +45 -0
- package/dist/src/services/bridge/spender.js.map +1 -0
- package/dist/src/services/bridge/srb/index.d.ts +2 -0
- package/dist/src/services/bridge/srb/index.js +2 -0
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/stx/index.d.ts +1 -0
- package/dist/src/services/bridge/stx/index.js +1 -0
- package/dist/src/services/bridge/stx/index.js.map +1 -1
- package/dist/src/services/bridge/sui/index.d.ts +1 -0
- package/dist/src/services/bridge/sui/index.js +1 -0
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.d.ts +2 -0
- package/dist/src/services/bridge/trx/index.js +2 -0
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +4 -0
- package/dist/src/services/bridge/utils.js +1 -0
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/index.d.ts +25 -2
- package/dist/src/services/index.js +17 -2
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/alg/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/alg/index.js +3 -0
- package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/evm/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/evm/index.js +3 -0
- package/dist/src/services/liquidity-pool/evm/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.d.ts +19 -0
- package/dist/src/services/liquidity-pool/index.js +9 -1
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/models/pool.d.ts +8 -0
- package/dist/src/services/liquidity-pool/models/pool.js +3 -0
- package/dist/src/services/liquidity-pool/models/pool.js.map +1 -1
- package/dist/src/services/liquidity-pool/models/pool.model.d.ts +27 -0
- package/dist/src/services/liquidity-pool/models/pool.model.js +3 -0
- package/dist/src/services/liquidity-pool/models/pool.model.js.map +1 -1
- package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.d.ts +11 -0
- package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.js +3 -0
- package/dist/src/services/liquidity-pool/raw-pool-transaction-builder.js.map +1 -1
- package/dist/src/services/liquidity-pool/sol/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/sol/index.js +3 -0
- package/dist/src/services/liquidity-pool/sol/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/srb/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/srb/index.js +3 -0
- package/dist/src/services/liquidity-pool/srb/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/stx/index.js +3 -0
- package/dist/src/services/liquidity-pool/stx/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/sui/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/sui/index.js +3 -0
- package/dist/src/services/liquidity-pool/sui/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/trx/index.d.ts +3 -0
- package/dist/src/services/liquidity-pool/trx/index.js +3 -0
- package/dist/src/services/liquidity-pool/trx/index.js.map +1 -1
- package/dist/src/services/utils/calculation/index.d.ts +6 -0
- package/dist/src/services/utils/calculation/index.js +6 -0
- package/dist/src/services/utils/calculation/index.js.map +1 -1
- package/dist/src/services/utils/sol/index.d.ts +6 -0
- package/dist/src/services/utils/sol/index.js +6 -0
- package/dist/src/services/utils/sol/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +24 -0
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/calculation/index.d.ts +26 -0
- package/dist/src/utils/calculation/index.js +26 -0
- package/dist/src/utils/calculation/index.js.map +1 -1
- package/dist/src/utils/calculation/swap-and-bridge-details.d.ts +9 -0
- package/dist/src/utils/calculation/swap-and-bridge-details.js +3 -0
- package/dist/src/utils/calculation/swap-and-bridge-details.js.map +1 -1
- package/dist/src/utils/calculation/swap-and-bridge-fee-calc.d.ts +18 -0
- package/dist/src/utils/calculation/swap-and-bridge-fee-calc.js +6 -0
- package/dist/src/utils/calculation/swap-and-bridge-fee-calc.js.map +1 -1
- package/dist/src/utils/utils.d.ts +3 -0
- package/dist/src/utils/utils.js +3 -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
|
@@ -7,19 +7,25 @@ import { Provider, TransactionResponse } from "../models";
|
|
|
7
7
|
import { TokenService } from "../token";
|
|
8
8
|
import { ApproveParams, ChainPoolService, CheckAllowanceParams, GetAllowanceParams, UserBalanceInfo } from "./models";
|
|
9
9
|
import { RawPoolTransactionBuilder } from "./raw-pool-transaction-builder";
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Do not use.
|
|
12
|
+
*/
|
|
10
13
|
export interface LiquidityPoolService {
|
|
14
|
+
/** @deprecated Do not use. */
|
|
11
15
|
rawTxBuilder: RawPoolTransactionBuilder;
|
|
12
16
|
/**
|
|
13
17
|
* Get amount of tokens approved for poolInfo
|
|
14
18
|
* @param provider - will be used to access the network
|
|
15
19
|
* @param params See {@link GetAllowanceParams}
|
|
16
20
|
* @returns the amount of approved tokens
|
|
21
|
+
* @deprecated Do not use.
|
|
17
22
|
*/
|
|
18
23
|
getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;
|
|
19
24
|
/**
|
|
20
25
|
* Get amount of tokens approved for poolInfo
|
|
21
26
|
* @param params See {@link GetAllowanceParams}
|
|
22
27
|
* @returns the amount of approved tokens
|
|
28
|
+
* @deprecated Do not use.
|
|
23
29
|
*/
|
|
24
30
|
getAllowance(params: GetAllowanceParams): Promise<string>;
|
|
25
31
|
/**
|
|
@@ -27,12 +33,14 @@ export interface LiquidityPoolService {
|
|
|
27
33
|
* @param provider - will be used to access the network
|
|
28
34
|
* @param params See {@link CheckAllowanceParams}
|
|
29
35
|
* @returns true if the amount of approved tokens is enough to make a transfer
|
|
36
|
+
* @deprecated Do not use.
|
|
30
37
|
*/
|
|
31
38
|
checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;
|
|
32
39
|
/**
|
|
33
40
|
* Check if the amount of approved tokens is enough
|
|
34
41
|
* @param params See {@link CheckAllowanceParams}
|
|
35
42
|
* @returns true if the amount of approved tokens is enough to make a transfer
|
|
43
|
+
* @deprecated Do not use.
|
|
36
44
|
*/
|
|
37
45
|
checkAllowance(params: CheckAllowanceParams): Promise<boolean>;
|
|
38
46
|
/**
|
|
@@ -51,6 +59,7 @@ export interface LiquidityPoolService {
|
|
|
51
59
|
* @param token
|
|
52
60
|
* @param provider - will be used to access the network
|
|
53
61
|
* @returns amount
|
|
62
|
+
* @deprecated Do not use.
|
|
54
63
|
*/
|
|
55
64
|
getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;
|
|
56
65
|
/**
|
|
@@ -60,6 +69,7 @@ export interface LiquidityPoolService {
|
|
|
60
69
|
* @param token
|
|
61
70
|
* @param provider - will be used to access the network
|
|
62
71
|
* @returns amount
|
|
72
|
+
* @deprecated Do not use.
|
|
63
73
|
*/
|
|
64
74
|
getAmountToBeWithdrawn(amount: string, accountAddress: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;
|
|
65
75
|
/**
|
|
@@ -68,6 +78,7 @@ export interface LiquidityPoolService {
|
|
|
68
78
|
* @param token
|
|
69
79
|
* @param provider
|
|
70
80
|
* @returns UserBalanceInfo
|
|
81
|
+
* @deprecated Do not use.
|
|
71
82
|
*/
|
|
72
83
|
getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails, provider?: Provider): Promise<UserBalanceInfo>;
|
|
73
84
|
/**
|
|
@@ -75,14 +86,19 @@ export interface LiquidityPoolService {
|
|
|
75
86
|
* @param token
|
|
76
87
|
* @param provider - will be used to access the network
|
|
77
88
|
* @returns poolInfo
|
|
89
|
+
* @deprecated Do not use.
|
|
78
90
|
*/
|
|
79
91
|
getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<Required<PoolInfo>>;
|
|
80
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Do not use.
|
|
95
|
+
*/
|
|
81
96
|
export declare class DefaultLiquidityPoolService implements LiquidityPoolService {
|
|
82
97
|
private api;
|
|
83
98
|
private nodeRpcUrlsConfig;
|
|
84
99
|
private params;
|
|
85
100
|
private tokenService;
|
|
101
|
+
/** @deprecated Do not use. */
|
|
86
102
|
rawTxBuilder: RawPoolTransactionBuilder;
|
|
87
103
|
private cache;
|
|
88
104
|
constructor(api: AllbridgeCoreClientFiltered, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, tokenService: TokenService);
|
|
@@ -94,4 +110,7 @@ export declare class DefaultLiquidityPoolService implements LiquidityPoolService
|
|
|
94
110
|
getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails, provider?: Provider): Promise<UserBalanceInfo>;
|
|
95
111
|
getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo>;
|
|
96
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Do not use.
|
|
115
|
+
*/
|
|
97
116
|
export declare function getChainPoolService(chainSymbol: string, api: AllbridgeCoreClient, nodeRpcUrlsConfig: NodeRpcUrlsConfig, params: AllbridgeCoreSdkOptions, provider?: Provider): ChainPoolService;
|
|
@@ -17,11 +17,15 @@ import { SrbPoolService } from "./srb";
|
|
|
17
17
|
import { StxPoolService } from "./stx";
|
|
18
18
|
import { SuiPoolService } from "./sui";
|
|
19
19
|
import { TronPoolService } from "./trx";
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Do not use.
|
|
22
|
+
*/
|
|
20
23
|
export class DefaultLiquidityPoolService {
|
|
21
24
|
api;
|
|
22
25
|
nodeRpcUrlsConfig;
|
|
23
26
|
params;
|
|
24
27
|
tokenService;
|
|
28
|
+
/** @deprecated Do not use. */
|
|
25
29
|
rawTxBuilder;
|
|
26
30
|
cache;
|
|
27
31
|
constructor(api, nodeRpcUrlsConfig, params, tokenService) {
|
|
@@ -30,7 +34,8 @@ export class DefaultLiquidityPoolService {
|
|
|
30
34
|
this.params = params;
|
|
31
35
|
this.tokenService = tokenService;
|
|
32
36
|
this.rawTxBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrlsConfig, this.params, tokenService);
|
|
33
|
-
const
|
|
37
|
+
const cachePoolInfoChainSec = params.cachePoolInfoChainSec ?? 20;
|
|
38
|
+
const ttl = cachePoolInfoChainSec > 0 ? cachePoolInfoChainSec * 1000 : 20 * 1000;
|
|
34
39
|
this.cache = new Cache({ defaultTtl: ttl });
|
|
35
40
|
}
|
|
36
41
|
async getAllowance(a, b) {
|
|
@@ -94,6 +99,9 @@ export class DefaultLiquidityPoolService {
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated Do not use.
|
|
104
|
+
*/
|
|
97
105
|
export function getChainPoolService(chainSymbol, api, nodeRpcUrlsConfig, params, provider) {
|
|
98
106
|
switch (Chains.getChainProperty(chainSymbol).chainType) {
|
|
99
107
|
case ChainType.EVM: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAA2B,SAAS,EAAiB,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,gC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a,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACvF,CAAC;QACD,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,KAAK,GAAG,QAAmB,CAAC;gBAClC,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvD,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;iBAAM,CAAC;gBACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChE,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC;oBACzC,WAAW,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;iBACpC,CAAC,CAAC;gBACH,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QACD,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAChE,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { Algodv2 } from \"algosdk\";\nimport { Big } from \"big.js\";\nimport Cache from \"timed-cache\";\nimport { TronWeb } from \"tronweb\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3 } from \"../../index\";\nimport { PoolInfo, PoolKeyObject, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertIntAmountToFloat, fromSystemPrecision } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { depositAmountToVUsd, vUsdToWithdrawalAmount } from \"../utils/calculation\";\nimport { AlgPoolService } from \"./alg\";\nimport { EvmPoolService } from \"./evm\";\nimport { ApproveParams, ChainPoolService, CheckAllowanceParams, GetAllowanceParams, UserBalanceInfo } from \"./models\";\nimport { DefaultRawPoolTransactionBuilder, RawPoolTransactionBuilder } from \"./raw-pool-transaction-builder\";\nimport { SolanaPoolService } from \"./sol\";\nimport { SrbPoolService } from \"./srb\";\nimport { StxPoolService } from \"./stx\";\nimport { SuiPoolService } from \"./sui\";\nimport { TronPoolService } from \"./trx\";\n\nexport interface LiquidityPoolService {\n rawTxBuilder: RawPoolTransactionBuilder;\n\n /**\n * Get amount of tokens approved for poolInfo\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved for poolInfo\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawPoolTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * Calculates the amount of LP tokens that will be deposited\n * @param amount The float amount of tokens that will be sent\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of tokens will be withdrawn\n * @param amount The float amount of tokens that will be sent\n * @param accountAddress\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n */\n getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string>;\n\n /**\n * Get User Balance Info on Liquidity poolInfo\n * @param accountAddress\n * @param token\n * @param provider\n * @returns UserBalanceInfo\n */\n getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo>;\n\n /**\n * Gets information about the poolInfo from chain\n * @param token\n * @param provider - will be used to access the network\n * @returns poolInfo\n */\n getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<Required<PoolInfo>>;\n}\n\nexport class DefaultLiquidityPoolService implements LiquidityPoolService {\n public rawTxBuilder: RawPoolTransactionBuilder;\n private cache: Cache<PoolInfo>;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrlsConfig, this.params, tokenService);\n const ttl = params.cachePoolInfoChainSec > 0 ? params.cachePoolInfoChainSec * 1000 : 20 * 1000;\n this.cache = new Cache<PoolInfo>({ defaultTtl: ttl });\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as GetAllowanceParams;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as CheckAllowanceParams;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n return this.tokenService.approve(provider, { ...approveData, spender: approveData.token.poolAddress });\n }\n\n async getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const { vUsdBalance, tokenBalance, aValue, dValue } = pool;\n const vUsd = depositAmountToVUsd(amount, aValue, dValue, tokenBalance, vUsdBalance);\n return convertIntAmountToFloat(vUsd, SYSTEM_PRECISION).toFixed();\n }\n\n async getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const tokenAmountInSP = vUsdToWithdrawalAmount(amount);\n const tokenAmount = fromSystemPrecision(tokenAmountInSP, token.decimals);\n const userBalanceInfo = await this.getUserBalanceInfo(accountAddress, token, provider);\n const earned = userBalanceInfo.earned(pool) || \"0\";\n const commonAmount = Big(tokenAmount).plus(earned).toFixed();\n return convertIntAmountToFloat(commonAmount, token.decimals).toFixed();\n }\n\n async getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo> {\n return getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getUserBalanceInfo(accountAddress, token);\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo> {\n const poolKey: PoolKeyObject = { chainSymbol: token.chainSymbol, poolAddress: token.poolAddress };\n const fromCache = this.cache.get(poolKey);\n if (fromCache) {\n return fromCache;\n } else {\n const poolInfo = await getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getPoolInfoFromChain(token);\n this.cache.put(poolKey, poolInfo);\n this.api.cachePut({ chainSymbol: token.chainSymbol, poolAddress: token.poolAddress }, poolInfo);\n return poolInfo;\n }\n }\n}\n\nexport function getChainPoolService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainPoolService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmPoolService(provider as EssentialWeb3, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const web3 = new Web3(nodeRpcUrl);\n web3.defaultReturnFormat = { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX };\n return new EvmPoolService(web3, api);\n }\n }\n case ChainType.TRX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronJsonRpc = params.tronJsonRpc;\n if (provider) {\n return new TronPoolService(provider as TronWeb, api, tronJsonRpc);\n } else {\n const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });\n return new TronPoolService(tronWeb, api, tronJsonRpc);\n }\n }\n case ChainType.SOLANA: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new SolanaPoolService(nodeRpcUrl, api);\n }\n case ChainType.SRB: {\n return new SrbPoolService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiPoolService(nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol), params, api);\n }\n case ChainType.ALG: {\n if (provider) {\n const algod = provider as Algodv2;\n const algorand = AlgorandClient.fromClients({ algod });\n return new AlgPoolService(algorand, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const algorand = AlgorandClient.fromConfig({\n algodConfig: { server: nodeRpcUrl },\n });\n return new AlgPoolService(algorand, api);\n }\n }\n case ChainType.STX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new StxPoolService(nodeRpcUrl, params, api);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAA2B,SAAS,EAAiB,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM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,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,cAAc,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACvF,CAAC;QACD,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,KAAK,GAAG,QAAmB,CAAC;gBAClC,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvD,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;iBAAM,CAAC;gBACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChE,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC;oBACzC,WAAW,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;iBACpC,CAAC,CAAC;gBACH,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QACD,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAChE,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AlgorandClient } from \"@algorandfoundation/algokit-utils\";\nimport { Algodv2 } from \"algosdk\";\nimport { Big } from \"big.js\";\nimport Cache from \"timed-cache\";\nimport { TronWeb } from \"tronweb\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { NodeRpcUrlsConfig } from \"..\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3 } from \"../../index\";\nimport { PoolInfo, PoolKeyObject, TokenWithChainDetails } from \"../../tokens-info\";\nimport { convertIntAmountToFloat, fromSystemPrecision } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, TransactionResponse } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { depositAmountToVUsd, vUsdToWithdrawalAmount } from \"../utils/calculation\";\nimport { AlgPoolService } from \"./alg\";\nimport { EvmPoolService } from \"./evm\";\nimport { ApproveParams, ChainPoolService, CheckAllowanceParams, GetAllowanceParams, UserBalanceInfo } from \"./models\";\nimport { DefaultRawPoolTransactionBuilder, RawPoolTransactionBuilder } from \"./raw-pool-transaction-builder\";\nimport { SolanaPoolService } from \"./sol\";\nimport { SrbPoolService } from \"./srb\";\nimport { StxPoolService } from \"./stx\";\nimport { SuiPoolService } from \"./sui\";\nimport { TronPoolService } from \"./trx\";\n\n/**\n * @deprecated Do not use.\n */\nexport interface LiquidityPoolService {\n /** @deprecated Do not use. */\n rawTxBuilder: RawPoolTransactionBuilder;\n\n /**\n * Get amount of tokens approved for poolInfo\n * @param provider - will be used to access the network\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n * @deprecated Do not use.\n */\n getAllowance(provider: Provider, params: GetAllowanceParams): Promise<string>;\n\n /**\n * Get amount of tokens approved for poolInfo\n * @param params See {@link GetAllowanceParams}\n * @returns the amount of approved tokens\n * @deprecated Do not use.\n */\n getAllowance(params: GetAllowanceParams): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param provider - will be used to access the network\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n * @deprecated Do not use.\n */\n checkAllowance(provider: Provider, params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param params See {@link CheckAllowanceParams}\n * @returns true if the amount of approved tokens is enough to make a transfer\n * @deprecated Do not use.\n */\n checkAllowance(params: CheckAllowanceParams): Promise<boolean>;\n\n /**\n * @deprecated Use {@link rawTxBuilder}.{@link RawPoolTransactionBuilder.approve}<p>\n * Approve tokens usage by another address on chains\n * <p>\n * For ETH/USDT: due to specificity of the USDT contract:<br/>\n * If the current allowance is not 0, this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.\n * @param provider - will be used to access the network\n * @param approveData\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse>;\n\n /**\n * Calculates the amount of LP tokens that will be deposited\n * @param amount The float amount of tokens that will be sent\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n * @deprecated Do not use.\n */\n getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of tokens will be withdrawn\n * @param amount The float amount of tokens that will be sent\n * @param accountAddress\n * @param token\n * @param provider - will be used to access the network\n * @returns amount\n * @deprecated Do not use.\n */\n getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string>;\n\n /**\n * Get User Balance Info on Liquidity poolInfo\n * @param accountAddress\n * @param token\n * @param provider\n * @returns UserBalanceInfo\n * @deprecated Do not use.\n */\n getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo>;\n\n /**\n * Gets information about the poolInfo from chain\n * @param token\n * @param provider - will be used to access the network\n * @returns poolInfo\n * @deprecated Do not use.\n */\n getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<Required<PoolInfo>>;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport class DefaultLiquidityPoolService implements LiquidityPoolService {\n /** @deprecated Do not use. */\n public rawTxBuilder: RawPoolTransactionBuilder;\n private cache: Cache<PoolInfo>;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrlsConfig, this.params, tokenService);\n const cachePoolInfoChainSec = params.cachePoolInfoChainSec ?? 20;\n const ttl = cachePoolInfoChainSec > 0 ? cachePoolInfoChainSec * 1000 : 20 * 1000;\n this.cache = new Cache<PoolInfo>({ defaultTtl: ttl });\n }\n\n async getAllowance(a: Provider | GetAllowanceParams, b?: GetAllowanceParams): Promise<string> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as GetAllowanceParams;\n return await this.tokenService.getAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async checkAllowance(a: Provider | CheckAllowanceParams, b?: CheckAllowanceParams): Promise<boolean> {\n if (b) {\n const provider = a as Provider;\n const params = b;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress }, provider);\n } else {\n const params = a as CheckAllowanceParams;\n return this.tokenService.checkAllowance({ ...params, spender: params.token.poolAddress });\n }\n }\n\n async approve(provider: Provider, approveData: ApproveParams): Promise<TransactionResponse> {\n return this.tokenService.approve(provider, { ...approveData, spender: approveData.token.poolAddress });\n }\n\n async getAmountToBeDeposited(amount: string, token: TokenWithChainDetails, provider?: Provider): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const { vUsdBalance, tokenBalance, aValue, dValue } = pool;\n const vUsd = depositAmountToVUsd(amount, aValue, dValue, tokenBalance, vUsdBalance);\n return convertIntAmountToFloat(vUsd, SYSTEM_PRECISION).toFixed();\n }\n\n async getAmountToBeWithdrawn(\n amount: string,\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(amount);\n validateAmountDecimals(\"amount\", amount, token.decimals);\n const pool = await this.getPoolInfoFromChain(token, provider);\n const tokenAmountInSP = vUsdToWithdrawalAmount(amount);\n const tokenAmount = fromSystemPrecision(tokenAmountInSP, token.decimals);\n const userBalanceInfo = await this.getUserBalanceInfo(accountAddress, token, provider);\n const earned = userBalanceInfo.earned(pool) || \"0\";\n const commonAmount = Big(tokenAmount).plus(earned).toFixed();\n return convertIntAmountToFloat(commonAmount, token.decimals).toFixed();\n }\n\n async getUserBalanceInfo(\n accountAddress: string,\n token: TokenWithChainDetails,\n provider?: Provider\n ): Promise<UserBalanceInfo> {\n return getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getUserBalanceInfo(accountAddress, token);\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails, provider?: Provider): Promise<PoolInfo> {\n const poolKey: PoolKeyObject = { chainSymbol: token.chainSymbol, poolAddress: token.poolAddress };\n const fromCache = this.cache.get(poolKey);\n if (fromCache) {\n return fromCache;\n } else {\n const poolInfo = await getChainPoolService(\n token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).getPoolInfoFromChain(token);\n this.cache.put(poolKey, poolInfo);\n this.api.cachePut({ chainSymbol: token.chainSymbol, poolAddress: token.poolAddress }, poolInfo);\n return poolInfo;\n }\n }\n}\n\n/**\n * @deprecated Do not use.\n */\nexport function getChainPoolService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n params: AllbridgeCoreSdkOptions,\n provider?: Provider\n): ChainPoolService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmPoolService(provider as EssentialWeb3, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const web3 = new Web3(nodeRpcUrl);\n web3.defaultReturnFormat = { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX };\n return new EvmPoolService(web3, api);\n }\n }\n case ChainType.TRX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronJsonRpc = params.tronJsonRpc;\n if (provider) {\n return new TronPoolService(provider as TronWeb, api, tronJsonRpc);\n } else {\n const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });\n return new TronPoolService(tronWeb, api, tronJsonRpc);\n }\n }\n case ChainType.SOLANA: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new SolanaPoolService(nodeRpcUrl, api);\n }\n case ChainType.SRB: {\n return new SrbPoolService(nodeRpcUrlsConfig, params, api);\n }\n case ChainType.SUI: {\n return new SuiPoolService(nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol), params, api);\n }\n case ChainType.ALG: {\n if (provider) {\n const algod = provider as Algodv2;\n const algorand = AlgorandClient.fromClients({ algod });\n return new AlgPoolService(algorand, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const algorand = AlgorandClient.fromConfig({\n algodConfig: { server: nodeRpcUrl },\n });\n return new AlgPoolService(algorand, api);\n }\n }\n case ChainType.STX: {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n return new StxPoolService(nodeRpcUrl, params, api);\n }\n }\n}\n"]}
|
|
@@ -3,12 +3,20 @@ import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base";
|
|
|
3
3
|
import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
|
|
4
4
|
import { RawTransaction } from "../../models";
|
|
5
5
|
import { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "./pool.model";
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Do not use.
|
|
8
|
+
*/
|
|
6
9
|
export declare abstract class ChainPoolService {
|
|
7
10
|
abstract chainType: ChainType;
|
|
8
11
|
abstract api: AllbridgeCoreClient;
|
|
12
|
+
/** @deprecated Do not use. */
|
|
9
13
|
abstract getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo>;
|
|
14
|
+
/** @deprecated Do not use. */
|
|
10
15
|
abstract getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo>;
|
|
16
|
+
/** @deprecated Do not use. */
|
|
11
17
|
abstract buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;
|
|
18
|
+
/** @deprecated Do not use. */
|
|
12
19
|
abstract buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;
|
|
20
|
+
/** @deprecated Do not use. */
|
|
13
21
|
abstract buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction>;
|
|
14
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/models/pool.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,gBAAgB;
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/models/pool.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAgB,gBAAgB;CAkBrC","sourcesContent":["import { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { RawTransaction } from \"../../models\";\nimport { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from \"./pool.model\";\n\n/**\n * @deprecated Do not use.\n */\nexport abstract class ChainPoolService {\n abstract chainType: ChainType;\n abstract api: AllbridgeCoreClient;\n\n /** @deprecated Do not use. */\n abstract getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo>;\n\n /** @deprecated Do not use. */\n abstract getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo>;\n\n /** @deprecated Do not use. */\n abstract buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;\n\n /** @deprecated Do not use. */\n abstract buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction>;\n\n /** @deprecated Do not use. */\n abstract buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction>;\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Big } from "big.js";
|
|
2
2
|
import { FeePaymentMethod, TxFeeParams } from "../../../models";
|
|
3
3
|
import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Do not use.
|
|
6
|
+
*/
|
|
4
7
|
export interface ApproveParams {
|
|
5
8
|
/**
|
|
6
9
|
* The token info
|
|
@@ -17,18 +20,30 @@ export interface ApproveParams {
|
|
|
17
20
|
*/
|
|
18
21
|
amount?: string | number | Big;
|
|
19
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Do not use.
|
|
25
|
+
*/
|
|
20
26
|
export interface GetAllowanceParams {
|
|
21
27
|
token: TokenWithChainDetails;
|
|
22
28
|
owner: string;
|
|
23
29
|
gasFeePaymentMethod?: FeePaymentMethod;
|
|
24
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Do not use.
|
|
33
|
+
*/
|
|
25
34
|
export type GetAllowanceParamsDto = GetAllowanceParams;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Do not use.
|
|
37
|
+
*/
|
|
26
38
|
export interface CheckAllowanceParams extends GetAllowanceParams {
|
|
27
39
|
/**
|
|
28
40
|
* The float amount of tokens to check the allowance.
|
|
29
41
|
*/
|
|
30
42
|
amount: string | number | Big;
|
|
31
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Do not use.
|
|
46
|
+
*/
|
|
32
47
|
export interface LiquidityPoolsParams {
|
|
33
48
|
/**
|
|
34
49
|
* The account address to operate tokens with.
|
|
@@ -40,20 +55,32 @@ export interface LiquidityPoolsParams {
|
|
|
40
55
|
token: TokenWithChainDetails;
|
|
41
56
|
txFeeParams?: TxFeeParams;
|
|
42
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Do not use.
|
|
60
|
+
*/
|
|
43
61
|
export interface LiquidityPoolsParamsWithAmount extends LiquidityPoolsParams {
|
|
44
62
|
/**
|
|
45
63
|
* The float amount of tokens.
|
|
46
64
|
*/
|
|
47
65
|
amount: string;
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Do not use.
|
|
69
|
+
*/
|
|
49
70
|
export interface UserBalanceInfoDTO {
|
|
50
71
|
lpAmount: string;
|
|
51
72
|
rewardDebt: string;
|
|
52
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Do not use.
|
|
76
|
+
*/
|
|
53
77
|
export interface UserBalanceInfo extends UserBalanceInfoDTO {
|
|
54
78
|
userLiquidity: string;
|
|
55
79
|
earned(poolInfo: PoolInfo, decimals?: number): string;
|
|
56
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Do not use.
|
|
83
|
+
*/
|
|
57
84
|
export declare class UserBalance implements UserBalanceInfo {
|
|
58
85
|
lpAmount: string;
|
|
59
86
|
rewardDebt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.model.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/models/pool.model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"pool.model.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/models/pool.model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AA2FxE;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,QAAQ,CAAS;IACjB,UAAU,CAAS;IAEnB,YAAY,QAA4B;QACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACxC,CAAC;IAED,IAAI,aAAa;QACf,OAAO,uBAAuB,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,QAAkB,EAAE,QAAiB;QAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QAClG,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QAC7D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { Big } from \"big.js\";\nimport { FeePaymentMethod, TxFeeParams } from \"../../../models\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { convertIntAmountToFloat, getEarned } from \"../../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../../utils/calculation/constants\";\n\n/**\n * @deprecated Do not use.\n */\nexport interface ApproveParams {\n /**\n * The token info\n */\n token: TokenWithChainDetails;\n\n /**\n * The address of the token owner who is granting permission to use tokens\n */\n owner: string;\n\n /**\n * The integer amount of tokens to approve.\n * Optional.\n * The maximum amount by default.\n */\n amount?: string | number | Big;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport interface GetAllowanceParams {\n token: TokenWithChainDetails;\n owner: string;\n gasFeePaymentMethod?: FeePaymentMethod;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport type GetAllowanceParamsDto = GetAllowanceParams;\n\n/**\n * @deprecated Do not use.\n */\nexport interface CheckAllowanceParams extends GetAllowanceParams {\n /**\n * The float amount of tokens to check the allowance.\n */\n amount: string | number | Big;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport interface LiquidityPoolsParams {\n /**\n * The account address to operate tokens with.\n */\n accountAddress: string;\n /**\n * {@link TokenWithChainDetails |The token info object} of operation token.\n */\n token: TokenWithChainDetails;\n\n txFeeParams?: TxFeeParams;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport interface LiquidityPoolsParamsWithAmount extends LiquidityPoolsParams {\n /**\n * The float amount of tokens.\n */\n amount: string;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport interface UserBalanceInfoDTO {\n lpAmount: string;\n rewardDebt: string;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport interface UserBalanceInfo extends UserBalanceInfoDTO {\n userLiquidity: string;\n\n earned(poolInfo: PoolInfo, decimals?: number): string;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport class UserBalance implements UserBalanceInfo {\n lpAmount: string;\n rewardDebt: string;\n\n constructor(userInfo: UserBalanceInfoDTO) {\n this.lpAmount = userInfo.lpAmount;\n this.rewardDebt = userInfo.rewardDebt;\n }\n\n get userLiquidity(): string {\n return convertIntAmountToFloat(this.lpAmount, SYSTEM_PRECISION).toFixed();\n }\n\n earned(poolInfo: PoolInfo, decimals?: number): string {\n const earned = getEarned(this.lpAmount, this.rewardDebt, poolInfo.accRewardPerShareP, poolInfo.p);\n if (decimals) {\n return convertIntAmountToFloat(earned, decimals).toFixed();\n }\n return earned;\n }\n}\n"]}
|
|
@@ -4,37 +4,48 @@ import { AllbridgeCoreSdkOptions } from "../../index";
|
|
|
4
4
|
import { Provider, RawTransaction } from "../models";
|
|
5
5
|
import { TokenService } from "../token";
|
|
6
6
|
import { ApproveParams, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount } from "./models";
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Do not use.
|
|
9
|
+
*/
|
|
7
10
|
export interface RawPoolTransactionBuilder {
|
|
8
11
|
/**
|
|
9
12
|
* Creates a Raw Transaction for approving tokens usage by the bridge
|
|
10
13
|
* @param provider - will be used to access the network
|
|
11
14
|
* @param approveData
|
|
15
|
+
* @deprecated Do not use.
|
|
12
16
|
*/
|
|
13
17
|
approve(provider: Provider, approveData: ApproveParams): Promise<RawTransaction>;
|
|
14
18
|
/**
|
|
15
19
|
* Creates a Raw Transaction for approving tokens usage by the bridge
|
|
16
20
|
* @param approveData
|
|
21
|
+
* @deprecated Do not use.
|
|
17
22
|
*/
|
|
18
23
|
approve(approveData: ApproveParams): Promise<RawTransaction>;
|
|
19
24
|
/**
|
|
20
25
|
* Creates a Raw Transaction for depositing tokens to Liquidity pools
|
|
21
26
|
* @param params
|
|
22
27
|
* @param provider - will be used to access the network
|
|
28
|
+
* @deprecated Do not use.
|
|
23
29
|
*/
|
|
24
30
|
deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;
|
|
25
31
|
/**
|
|
26
32
|
* Creates a Raw Transaction for withdrawing tokens from Liquidity pools
|
|
27
33
|
* @param params
|
|
28
34
|
* @param provider - will be used to access the network
|
|
35
|
+
* @deprecated Do not use.
|
|
29
36
|
*/
|
|
30
37
|
withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;
|
|
31
38
|
/**
|
|
32
39
|
* Creates a Raw Transaction for claiming rewards from Liquidity pools
|
|
33
40
|
* @param params
|
|
34
41
|
* @param provider - will be used to access the network
|
|
42
|
+
* @deprecated Do not use.
|
|
35
43
|
*/
|
|
36
44
|
claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction>;
|
|
37
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Do not use.
|
|
48
|
+
*/
|
|
38
49
|
export declare class DefaultRawPoolTransactionBuilder implements RawPoolTransactionBuilder {
|
|
39
50
|
private api;
|
|
40
51
|
private nodeRpcUrlsConfig;
|
|
@@ -2,6 +2,9 @@ import { convertFloatAmountToInt } from "../../utils/calculation";
|
|
|
2
2
|
import { SYSTEM_PRECISION } from "../../utils/calculation/constants";
|
|
3
3
|
import { validateAmountDecimals, validateAmountGtZero } from "../../utils/utils";
|
|
4
4
|
import { getChainPoolService } from "./index";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Do not use.
|
|
7
|
+
*/
|
|
5
8
|
export class DefaultRawPoolTransactionBuilder {
|
|
6
9
|
api;
|
|
7
10
|
nodeRpcUrlsConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"raw-pool-transaction-builder.js","sourceRoot":"","sources":["../../../../src/services/liquidity-pool/raw-pool-transaction-builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA6C9C;;GAEG;AACH,MAAM,OAAO,gCAAgC;IAEjC;IACA;IACA;IACA;IAJV,YACU,GAAwB,EACxB,iBAAoC,EACpC,MAA+B,EAC/B,YA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MAAsC,EAAE,QAAmB;QACxE,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,OAAO,EAAE,CAAC;QACnF,OAAO,mBAAmB,CACxB,MAAM,CAAC,KAAK,CAAC,WAAW,EACxB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA4B,EAAE,QAAmB;QAClE,OAAO,mBAAmB,CACxB,MAAM,CAAC,KAAK,CAAC,WAAW,EACxB,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,MAAM,EACX,QAAQ,CACT,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import { NodeRpcUrlsConfig } from \"..\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions } from \"../../index\";\nimport { convertFloatAmountToInt } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { Provider, RawTransaction } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { ApproveParams, LiquidityPoolsParams, LiquidityPoolsParamsWithAmount } from \"./models\";\nimport { getChainPoolService } from \"./index\";\n\n/**\n * @deprecated Do not use.\n */\nexport interface RawPoolTransactionBuilder {\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param provider - will be used to access the network\n * @param approveData\n * @deprecated Do not use.\n */\n approve(provider: Provider, approveData: ApproveParams): Promise<RawTransaction>;\n /**\n * Creates a Raw Transaction for approving tokens usage by the bridge\n * @param approveData\n * @deprecated Do not use.\n */\n approve(approveData: ApproveParams): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for depositing tokens to Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n * @deprecated Do not use.\n */\n deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for withdrawing tokens from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n * @deprecated Do not use.\n */\n withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction>;\n\n /**\n * Creates a Raw Transaction for claiming rewards from Liquidity pools\n * @param params\n * @param provider - will be used to access the network\n * @deprecated Do not use.\n */\n claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction>;\n}\n\n/**\n * @deprecated Do not use.\n */\nexport class DefaultRawPoolTransactionBuilder implements RawPoolTransactionBuilder {\n constructor(\n private api: AllbridgeCoreClient,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {}\n\n async approve(a: Provider | ApproveParams, b?: ApproveParams): Promise<RawTransaction> {\n if (b) {\n const provider = a as Provider;\n const approveData: ApproveParams = b;\n return this.tokenService.buildRawTransactionApprove(\n {\n ...approveData,\n spender: approveData.token.poolAddress,\n },\n provider\n );\n } else {\n const approveData: ApproveParams = a as ApproveParams;\n return this.tokenService.buildRawTransactionApprove({\n ...approveData,\n spender: approveData.token.poolAddress,\n });\n }\n }\n\n async deposit(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, params.token.decimals).toFixed();\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionDeposit(params);\n }\n\n async withdraw(params: LiquidityPoolsParamsWithAmount, provider?: Provider): Promise<RawTransaction> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n params.amount = convertFloatAmountToInt(params.amount, SYSTEM_PRECISION).toFixed();\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionWithdraw(params);\n }\n\n async claimRewards(params: LiquidityPoolsParams, provider?: Provider): Promise<RawTransaction> {\n return getChainPoolService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n this.params,\n provider\n ).buildRawTransactionClaimRewards(params);\n }\n}\n"]}
|
|
@@ -4,6 +4,9 @@ import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info";
|
|
|
4
4
|
import { RawTransaction } from "../../models";
|
|
5
5
|
import { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "../models";
|
|
6
6
|
import { ChainPoolService } from "../models/pool";
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Do not use.
|
|
9
|
+
*/
|
|
7
10
|
export declare class SolanaPoolService extends ChainPoolService {
|
|
8
11
|
solanaRpcUrl: string;
|
|
9
12
|
api: AllbridgeCoreClient;
|
|
@@ -9,6 +9,9 @@ import { getAssociatedAccount, getAuthorityAccount, getBridgeTokenAccount, getCo
|
|
|
9
9
|
import { addUnitLimitAndUnitPriceToTx } from "../../utils/sol/compute-budget";
|
|
10
10
|
import { UserBalance } from "../models";
|
|
11
11
|
import { ChainPoolService } from "../models/pool";
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Do not use.
|
|
14
|
+
*/
|
|
12
15
|
export class SolanaPoolService extends ChainPoolService {
|
|
13
16
|
solanaRpcUrl;
|
|
14
17
|
api;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../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;QAED,MAAM,QAAQ,GAAe;YAC3B,IAAI,EAAE,gBAAgB;YACtB,IAAI;YACJ,MAAM,EAAE,aAAa;YACrB,IAAI,EAAE,WAAW;YACjB,eAAe,EAAE,eAAe;YAChC,WAAW,EAAE,kBAAkB;YAC/B,SAAS;YACT,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { AnchorProvider, BN, Program, Provider, web3 } from \"@coral-xyz/anchor\";\nimport { createAssociatedTokenAccountInstruction } from \"@solana/spl-token\";\nimport { Connection, PublicKey, TransactionInstruction } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { RawTransaction } from \"../../models\";\nimport { Bridge as BridgeType } from \"../../models/sol/types/bridge\";\nimport * as bridgeIdl from \"../../models/sol/types/bridge.json\";\nimport { getTokenAccountData } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getConfigAccount,\n getUserDepositAccount,\n} from \"../../utils/sol/accounts\";\nimport { addUnitLimitAndUnitPriceToTx } from \"../../utils/sol/compute-budget\";\nimport { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalance, UserBalanceInfo } from \"../models\";\nimport { ChainPoolService } from \"../models/pool\";\n\ninterface LPAccounts {\n mint: PublicKey;\n user: PublicKey;\n config: PublicKey;\n pool: PublicKey;\n bridgeAuthority: PublicKey;\n userDeposit: PublicKey;\n userToken: PublicKey;\n bridgeToken: PublicKey;\n}\n\ninterface LPTransactionData {\n accounts: LPAccounts;\n preInstructions: TransactionInstruction[];\n}\n\nexport class SolanaPoolService extends ChainPoolService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n private P = 48;\n\n constructor(\n public solanaRpcUrl: string,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n const provider = this.buildAnchorProvider(accountAddress);\n const bridge = this.getBridge(token.bridgeAddress, provider);\n const poolAccount = new PublicKey(token.poolAddress);\n const poolAccountInfo = await bridge.account.pool.fetch(poolAccount);\n try {\n const userDepositAccount = await getUserDepositAccount(\n new PublicKey(accountAddress),\n poolAccountInfo.mint,\n bridge.programId\n );\n const { lpAmount, rewardDebt } = await bridge.account.userDeposit.fetch(userDepositAccount);\n return new UserBalance({\n lpAmount: lpAmount.toString(),\n rewardDebt: rewardDebt.toString(),\n });\n } catch (ignoreError) {\n return new UserBalance({ lpAmount: \"0\", rewardDebt: \"0\" });\n }\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n const provider = this.buildAnchorProvider(token.bridgeAddress);\n const pool = await this.getBridge(token.bridgeAddress, provider).account.pool.fetch(token.poolAddress);\n const vUsdBalance = pool.vUsdBalance.toString();\n const tokenBalance = pool.tokenBalance.toString();\n const imbalance = calculatePoolInfoImbalance({ tokenBalance, vUsdBalance });\n return {\n dValue: pool.d.toString(),\n aValue: pool.a.toString(),\n totalLpAmount: pool.totalLpAmount.toString(),\n vUsdBalance,\n tokenBalance,\n accRewardPerShareP: pool.accRewardPerShareP.toString(),\n p: this.P,\n imbalance,\n };\n }\n\n async buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods\n .deposit(new BN(params.amount))\n .accounts(accounts)\n .preInstructions(preInstructions)\n .transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods\n .withdraw(new BN(params.amount))\n .accounts(accounts)\n .preInstructions(preInstructions)\n .transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods.claimRewards().accounts(accounts).preInstructions(preInstructions).transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n private async prepareDataForTransaction(params: LiquidityPoolsParams) {\n const provider = this.buildAnchorProvider(params.accountAddress);\n const bridge = this.getBridge(params.token.bridgeAddress, provider);\n\n const { accounts, preInstructions } = await this._getLPTransactionData(\n bridge,\n params.token.poolAddress,\n params.accountAddress,\n provider\n );\n return { bridge, accounts, preInstructions };\n }\n\n private getBridge(bridgeAddress: string, provider: Provider): Program<BridgeType> {\n return new Program<BridgeType>({ ...bridgeIdl, address: bridgeAddress }, provider);\n }\n\n private buildAnchorProvider(accountAddress: string): Provider {\n const connection = new Connection(this.solanaRpcUrl, \"confirmed\");\n\n const publicKey = new PublicKey(accountAddress);\n\n return new AnchorProvider(\n connection,\n // @ts-expect-error enough wallet for fetch actions\n { publicKey: publicKey },\n {\n preflightCommitment: \"confirmed\",\n commitment: \"confirmed\",\n }\n );\n }\n\n private async _getLPTransactionData(\n bridge: Program<BridgeType>,\n poolAddress: string,\n account: string,\n provider: Provider\n ): Promise<LPTransactionData> {\n const user = new PublicKey(account);\n const configAccount = await getConfigAccount(bridge.programId);\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const poolAccount = new PublicKey(poolAddress);\n const poolAccountInfo = await bridge.account.pool.fetch(poolAccount);\n const tokenMintAccount = poolAccountInfo.mint;\n const userToken = getAssociatedAccount(user, tokenMintAccount);\n const bridgeTokenAccount = await getBridgeTokenAccount(tokenMintAccount, bridge.programId);\n const userDepositAccount = await getUserDepositAccount(user, tokenMintAccount, bridge.programId);\n\n const preInstructions: TransactionInstruction[] = [\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: 1000000,\n }),\n ];\n\n try {\n await getTokenAccountData(userToken, provider);\n } catch (ignoreError) {\n const createUserTokenInstruction = createAssociatedTokenAccountInstruction(\n user,\n userToken,\n user,\n tokenMintAccount\n );\n preInstructions.push(createUserTokenInstruction);\n }\n\n try {\n await bridge.account.userDeposit.fetch(userDepositAccount);\n } catch (ignoreError) {\n const instruction: TransactionInstruction = await bridge.methods\n .initDepositAccount()\n .accountsPartial({\n mint: tokenMintAccount,\n user,\n userDeposit: userDepositAccount,\n })\n .instruction();\n preInstructions.push(instruction);\n }\n\n const accounts: LPAccounts = {\n mint: tokenMintAccount,\n user,\n config: configAccount,\n pool: poolAccount,\n bridgeAuthority: bridgeAuthority,\n userDeposit: userDepositAccount,\n userToken,\n bridgeToken: bridgeTokenAccount,\n };\n\n return { accounts, preInstructions };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/sol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAY,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,uCAAuC,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,SAAS,EAA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,CAAC;QAEF,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { AnchorProvider, BN, Program, Provider, web3 } from \"@coral-xyz/anchor\";\nimport { createAssociatedTokenAccountInstruction } from \"@solana/spl-token\";\nimport { Connection, PublicKey, TransactionInstruction } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { PoolInfo, TokenWithChainDetails } from \"../../../tokens-info\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { RawTransaction } from \"../../models\";\nimport { Bridge as BridgeType } from \"../../models/sol/types/bridge\";\nimport * as bridgeIdl from \"../../models/sol/types/bridge.json\";\nimport { getTokenAccountData } from \"../../utils/sol\";\nimport {\n getAssociatedAccount,\n getAuthorityAccount,\n getBridgeTokenAccount,\n getConfigAccount,\n getUserDepositAccount,\n} from \"../../utils/sol/accounts\";\nimport { addUnitLimitAndUnitPriceToTx } from \"../../utils/sol/compute-budget\";\nimport { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalance, UserBalanceInfo } from \"../models\";\nimport { ChainPoolService } from \"../models/pool\";\n\ninterface LPAccounts {\n mint: PublicKey;\n user: PublicKey;\n config: PublicKey;\n pool: PublicKey;\n bridgeAuthority: PublicKey;\n userDeposit: PublicKey;\n userToken: PublicKey;\n bridgeToken: PublicKey;\n}\n\ninterface LPTransactionData {\n accounts: LPAccounts;\n preInstructions: TransactionInstruction[];\n}\n\n/**\n * @deprecated Do not use.\n */\nexport class SolanaPoolService extends ChainPoolService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n private P = 48;\n\n constructor(\n public solanaRpcUrl: string,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n const provider = this.buildAnchorProvider(accountAddress);\n const bridge = this.getBridge(token.bridgeAddress, provider);\n const poolAccount = new PublicKey(token.poolAddress);\n const poolAccountInfo = await bridge.account.pool.fetch(poolAccount);\n try {\n const userDepositAccount = await getUserDepositAccount(\n new PublicKey(accountAddress),\n poolAccountInfo.mint,\n bridge.programId\n );\n const { lpAmount, rewardDebt } = await bridge.account.userDeposit.fetch(userDepositAccount);\n return new UserBalance({\n lpAmount: lpAmount.toString(),\n rewardDebt: rewardDebt.toString(),\n });\n } catch (ignoreError) {\n return new UserBalance({ lpAmount: \"0\", rewardDebt: \"0\" });\n }\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n const provider = this.buildAnchorProvider(token.bridgeAddress);\n const pool = await this.getBridge(token.bridgeAddress, provider).account.pool.fetch(token.poolAddress);\n const vUsdBalance = pool.vUsdBalance.toString();\n const tokenBalance = pool.tokenBalance.toString();\n const imbalance = calculatePoolInfoImbalance({ tokenBalance, vUsdBalance });\n return {\n dValue: pool.d.toString(),\n aValue: pool.a.toString(),\n totalLpAmount: pool.totalLpAmount.toString(),\n vUsdBalance,\n tokenBalance,\n accRewardPerShareP: pool.accRewardPerShareP.toString(),\n p: this.P,\n imbalance,\n };\n }\n\n async buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods\n .deposit(new BN(params.amount))\n .accounts(accounts)\n .preInstructions(preInstructions)\n .transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods\n .withdraw(new BN(params.amount))\n .accounts(accounts)\n .preInstructions(preInstructions)\n .transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const { bridge, accounts, preInstructions } = await this.prepareDataForTransaction(params);\n\n const tx = await bridge.methods.claimRewards().accounts(accounts).preInstructions(preInstructions).transaction();\n tx.recentBlockhash = (\n await this.buildAnchorProvider(params.accountAddress).connection.getLatestBlockhash()\n ).blockhash;\n tx.feePayer = new PublicKey(params.accountAddress);\n await addUnitLimitAndUnitPriceToTx(tx, params.txFeeParams, this.solanaRpcUrl);\n return tx;\n }\n\n private async prepareDataForTransaction(params: LiquidityPoolsParams) {\n const provider = this.buildAnchorProvider(params.accountAddress);\n const bridge = this.getBridge(params.token.bridgeAddress, provider);\n\n const { accounts, preInstructions } = await this._getLPTransactionData(\n bridge,\n params.token.poolAddress,\n params.accountAddress,\n provider\n );\n return { bridge, accounts, preInstructions };\n }\n\n private getBridge(bridgeAddress: string, provider: Provider): Program<BridgeType> {\n return new Program<BridgeType>({ ...bridgeIdl, address: bridgeAddress }, provider);\n }\n\n private buildAnchorProvider(accountAddress: string): Provider {\n const connection = new Connection(this.solanaRpcUrl, \"confirmed\");\n\n const publicKey = new PublicKey(accountAddress);\n\n return new AnchorProvider(\n connection,\n // @ts-expect-error enough wallet for fetch actions\n { publicKey: publicKey },\n {\n preflightCommitment: \"confirmed\",\n commitment: \"confirmed\",\n }\n );\n }\n\n private async _getLPTransactionData(\n bridge: Program<BridgeType>,\n poolAddress: string,\n account: string,\n provider: Provider\n ): Promise<LPTransactionData> {\n const user = new PublicKey(account);\n const configAccount = await getConfigAccount(bridge.programId);\n const bridgeAuthority = await getAuthorityAccount(bridge.programId);\n const poolAccount = new PublicKey(poolAddress);\n const poolAccountInfo = await bridge.account.pool.fetch(poolAccount);\n const tokenMintAccount = poolAccountInfo.mint;\n const userToken = getAssociatedAccount(user, tokenMintAccount);\n const bridgeTokenAccount = await getBridgeTokenAccount(tokenMintAccount, bridge.programId);\n const userDepositAccount = await getUserDepositAccount(user, tokenMintAccount, bridge.programId);\n\n const preInstructions: TransactionInstruction[] = [\n web3.ComputeBudgetProgram.setComputeUnitLimit({\n units: 1000000,\n }),\n ];\n\n try {\n await getTokenAccountData(userToken, provider);\n } catch (ignoreError) {\n const createUserTokenInstruction = createAssociatedTokenAccountInstruction(\n user,\n userToken,\n user,\n tokenMintAccount\n );\n preInstructions.push(createUserTokenInstruction);\n }\n\n try {\n await bridge.account.userDeposit.fetch(userDepositAccount);\n } catch (ignoreError) {\n const instruction: TransactionInstruction = await bridge.methods\n .initDepositAccount()\n .accountsPartial({\n mint: tokenMintAccount,\n user,\n userDeposit: userDepositAccount,\n })\n .instruction();\n preInstructions.push(instruction);\n }\n\n const accounts: LPAccounts = {\n mint: tokenMintAccount,\n user,\n config: configAccount,\n pool: poolAccount,\n bridgeAuthority: bridgeAuthority,\n userDeposit: userDepositAccount,\n userToken,\n bridgeToken: bridgeTokenAccount,\n };\n\n return { accounts, preInstructions };\n }\n}\n"]}
|
|
@@ -4,6 +4,9 @@ import { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, PoolInfo, TokenWi
|
|
|
4
4
|
import { NodeRpcUrlsConfig } from "../../index";
|
|
5
5
|
import { RawTransaction } from "../../models";
|
|
6
6
|
import { ChainPoolService } from "../models";
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Do not use.
|
|
9
|
+
*/
|
|
7
10
|
export declare class SrbPoolService extends ChainPoolService {
|
|
8
11
|
readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig;
|
|
9
12
|
readonly params: AllbridgeCoreSdkOptions;
|
|
@@ -4,6 +4,9 @@ import { calculatePoolInfoImbalance } from "../../../utils/calculation";
|
|
|
4
4
|
import { PoolContract } from "../../models/srb/pool-contract";
|
|
5
5
|
import { getSorobanInclusionFee, getViewResultSoroban, isErrorSorobanResult } from "../../models/srb/utils";
|
|
6
6
|
import { ChainPoolService, UserBalance } from "../models";
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Do not use.
|
|
9
|
+
*/
|
|
7
10
|
export class SrbPoolService extends ChainPoolService {
|
|
8
11
|
nodeRpcUrlsConfig;
|
|
9
12
|
params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/srb/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAIL,QAAQ,GAGT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG1D,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAKvC;IACA;IACA;IANX,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IACjC,CAAC,GAAG,EAAE,CAAC;IAEf,YACW,iBAAoC,EACpC,MAA+B,EAC/B,GAAwB;QAEjC,KAAK,EAAE,CAAC;QAJC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;IAGnC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,cAAsB,EAAE,KAA4B;QAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC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AAC,MAAM,CAAC,MAAM,CAAC;SACjC,EACD,EAAE,GAAG,EAAE,YAAY,EAAE,CACtB,CACF,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,+BAA+B,CAAC,MAA4B;QAChE,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;QACvF,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACzG,OAAO,CACL,MAAM,YAAY,CAAC,aAAa,CAC9B;YACE,MAAM,EAAE,MAAM,CAAC,cAAc;SAC9B,EACD,EAAE,GAAG,EAAE,YAAY,EAAE,CACtB,CACF,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAEO,WAAW,CAAC,OAAe,EAAE,MAAe;QAClD,MAAM,MAAM,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import { contract } from \"@stellar/stellar-sdk\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType } from \"../../../index\";\nimport {\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n PoolInfo,\n SdkError,\n TokenWithChainDetails,\n UserBalanceInfo,\n} from \"../../../models\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport { PoolContract } from \"../../models/srb/pool-contract\";\nimport { getSorobanInclusionFee, getViewResultSoroban, isErrorSorobanResult } from \"../../models/srb/utils\";\nimport { ChainPoolService, UserBalance } from \"../models\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbPoolService extends ChainPoolService {\n chainType: ChainType.SRB = ChainType.SRB;\n private P = 48;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n const poolContract = this.getContract(token.poolAddress);\n const result = await poolContract.get_user_deposit({ user: accountAddress });\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const viewResultSoroban = getViewResultSoroban(result);\n if (!viewResultSoroban) {\n throw new SdkError();\n }\n\n const userDeposit = viewResultSoroban.unwrap();\n return new UserBalance({\n lpAmount: userDeposit.lp_amount.toString(),\n rewardDebt: userDeposit.reward_debt.toString(),\n });\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n const poolContract = this.getContract(token.poolAddress);\n const result = await poolContract.get_pool();\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const viewResultSoroban = getViewResultSoroban(result);\n if (!viewResultSoroban) {\n throw new SdkError();\n }\n\n const pool = viewResultSoroban.unwrap();\n return {\n aValue: pool.a.toString(),\n accRewardPerShareP: pool.acc_reward_per_share_p.toString(),\n dValue: pool.d.toString(),\n tokenBalance: pool.token_balance.toString(),\n p: this.P,\n totalLpAmount: pool.total_lp_amount.toString(),\n vUsdBalance: pool.v_usd_balance.toString(),\n imbalance: calculatePoolInfoImbalance({\n tokenBalance: pool.token_balance.toString(),\n vUsdBalance: pool.v_usd_balance.toString(),\n }),\n };\n }\n\n async buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.deposit(\n {\n sender: params.accountAddress,\n amount: BigInt(params.amount),\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.withdraw(\n {\n sender: params.accountAddress,\n amount_lp: BigInt(params.amount),\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.claim_rewards(\n {\n sender: params.accountAddress,\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n private getContract(address: string, sender?: string): PoolContract {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new PoolContract(config);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/srb/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAIL,QAAQ,GAGT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,E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,GAA0B;YACpC,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import { contract } from \"@stellar/stellar-sdk\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions, ChainSymbol, ChainType } from \"../../../index\";\nimport {\n LiquidityPoolsParams,\n LiquidityPoolsParamsWithAmount,\n PoolInfo,\n SdkError,\n TokenWithChainDetails,\n UserBalanceInfo,\n} from \"../../../models\";\nimport { calculatePoolInfoImbalance } from \"../../../utils/calculation\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport { PoolContract } from \"../../models/srb/pool-contract\";\nimport { getSorobanInclusionFee, getViewResultSoroban, isErrorSorobanResult } from \"../../models/srb/utils\";\nimport { ChainPoolService, UserBalance } from \"../models\";\nimport ContractClientOptions = contract.ClientOptions;\n\n/**\n * @deprecated Do not use.\n */\nexport class SrbPoolService extends ChainPoolService {\n chainType: ChainType.SRB = ChainType.SRB;\n private P = 48;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise<UserBalanceInfo> {\n const poolContract = this.getContract(token.poolAddress);\n const result = await poolContract.get_user_deposit({ user: accountAddress });\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const viewResultSoroban = getViewResultSoroban(result);\n if (!viewResultSoroban) {\n throw new SdkError();\n }\n\n const userDeposit = viewResultSoroban.unwrap();\n return new UserBalance({\n lpAmount: userDeposit.lp_amount.toString(),\n rewardDebt: userDeposit.reward_debt.toString(),\n });\n }\n\n async getPoolInfoFromChain(token: TokenWithChainDetails): Promise<PoolInfo> {\n const poolContract = this.getContract(token.poolAddress);\n const result = await poolContract.get_pool();\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const viewResultSoroban = getViewResultSoroban(result);\n if (!viewResultSoroban) {\n throw new SdkError();\n }\n\n const pool = viewResultSoroban.unwrap();\n return {\n aValue: pool.a.toString(),\n accRewardPerShareP: pool.acc_reward_per_share_p.toString(),\n dValue: pool.d.toString(),\n tokenBalance: pool.token_balance.toString(),\n p: this.P,\n totalLpAmount: pool.total_lp_amount.toString(),\n vUsdBalance: pool.v_usd_balance.toString(),\n imbalance: calculatePoolInfoImbalance({\n tokenBalance: pool.token_balance.toString(),\n vUsdBalance: pool.v_usd_balance.toString(),\n }),\n };\n }\n\n async buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.deposit(\n {\n sender: params.accountAddress,\n amount: BigInt(params.amount),\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.withdraw(\n {\n sender: params.accountAddress,\n amount_lp: BigInt(params.amount),\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await poolContract.claim_rewards(\n {\n sender: params.accountAddress,\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n private getContract(address: string, sender?: string): PoolContract {\n const config: ContractClientOptions = {\n publicKey: sender,\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new PoolContract(config);\n }\n}\n"]}
|