@allbridge/bridge-core-sdk 3.21.0 → 3.21.1-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 +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +4 -4
- package/dist/src/client/core-api/core-api.model.d.ts +4 -0
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/services/liquidity-pool/srb/index.js +15 -6
- package/dist/src/services/liquidity-pool/srb/index.js.map +1 -1
- package/dist/src/utils/srb/index.js +19 -4
- package/dist/src/utils/srb/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 +1 -1
|
@@ -91,6 +91,8 @@ export interface TransferStatusResponse {
|
|
|
91
91
|
stableFeeFormatted: number;
|
|
92
92
|
sourceTokenAddress: string;
|
|
93
93
|
destinationTokenAddress: string;
|
|
94
|
+
originSourceTokenAddress?: string;
|
|
95
|
+
originDestinationTokenAddress?: string;
|
|
94
96
|
senderAddress: string;
|
|
95
97
|
recipientAddress: string;
|
|
96
98
|
signaturesCount: number;
|
|
@@ -115,6 +117,8 @@ export interface BridgeTransaction {
|
|
|
115
117
|
recipient: string;
|
|
116
118
|
sourceTokenAddress: string;
|
|
117
119
|
destinationTokenAddress: string;
|
|
120
|
+
originSourceTokenAddress?: string;
|
|
121
|
+
originDestinationTokenAddress?: string;
|
|
118
122
|
hash: string;
|
|
119
123
|
messenger: Messenger;
|
|
120
124
|
blockTime: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-api.model.js","sourceRoot":"","sources":["../../../../src/client/core-api/core-api.model.ts"],"names":[],"mappings":";;;AAeA,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,0BAAS,CAAA;IACT,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,gDAA+B,CAAA;IAC/B,sDAAqC,CAAA;IACrC,kFAAiE,CAAA;AACnE,CAAC,EAPW,aAAa,6BAAb,aAAa,QAOxB;AA8BD,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,wCAAqB,CAAA;IACrB,gCAAa,CAAA;AACf,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAcD,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,mDAAa,CAAA;IACb,iDAAY,CAAA;IACZ,yCAAQ,CAAA;AACV,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB","sourcesContent":["import { ChainSymbol } from \"../../chains/chain.enums\";\nimport { PoolInfo, SuiAddresses } from \"../../tokens-info\";\n\nexport type ChainDetailsResponse = Record<string, ChainDetailsDTO>;\n\nexport interface ChainDetailsDTO {\n tokens: TokenDTO[];\n chainId: number;\n bridgeAddress: string;\n transferTime: TransferTimeDTO;\n txCostAmount: TxCostAmountDTO;\n confirmations: number;\n suiAddresses?: SuiAddresses;\n}\n\nexport enum AddressStatus {\n OK = \"OK\",\n INVALID = \"INVALID\",\n FORBIDDEN = \"FORBIDDEN\",\n UNINITIALIZED = \"UNINITIALIZED\",\n CONTRACT_ADDRESS = \"CONTRACT_ADDRESS\",\n WRONG_ASSOCIATED_ACCOUNT_OWNER = \"WRONG_ASSOCIATED_ACCOUNT_OWNER\",\n}\n\nexport interface TokenDTO {\n symbol: string;\n name: string;\n decimals: number;\n poolAddress: string;\n tokenAddress: string;\n poolInfo: PoolInfoDTO;\n feeShare: string;\n apr: string;\n apr7d: string;\n apr30d: string;\n lpRate: string;\n flags: {\n swap: boolean;\n pool: boolean;\n };\n}\n\nexport interface PoolInfoDTO {\n aValue: string;\n dValue: string;\n tokenBalance: string;\n vUsdBalance: string;\n totalLpAmount: string;\n accRewardPerShareP: string;\n p: number;\n}\n\nexport enum MessengerKeyDTO {\n ALLBRIDGE = \"allbridge\",\n WORMHOLE = \"wormhole\",\n CCTP = \"cctp\",\n}\n\nexport type TransferTimeDTO = Record<string, MessengerTransferTimeDTO>;\n\nexport interface TxCostAmountDTO {\n maxAmount: string;\n swap: string;\n transfer: string;\n}\n\nexport type MessengerTransferTimeDTO = {\n [messenger in MessengerKeyDTO]: number;\n};\n\nexport enum Messenger {\n ALLBRIDGE = 1,\n WORMHOLE = 2,\n CCTP = 3,\n}\n\nexport interface ReceiveTransactionCostRequest {\n sourceChainId: number;\n destinationChainId: number;\n messenger: Messenger;\n}\n\nexport interface ReceiveTransactionCostResponse {\n exchangeRate: string;\n fee: string;\n sourceNativeTokenPrice: string;\n}\n\nexport interface GasBalanceResponse {\n gasBalance: string | null;\n status: AddressStatus;\n}\n\nexport interface CheckAddressResponse {\n gasBalance: string | null;\n status: AddressStatus;\n}\n\nexport interface TransferStatusResponse {\n txId: string;\n\n sourceChainSymbol: ChainSymbol;\n destinationChainSymbol: ChainSymbol;\n\n sendAmount: string;\n sendAmountFormatted: number;\n\n stableFee: string;\n stableFeeFormatted: number;\n\n sourceTokenAddress: string;\n destinationTokenAddress: string;\n\n senderAddress: string;\n recipientAddress: string;\n\n signaturesCount: number;\n signaturesNeeded: number;\n\n send: BridgeTransaction;\n receive?: BridgeTransaction;\n\n responseTime?: number;\n}\n\nexport interface BridgeTransaction {\n txId: string;\n\n sourceChainId: number;\n destinationChainId: number;\n\n fee: string;\n feeFormatted: number;\n\n stableFee: string;\n stableFeeFormatted: number;\n\n amount: string;\n amountFormatted: number;\n virtualAmount: string;\n\n bridgeContract: string;\n sender: string;\n recipient: string;\n\n sourceTokenAddress: string;\n destinationTokenAddress: string;\n\n hash: string;\n\n messenger: Messenger;\n\n blockTime: number;\n blockId: string;\n\n confirmations: number;\n confirmationsNeeded: number;\n\n isClaimable?: boolean;\n}\n\nexport type PoolInfoResponse = Record<ChainSymbol, PoolInfo>;\nexport type PendingInfoResponse = Partial<Record<ChainSymbol, TokenPendingInfoDTO>>;\nexport type TokenPendingInfoDTO = Record<string, PendingInfoDTO>;\n\nexport interface PendingInfoDTO {\n pendingTxs: number;\n totalSentAmount: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"core-api.model.js","sourceRoot":"","sources":["../../../../src/client/core-api/core-api.model.ts"],"names":[],"mappings":";;;AAeA,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,0BAAS,CAAA;IACT,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,gDAA+B,CAAA;IAC/B,sDAAqC,CAAA;IACrC,kFAAiE,CAAA;AACnE,CAAC,EAPW,aAAa,6BAAb,aAAa,QAOxB;AA8BD,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,wCAAqB,CAAA;IACrB,gCAAa,CAAA;AACf,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAcD,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,mDAAa,CAAA;IACb,iDAAY,CAAA;IACZ,yCAAQ,CAAA;AACV,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB","sourcesContent":["import { ChainSymbol } from \"../../chains/chain.enums\";\nimport { PoolInfo, SuiAddresses } from \"../../tokens-info\";\n\nexport type ChainDetailsResponse = Record<string, ChainDetailsDTO>;\n\nexport interface ChainDetailsDTO {\n tokens: TokenDTO[];\n chainId: number;\n bridgeAddress: string;\n transferTime: TransferTimeDTO;\n txCostAmount: TxCostAmountDTO;\n confirmations: number;\n suiAddresses?: SuiAddresses;\n}\n\nexport enum AddressStatus {\n OK = \"OK\",\n INVALID = \"INVALID\",\n FORBIDDEN = \"FORBIDDEN\",\n UNINITIALIZED = \"UNINITIALIZED\",\n CONTRACT_ADDRESS = \"CONTRACT_ADDRESS\",\n WRONG_ASSOCIATED_ACCOUNT_OWNER = \"WRONG_ASSOCIATED_ACCOUNT_OWNER\",\n}\n\nexport interface TokenDTO {\n symbol: string;\n name: string;\n decimals: number;\n poolAddress: string;\n tokenAddress: string;\n poolInfo: PoolInfoDTO;\n feeShare: string;\n apr: string;\n apr7d: string;\n apr30d: string;\n lpRate: string;\n flags: {\n swap: boolean;\n pool: boolean;\n };\n}\n\nexport interface PoolInfoDTO {\n aValue: string;\n dValue: string;\n tokenBalance: string;\n vUsdBalance: string;\n totalLpAmount: string;\n accRewardPerShareP: string;\n p: number;\n}\n\nexport enum MessengerKeyDTO {\n ALLBRIDGE = \"allbridge\",\n WORMHOLE = \"wormhole\",\n CCTP = \"cctp\",\n}\n\nexport type TransferTimeDTO = Record<string, MessengerTransferTimeDTO>;\n\nexport interface TxCostAmountDTO {\n maxAmount: string;\n swap: string;\n transfer: string;\n}\n\nexport type MessengerTransferTimeDTO = {\n [messenger in MessengerKeyDTO]: number;\n};\n\nexport enum Messenger {\n ALLBRIDGE = 1,\n WORMHOLE = 2,\n CCTP = 3,\n}\n\nexport interface ReceiveTransactionCostRequest {\n sourceChainId: number;\n destinationChainId: number;\n messenger: Messenger;\n}\n\nexport interface ReceiveTransactionCostResponse {\n exchangeRate: string;\n fee: string;\n sourceNativeTokenPrice: string;\n}\n\nexport interface GasBalanceResponse {\n gasBalance: string | null;\n status: AddressStatus;\n}\n\nexport interface CheckAddressResponse {\n gasBalance: string | null;\n status: AddressStatus;\n}\n\nexport interface TransferStatusResponse {\n txId: string;\n\n sourceChainSymbol: ChainSymbol;\n destinationChainSymbol: ChainSymbol;\n\n sendAmount: string;\n sendAmountFormatted: number;\n\n stableFee: string;\n stableFeeFormatted: number;\n\n sourceTokenAddress: string;\n destinationTokenAddress: string;\n\n originSourceTokenAddress?: string;\n originDestinationTokenAddress?: string;\n\n senderAddress: string;\n recipientAddress: string;\n\n signaturesCount: number;\n signaturesNeeded: number;\n\n send: BridgeTransaction;\n receive?: BridgeTransaction;\n\n responseTime?: number;\n}\n\nexport interface BridgeTransaction {\n txId: string;\n\n sourceChainId: number;\n destinationChainId: number;\n\n fee: string;\n feeFormatted: number;\n\n stableFee: string;\n stableFeeFormatted: number;\n\n amount: string;\n amountFormatted: number;\n virtualAmount: string;\n\n bridgeContract: string;\n sender: string;\n recipient: string;\n\n sourceTokenAddress: string;\n destinationTokenAddress: string;\n\n originSourceTokenAddress?: string;\n originDestinationTokenAddress?: string;\n\n hash: string;\n\n messenger: Messenger;\n\n blockTime: number;\n blockId: string;\n\n confirmations: number;\n confirmationsNeeded: number;\n\n isClaimable?: boolean;\n}\n\nexport type PoolInfoResponse = Record<ChainSymbol, PoolInfo>;\nexport type PendingInfoResponse = Partial<Record<ChainSymbol, TokenPendingInfoDTO>>;\nexport type TokenPendingInfoDTO = Record<string, PendingInfoDTO>;\n\nexport interface PendingInfoDTO {\n pendingTxs: number;\n totalSentAmount: string;\n}\n"]}
|
|
@@ -5,6 +5,7 @@ const index_1 = require("../../../index");
|
|
|
5
5
|
const models_1 = require("../../../models");
|
|
6
6
|
const calculation_1 = require("../../../utils/calculation");
|
|
7
7
|
const pool_contract_1 = require("../../models/srb/pool-contract");
|
|
8
|
+
const utils_1 = require("../../models/srb/utils");
|
|
8
9
|
const models_2 = require("../models");
|
|
9
10
|
class SrbPoolService extends models_2.ChainPoolService {
|
|
10
11
|
nodeRpcUrlsConfig;
|
|
@@ -20,11 +21,15 @@ class SrbPoolService extends models_2.ChainPoolService {
|
|
|
20
21
|
}
|
|
21
22
|
async getUserBalanceInfo(accountAddress, token) {
|
|
22
23
|
const poolContract = this.getContract(token.poolAddress);
|
|
23
|
-
const result =
|
|
24
|
-
if (
|
|
24
|
+
const result = await poolContract.get_user_deposit({ user: accountAddress });
|
|
25
|
+
if ((0, utils_1.isErrorSorobanResult)(result)) {
|
|
25
26
|
throw new models_1.SdkError();
|
|
26
27
|
}
|
|
27
|
-
const
|
|
28
|
+
const viewResultSoroban = (0, utils_1.getViewResultSoroban)(result);
|
|
29
|
+
if (!viewResultSoroban) {
|
|
30
|
+
throw new models_1.SdkError();
|
|
31
|
+
}
|
|
32
|
+
const userDeposit = viewResultSoroban.unwrap();
|
|
28
33
|
return new models_2.UserBalance({
|
|
29
34
|
lpAmount: userDeposit.lp_amount.toString(),
|
|
30
35
|
rewardDebt: userDeposit.reward_debt.toString(),
|
|
@@ -32,11 +37,15 @@ class SrbPoolService extends models_2.ChainPoolService {
|
|
|
32
37
|
}
|
|
33
38
|
async getPoolInfoFromChain(token) {
|
|
34
39
|
const poolContract = this.getContract(token.poolAddress);
|
|
35
|
-
const result =
|
|
36
|
-
if (
|
|
40
|
+
const result = await poolContract.get_pool();
|
|
41
|
+
if ((0, utils_1.isErrorSorobanResult)(result)) {
|
|
42
|
+
throw new models_1.SdkError();
|
|
43
|
+
}
|
|
44
|
+
const viewResultSoroban = (0, utils_1.getViewResultSoroban)(result);
|
|
45
|
+
if (!viewResultSoroban) {
|
|
37
46
|
throw new models_1.SdkError();
|
|
38
47
|
}
|
|
39
|
-
const pool =
|
|
48
|
+
const pool = viewResultSoroban.unwrap();
|
|
40
49
|
return {
|
|
41
50
|
aValue: pool.a.toString(),
|
|
42
51
|
accRewardPerShareP: pool.acc_reward_per_share_p.toString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/liquidity-pool/srb/index.ts"],"names":[],"mappings":";;;AAEA,0CAAiF;AACjF,4CAOyB;AACzB,4DAAwE;AAGxE,kEAA8D;AAC9D,sCAA0D;AAG1D,MAAa,cAAe,SAAQ,yBAAgB;IAKvC;IACA;IACA;IANX,SAAS,GAAkB,iBAAS,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,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";\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 { 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 return (\n await poolContract.deposit({\n sender: params.accountAddress,\n amount: BigInt(params.amount),\n })\n ).toXDR();\n }\n\n async buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n return (\n await poolContract.withdraw({\n sender: params.accountAddress,\n amount_lp: BigInt(params.amount),\n })\n ).toXDR();\n }\n\n async buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise<RawTransaction> {\n const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);\n return (\n await poolContract.claim_rewards({\n sender: params.accountAddress,\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"]}
|
|
@@ -5,7 +5,8 @@ const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
|
5
5
|
const chain_enums_1 = require("../../chains/chain.enums");
|
|
6
6
|
const index_1 = require("../../index");
|
|
7
7
|
const token_contract_1 = require("../../services/models/srb/token-contract");
|
|
8
|
-
const utils_1 = require("
|
|
8
|
+
const utils_1 = require("../../services/models/srb/utils");
|
|
9
|
+
const utils_2 = require("../utils");
|
|
9
10
|
const FEE = 100;
|
|
10
11
|
const SEND_TRANSACTION_TIMEOUT = 180;
|
|
11
12
|
class DefaultSrbUtils {
|
|
@@ -19,7 +20,14 @@ class DefaultSrbUtils {
|
|
|
19
20
|
const stellar = new stellar_sdk_1.Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(chain_enums_1.ChainSymbol.STLR));
|
|
20
21
|
const stellarAccount = await stellar.loadAccount(params.sender);
|
|
21
22
|
const tokenContract = this.getContract(token_contract_1.TokenContract, params.tokenAddress);
|
|
22
|
-
const
|
|
23
|
+
const result = await tokenContract.name();
|
|
24
|
+
if ((0, utils_1.isErrorSorobanResult)(result)) {
|
|
25
|
+
throw new index_1.SdkError();
|
|
26
|
+
}
|
|
27
|
+
const tokenName = (0, utils_1.getViewResultSoroban)(result);
|
|
28
|
+
if (!tokenName) {
|
|
29
|
+
throw new index_1.SdkError();
|
|
30
|
+
}
|
|
23
31
|
const [symbol, srbTokenAddress] = tokenName.split(":");
|
|
24
32
|
if (symbol === undefined || srbTokenAddress === undefined) {
|
|
25
33
|
throw new index_1.SdkError(`Invalid token name format. Expected format 'symbol:srbTokenAddress'`);
|
|
@@ -40,7 +48,14 @@ class DefaultSrbUtils {
|
|
|
40
48
|
}
|
|
41
49
|
async getBalanceLine(sender, tokenAddress) {
|
|
42
50
|
const tokenContract = this.getContract(token_contract_1.TokenContract, tokenAddress);
|
|
43
|
-
const
|
|
51
|
+
const result = await tokenContract.name();
|
|
52
|
+
if ((0, utils_1.isErrorSorobanResult)(result)) {
|
|
53
|
+
throw new index_1.SdkError();
|
|
54
|
+
}
|
|
55
|
+
const tokenName = (0, utils_1.getViewResultSoroban)(result);
|
|
56
|
+
if (!tokenName) {
|
|
57
|
+
throw new index_1.SdkError();
|
|
58
|
+
}
|
|
44
59
|
const [symbol, srbTokenAddress] = tokenName.split(":");
|
|
45
60
|
const nodeRpcUrl = this.nodeRpcUrlsConfig.getNodeRpcUrl(chain_enums_1.ChainSymbol.STLR);
|
|
46
61
|
const stellar = new stellar_sdk_1.Horizon.Server(nodeRpcUrl);
|
|
@@ -80,7 +95,7 @@ class DefaultSrbUtils {
|
|
|
80
95
|
}
|
|
81
96
|
async confirmTx(hash, secondsToWait = 15) {
|
|
82
97
|
const server = new stellar_sdk_1.rpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(chain_enums_1.ChainSymbol.SRB));
|
|
83
|
-
const getTransactionResponseAll = await (0,
|
|
98
|
+
const getTransactionResponseAll = await (0, utils_2.withExponentialBackoff)(() => server.getTransaction(hash), (resp) => resp.status === stellar_sdk_1.rpc.Api.GetTransactionStatus.NOT_FOUND, secondsToWait);
|
|
84
99
|
if (getTransactionResponseAll.length === 0) {
|
|
85
100
|
throw new index_1.SdkError("No transaction responses found.");
|
|
86
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAY8B;AAC9B,0DAAuD;AACvD,uCAAgE;AAEhE,6EAAyE;AACzE,oCAAkD;AAyDlD,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAa,eAAe;IAEf;IACA;IAFX,YACW,iBAAoC,EACpC,MAA+B;QAD/B,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;IACvC,CAAC;IAEJ,KAAK,CAAC,yBAAyB,CAAC,MAAuB;QACrD,MAAM,OAAO,GAAG,IAAI,qBAAO,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3F,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChE,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,8BAAa,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QAC3E,MAAM,SAAS,GAAG,CAAC,MAAM,aAAa,CAAC,I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B,CAAC,SAAS,EACvE,aAAa,CACd,CAAC;QAEF,IAAI,yBAAyB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,gBAAQ,CAAC,iCAAiC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,YAAY,GAAG,yBAAyB,CAAC,yBAAyB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACrF,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,gBAAQ,CAAC,+CAA+C,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe;QACtF,MAAM,MAAM,GAA0B;YACpC,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA9GD,0CA8GC","sourcesContent":["import {\n Asset as StellarAsset,\n BASE_FEE,\n contract,\n Horizon,\n Operation,\n Operation as StellarOperation,\n rpc as SorobanRpc,\n TimeoutInfinite,\n Transaction,\n TransactionBuilder,\n TransactionBuilder as StellarTransactionBuilder,\n} from \"@stellar/stellar-sdk\";\nimport { ChainSymbol } from \"../../chains/chain.enums\";\nimport { AllbridgeCoreSdkOptions, SdkError } from \"../../index\";\nimport { NodeRpcUrlsConfig } from \"../../services\";\nimport { TokenContract } from \"../../services/models/srb/token-contract\";\nimport { withExponentialBackoff } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\nimport BalanceLineAsset = Horizon.HorizonApi.BalanceLineAsset;\n\n/**\n * Contains usefully Soroban methods\n */\nexport interface SrbUtils {\n /**\n * Build change Trust line Tx\n * @param params see {@link TrustLineParams}\n * @returns xdr Tx\n */\n buildChangeTrustLineXdrTx(params: TrustLineParams): Promise<string>;\n\n /**\n * Get Balance Line information if exists\n * @param sender\n * @param tokenAddress\n */\n getBalanceLine(sender: string, tokenAddress: string): Promise<Horizon.HorizonApi.BalanceLineAsset | undefined>;\n\n /**\n * Submit tx\n * @param xdrTx\n */\n submitTransactionStellar(xdrTx: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;\n\n /**\n * Simulate and check if Restore needed\n * @param xdrTx - restore\n * @param sourceAccount\n * @returns xdrTx restore transaction if it required after check\n */\n simulateAndCheckRestoreTxRequiredSoroban(xdrTx: string, sourceAccount: string): Promise<string | undefined>;\n\n /**\n * Submit tx\n * @param xdrTx\n */\n sendTransactionSoroban(xdrTx: string): Promise<SorobanRpc.Api.SendTransactionResponse>;\n\n /**\n * Confirm tx\n */\n confirmTx(hash: string, secondsToWait?: number): Promise<SorobanRpc.Api.GetTransactionResponse>;\n}\n\nexport interface TrustLineParams {\n /**\n * Float amount of tokens, default is Number.MAX_SAFE_INTEGER\n */\n limit?: string;\n sender: string;\n tokenAddress: string;\n}\n\nconst FEE = 100;\nconst SEND_TRANSACTION_TIMEOUT = 180;\n\nexport class DefaultSrbUtils implements SrbUtils {\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions\n ) {}\n\n async buildChangeTrustLineXdrTx(params: TrustLineParams): Promise<string> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const stellarAccount = await stellar.loadAccount(params.sender);\n const tokenContract = this.getContract(TokenContract, params.tokenAddress);\n const tokenName = (await tokenContract.name()).result;\n const [symbol, srbTokenAddress] = tokenName.split(\":\");\n if (symbol === undefined || srbTokenAddress === undefined) {\n throw new SdkError(`Invalid token name format. Expected format 'symbol:srbTokenAddress'`);\n }\n const asset = new StellarAsset(symbol, srbTokenAddress);\n const changeTrust = StellarOperation.changeTrust({\n asset: asset,\n limit: params.limit,\n });\n\n return new StellarTransactionBuilder(stellarAccount, {\n fee: FEE.toString(10),\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n })\n .addOperation(changeTrust)\n .setTimeout(SEND_TRANSACTION_TIMEOUT)\n .build()\n .toXDR();\n }\n\n async getBalanceLine(sender: string, tokenAddress: string): Promise<Horizon.HorizonApi.BalanceLineAsset | undefined> {\n const tokenContract = this.getContract(TokenContract, tokenAddress);\n const tokenName = (await tokenContract.name()).result;\n const [symbol, srbTokenAddress] = tokenName.split(\":\");\n const nodeRpcUrl = this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR);\n const stellar = new Horizon.Server(nodeRpcUrl);\n const stellarAccount = await stellar.loadAccount(sender);\n const balanceInfo = stellarAccount.balances;\n\n return balanceInfo.find(\n (balance): balance is BalanceLineAsset =>\n (balance.asset_type === \"credit_alphanum4\" || balance.asset_type === \"credit_alphanum12\") &&\n balance.asset_code == symbol &&\n balance.asset_issuer == srbTokenAddress\n );\n }\n\n async submitTransactionStellar(xdrTx: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const transaction = StellarTransactionBuilder.fromXDR(\n xdrTx,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR)\n );\n return await stellar.submitTransaction(transaction);\n }\n\n async simulateAndCheckRestoreTxRequiredSoroban(xdrTx: string, sourceAccount: string): Promise<string | undefined> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const account = await server.getAccount(sourceAccount);\n const transaction = TransactionBuilder.fromXDR(xdrTx, this.params.sorobanNetworkPassphrase) as Transaction;\n const simulation = await server.simulateTransaction(transaction);\n if (SorobanRpc.Api.isSimulationRestore(simulation)) {\n return new TransactionBuilder(account, {\n fee: (+BASE_FEE + +simulation.restorePreamble.minResourceFee).toString(),\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n })\n .setSorobanData(simulation.restorePreamble.transactionData.build())\n .addOperation(Operation.restoreFootprint({}))\n .setTimeout(TimeoutInfinite)\n .build()\n .toXDR();\n }\n return undefined;\n }\n\n async sendTransactionSoroban(xdrTx: string): Promise<SorobanRpc.Api.SendTransactionResponse> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const transaction = TransactionBuilder.fromXDR(xdrTx, this.params.sorobanNetworkPassphrase) as Transaction;\n return server.sendTransaction(transaction);\n }\n\n async confirmTx(hash: string, secondsToWait = 15): Promise<SorobanRpc.Api.GetTransactionResponse> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const getTransactionResponseAll = await withExponentialBackoff(\n () => server.getTransaction(hash),\n (resp) => resp.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND,\n secondsToWait\n );\n\n if (getTransactionResponseAll.length === 0) {\n throw new SdkError(\"No transaction responses found.\");\n }\n\n const lastResponse = getTransactionResponseAll[getTransactionResponseAll.length - 1];\n if (!lastResponse) {\n throw new SdkError(\"Unexpected error: last response is undefined.\");\n }\n\n return lastResponse;\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string): T {\n const config: ContractClientOptions = {\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/srb/index.ts"],"names":[],"mappings":";;;AAAA,sDAY8B;AAC9B,0DAAuD;AACvD,uCAAgE;AAEhE,6EAAyE;AACzE,2DAA6F;AAC7F,oCAAkD;AAyDlD,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAa,eAAe;IAEf;IACA;IAFX,YACW,iB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E,CAAC;YAClB,MAAM,IAAI,gBAAQ,CAAC,+CAA+C,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe;QACtF,MAAM,MAAM,GAA0B;YACpC,UAAU,EAAE,OAAO;YACnB,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,yBAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA9HD,0CA8HC","sourcesContent":["import {\n Asset as StellarAsset,\n BASE_FEE,\n contract,\n Horizon,\n Operation,\n Operation as StellarOperation,\n rpc as SorobanRpc,\n TimeoutInfinite,\n Transaction,\n TransactionBuilder,\n TransactionBuilder as StellarTransactionBuilder,\n} from \"@stellar/stellar-sdk\";\nimport { ChainSymbol } from \"../../chains/chain.enums\";\nimport { AllbridgeCoreSdkOptions, SdkError } from \"../../index\";\nimport { NodeRpcUrlsConfig } from \"../../services\";\nimport { TokenContract } from \"../../services/models/srb/token-contract\";\nimport { getViewResultSoroban, isErrorSorobanResult } from \"../../services/models/srb/utils\";\nimport { withExponentialBackoff } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\nimport BalanceLineAsset = Horizon.HorizonApi.BalanceLineAsset;\n\n/**\n * Contains usefully Soroban methods\n */\nexport interface SrbUtils {\n /**\n * Build change Trust line Tx\n * @param params see {@link TrustLineParams}\n * @returns xdr Tx\n */\n buildChangeTrustLineXdrTx(params: TrustLineParams): Promise<string>;\n\n /**\n * Get Balance Line information if exists\n * @param sender\n * @param tokenAddress\n */\n getBalanceLine(sender: string, tokenAddress: string): Promise<Horizon.HorizonApi.BalanceLineAsset | undefined>;\n\n /**\n * Submit tx\n * @param xdrTx\n */\n submitTransactionStellar(xdrTx: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;\n\n /**\n * Simulate and check if Restore needed\n * @param xdrTx - restore\n * @param sourceAccount\n * @returns xdrTx restore transaction if it required after check\n */\n simulateAndCheckRestoreTxRequiredSoroban(xdrTx: string, sourceAccount: string): Promise<string | undefined>;\n\n /**\n * Submit tx\n * @param xdrTx\n */\n sendTransactionSoroban(xdrTx: string): Promise<SorobanRpc.Api.SendTransactionResponse>;\n\n /**\n * Confirm tx\n */\n confirmTx(hash: string, secondsToWait?: number): Promise<SorobanRpc.Api.GetTransactionResponse>;\n}\n\nexport interface TrustLineParams {\n /**\n * Float amount of tokens, default is Number.MAX_SAFE_INTEGER\n */\n limit?: string;\n sender: string;\n tokenAddress: string;\n}\n\nconst FEE = 100;\nconst SEND_TRANSACTION_TIMEOUT = 180;\n\nexport class DefaultSrbUtils implements SrbUtils {\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions\n ) {}\n\n async buildChangeTrustLineXdrTx(params: TrustLineParams): Promise<string> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const stellarAccount = await stellar.loadAccount(params.sender);\n const tokenContract = this.getContract(TokenContract, params.tokenAddress);\n const result = await tokenContract.name();\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const tokenName = getViewResultSoroban(result);\n if (!tokenName) {\n throw new SdkError();\n }\n\n const [symbol, srbTokenAddress] = tokenName.split(\":\");\n if (symbol === undefined || srbTokenAddress === undefined) {\n throw new SdkError(`Invalid token name format. Expected format 'symbol:srbTokenAddress'`);\n }\n const asset = new StellarAsset(symbol, srbTokenAddress);\n const changeTrust = StellarOperation.changeTrust({\n asset: asset,\n limit: params.limit,\n });\n\n return new StellarTransactionBuilder(stellarAccount, {\n fee: FEE.toString(10),\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n })\n .addOperation(changeTrust)\n .setTimeout(SEND_TRANSACTION_TIMEOUT)\n .build()\n .toXDR();\n }\n\n async getBalanceLine(sender: string, tokenAddress: string): Promise<Horizon.HorizonApi.BalanceLineAsset | undefined> {\n const tokenContract = this.getContract(TokenContract, tokenAddress);\n const result = await tokenContract.name();\n if (isErrorSorobanResult(result)) {\n throw new SdkError();\n }\n const tokenName = getViewResultSoroban(result);\n if (!tokenName) {\n throw new SdkError();\n }\n\n const [symbol, srbTokenAddress] = tokenName.split(\":\");\n const nodeRpcUrl = this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR);\n const stellar = new Horizon.Server(nodeRpcUrl);\n const stellarAccount = await stellar.loadAccount(sender);\n const balanceInfo = stellarAccount.balances;\n\n return balanceInfo.find(\n (balance): balance is BalanceLineAsset =>\n (balance.asset_type === \"credit_alphanum4\" || balance.asset_type === \"credit_alphanum12\") &&\n balance.asset_code == symbol &&\n balance.asset_issuer == srbTokenAddress\n );\n }\n\n async submitTransactionStellar(xdrTx: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const transaction = StellarTransactionBuilder.fromXDR(\n xdrTx,\n this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR)\n );\n return await stellar.submitTransaction(transaction);\n }\n\n async simulateAndCheckRestoreTxRequiredSoroban(xdrTx: string, sourceAccount: string): Promise<string | undefined> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const account = await server.getAccount(sourceAccount);\n const transaction = TransactionBuilder.fromXDR(xdrTx, this.params.sorobanNetworkPassphrase) as Transaction;\n const simulation = await server.simulateTransaction(transaction);\n if (SorobanRpc.Api.isSimulationRestore(simulation)) {\n return new TransactionBuilder(account, {\n fee: (+BASE_FEE + +simulation.restorePreamble.minResourceFee).toString(),\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n })\n .setSorobanData(simulation.restorePreamble.transactionData.build())\n .addOperation(Operation.restoreFootprint({}))\n .setTimeout(TimeoutInfinite)\n .build()\n .toXDR();\n }\n return undefined;\n }\n\n async sendTransactionSoroban(xdrTx: string): Promise<SorobanRpc.Api.SendTransactionResponse> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const transaction = TransactionBuilder.fromXDR(xdrTx, this.params.sorobanNetworkPassphrase) as Transaction;\n return server.sendTransaction(transaction);\n }\n\n async confirmTx(hash: string, secondsToWait = 15): Promise<SorobanRpc.Api.GetTransactionResponse> {\n const server = new SorobanRpc.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n const getTransactionResponseAll = await withExponentialBackoff(\n () => server.getTransaction(hash),\n (resp) => resp.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND,\n secondsToWait\n );\n\n if (getTransactionResponseAll.length === 0) {\n throw new SdkError(\"No transaction responses found.\");\n }\n\n const lastResponse = getTransactionResponseAll[getTransactionResponseAll.length - 1];\n if (!lastResponse) {\n throw new SdkError(\"Unexpected error: last response is undefined.\");\n }\n\n return lastResponse;\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string): T {\n const config: ContractClientOptions = {\n contractId: address,\n networkPassphrase: this.params.sorobanNetworkPassphrase,\n rpcUrl: this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB),\n };\n return new contract(config);\n }\n}\n"]}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.21.
|
|
1
|
+
export declare const VERSION = "3.21.1-alpha.2";
|
package/dist/src/version.js
CHANGED
package/dist/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["export const VERSION = \"3.21.1-alpha.2\";\n"]}
|