@allbridge/bridge-core-sdk 3.32.0 → 3.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +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/services/bridge/srb/index.js +6 -3
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/srb/index.js +7 -4
- package/dist/src/services/liquidity-pool/srb/index.js.map +1 -1
- package/dist/src/services/models/srb/utils.d.ts +13 -0
- package/dist/src/services/models/srb/utils.js +39 -0
- package/dist/src/services/models/srb/utils.js.map +1 -1
- package/dist/src/utils/srb/index.js +8 -6
- 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
|
@@ -6,6 +6,7 @@ import { ChainType } from "../../../index";
|
|
|
6
6
|
import { FeePaymentMethod } from "../../../models";
|
|
7
7
|
import { assertNever } from "../../../utils/utils";
|
|
8
8
|
import { BridgeContract } from "../../models/srb/bridge-contract";
|
|
9
|
+
import { getSorobanInclusionFee } from "../../models/srb/utils";
|
|
9
10
|
import { ChainBridgeService } from "../models";
|
|
10
11
|
import { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from "../utils";
|
|
11
12
|
export class SrbBridgeService extends ChainBridgeService {
|
|
@@ -30,6 +31,7 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
30
31
|
totalFee = Big(totalFee).plus(extraGas).toFixed();
|
|
31
32
|
}
|
|
32
33
|
const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);
|
|
34
|
+
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
33
35
|
let tx;
|
|
34
36
|
switch (gasFeePaymentMethod) {
|
|
35
37
|
case FeePaymentMethod.WITH_NATIVE_CURRENCY:
|
|
@@ -43,7 +45,7 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
43
45
|
nonce: getNonceBigInt(),
|
|
44
46
|
gas_amount: BigInt(totalFee),
|
|
45
47
|
fee_token_amount: BigInt(0),
|
|
46
|
-
});
|
|
48
|
+
}, { fee: inclusionFee });
|
|
47
49
|
break;
|
|
48
50
|
case FeePaymentMethod.WITH_STABLECOIN:
|
|
49
51
|
tx = await contract.swap_and_bridge({
|
|
@@ -56,7 +58,7 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
56
58
|
nonce: getNonceBigInt(),
|
|
57
59
|
gas_amount: BigInt(0),
|
|
58
60
|
fee_token_amount: BigInt(totalFee),
|
|
59
|
-
});
|
|
61
|
+
}, { fee: inclusionFee });
|
|
60
62
|
break;
|
|
61
63
|
case FeePaymentMethod.WITH_ABR:
|
|
62
64
|
throw new SdkError("SRB bridge does not support ABR payment method");
|
|
@@ -73,6 +75,7 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
73
75
|
async buildRawTransactionSwapFromParams(params) {
|
|
74
76
|
const { amount, contractAddress, fromAccountAddress, fromTokenAddress, toAccountAddress, toTokenAddress, minimumReceiveAmount, } = params;
|
|
75
77
|
const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);
|
|
78
|
+
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
76
79
|
return (await contract.swap({
|
|
77
80
|
sender: fromAccountAddress,
|
|
78
81
|
amount: BigInt(amount),
|
|
@@ -80,7 +83,7 @@ export class SrbBridgeService extends ChainBridgeService {
|
|
|
80
83
|
receive_token: Buffer.from(toTokenAddress),
|
|
81
84
|
recipient: toAccountAddress,
|
|
82
85
|
receive_amount_min: BigInt(minimumReceiveAmount),
|
|
83
|
-
})).toXDR();
|
|
86
|
+
}, { fee: inclusionFee })).toXDR();
|
|
84
87
|
}
|
|
85
88
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
89
|
send(params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/bridge/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAA2B,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAA4D,MAAM,WAAW,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpF,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IAI3C;IACA;IACA;IALX,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IAEzC,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,uBAAuB,CAAC,MAAkB;QAC9C,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjF,OAAO,MAAM,IAAI,CAAC,iC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tB,CACF,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC;IAED,6DAA6D;IAC7D,IAAI,CAAC,MAAkB;QACrB,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAEO,WAAW,CAAI,QAAgD,EAAE,OAAe,EAAE,MAAe;QACvG,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,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { Address, contract } from \"@stellar/stellar-sdk\";\nimport { Big } from \"big.js\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType } from \"../../../index\";\nimport { FeePaymentMethod } from \"../../../models\";\nimport { assertNever } from \"../../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { BridgeContract } from \"../../models/srb/bridge-contract\";\nimport { getSorobanInclusionFee } from \"../../models/srb/utils\";\nimport { ChainBridgeService, SendParams, SwapParams, TxSendParamsSrb, TxSwapParamsSol } from \"../models\";\nimport { getNonceBigInt, prepareTxSendParams, prepareTxSwapParams } from \"../utils\";\nimport ContractClientOptions = contract.ClientOptions;\n\nexport class SrbBridgeService extends ChainBridgeService {\n chainType: ChainType.SRB = ChainType.SRB;\n\n constructor(\n readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n readonly params: AllbridgeCoreSdkOptions,\n readonly api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async buildRawTransactionSend(params: SendParams): Promise<RawTransaction> {\n const txSendParams = await prepareTxSendParams(this.chainType, params, this.api);\n return await this.buildRawTransactionSendFromParams(txSendParams);\n }\n\n async buildRawTransactionSendFromParams(params: TxSendParamsSrb): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toChainId,\n toAccountAddress,\n toTokenAddress,\n fee,\n gasFeePaymentMethod,\n extraGas,\n } = params;\n\n let totalFee = fee;\n if (extraGas) {\n totalFee = Big(totalFee).plus(extraGas).toFixed();\n }\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n let tx;\n switch (gasFeePaymentMethod) {\n case FeePaymentMethod.WITH_NATIVE_CURRENCY:\n tx = await contract.swap_and_bridge(\n {\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(totalFee),\n fee_token_amount: BigInt(0),\n },\n { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_STABLECOIN:\n tx = await contract.swap_and_bridge(\n {\n sender: fromAccountAddress,\n token: Address.contract(Buffer.from(fromTokenAddress)).toString(),\n amount: BigInt(amount),\n recipient: Buffer.from(toAccountAddress),\n destination_chain_id: +toChainId,\n receive_token: Buffer.from(toTokenAddress),\n nonce: getNonceBigInt(),\n gas_amount: BigInt(0),\n fee_token_amount: BigInt(totalFee),\n },\n { fee: inclusionFee }\n );\n break;\n case FeePaymentMethod.WITH_ABR:\n throw new SdkError(\"SRB bridge does not support ABR payment method\");\n default: {\n return assertNever(gasFeePaymentMethod, \"Unhandled FeePaymentMethod\");\n }\n }\n\n return tx.toXDR();\n }\n\n async buildRawTransactionSwap(params: SwapParams): Promise<RawTransaction> {\n const txSwapParams = prepareTxSwapParams(this.chainType, params);\n return await this.buildRawTransactionSwapFromParams(txSwapParams);\n }\n\n async buildRawTransactionSwapFromParams(params: TxSwapParamsSol): Promise<RawTransaction> {\n const {\n amount,\n contractAddress,\n fromAccountAddress,\n fromTokenAddress,\n toAccountAddress,\n toTokenAddress,\n minimumReceiveAmount,\n } = params;\n const contract = this.getContract(BridgeContract, contractAddress, fromAccountAddress);\n const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return (\n await contract.swap(\n {\n sender: fromAccountAddress,\n amount: BigInt(amount),\n token: Address.contract(Buffer.from(fromTokenAddress)).toBuffer(),\n receive_token: Buffer.from(toTokenAddress),\n recipient: toAccountAddress,\n receive_amount_min: BigInt(minimumReceiveAmount),\n },\n { fee: inclusionFee }\n )\n ).toXDR();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n send(params: SendParams): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n private getContract<T>(contract: new (args: ContractClientOptions) => T, address: string, sender?: string): T {\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 contract(config);\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { ChainSymbol, ChainType } from "../../../index";
|
|
|
2
2
|
import { SdkError, } from "../../../models";
|
|
3
3
|
import { calculatePoolInfoImbalance } from "../../../utils/calculation";
|
|
4
4
|
import { PoolContract } from "../../models/srb/pool-contract";
|
|
5
|
-
import { getViewResultSoroban, isErrorSorobanResult } from "../../models/srb/utils";
|
|
5
|
+
import { getSorobanInclusionFee, getViewResultSoroban, isErrorSorobanResult } from "../../models/srb/utils";
|
|
6
6
|
import { ChainPoolService, UserBalance } from "../models";
|
|
7
7
|
export class SrbPoolService extends ChainPoolService {
|
|
8
8
|
nodeRpcUrlsConfig;
|
|
@@ -59,23 +59,26 @@ export class SrbPoolService extends ChainPoolService {
|
|
|
59
59
|
}
|
|
60
60
|
async buildRawTransactionDeposit(params) {
|
|
61
61
|
const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);
|
|
62
|
+
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
62
63
|
return (await poolContract.deposit({
|
|
63
64
|
sender: params.accountAddress,
|
|
64
65
|
amount: BigInt(params.amount),
|
|
65
|
-
})).toXDR();
|
|
66
|
+
}, { fee: inclusionFee })).toXDR();
|
|
66
67
|
}
|
|
67
68
|
async buildRawTransactionWithdraw(params) {
|
|
68
69
|
const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);
|
|
70
|
+
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
69
71
|
return (await poolContract.withdraw({
|
|
70
72
|
sender: params.accountAddress,
|
|
71
73
|
amount_lp: BigInt(params.amount),
|
|
72
|
-
})).toXDR();
|
|
74
|
+
}, { fee: inclusionFee })).toXDR();
|
|
73
75
|
}
|
|
74
76
|
async buildRawTransactionClaimRewards(params) {
|
|
75
77
|
const poolContract = this.getContract(params.token.poolAddress, params.accountAddress);
|
|
78
|
+
const inclusionFee = await getSorobanInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
76
79
|
return (await poolContract.claim_rewards({
|
|
77
80
|
sender: params.accountAddress,
|
|
78
|
-
})).toXDR();
|
|
81
|
+
}, { fee: inclusionFee })).toXDR();
|
|
79
82
|
}
|
|
80
83
|
getContract(address, sender) {
|
|
81
84
|
const config = {
|
|
@@ -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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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,6 +1,19 @@
|
|
|
1
1
|
import { contract } from "@stellar/stellar-sdk";
|
|
2
2
|
import AssembledTransaction = contract.AssembledTransaction;
|
|
3
3
|
import SentTransaction = contract.SentTransaction;
|
|
4
|
+
/**
|
|
5
|
+
* Fallback inclusion fee (in stroops) used when fee stats are unavailable.
|
|
6
|
+
* Matches the stellar-sdk `BASE_FEE` default.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_INCLUSION_FEE = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Inclusion-fee bid (in stroops) for Soroban (smart-contract) transactions.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSorobanInclusionFee(rpcUrl: string): Promise<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Inclusion-fee bid (in stroops) for classic Stellar transactions (e.g. changeTrust).
|
|
15
|
+
*/
|
|
16
|
+
export declare function getStellarInclusionFee(rpcUrl: string): Promise<number>;
|
|
4
17
|
export declare function getViewResultSoroban<T>(assembledTx: AssembledTransaction<T>): T | undefined;
|
|
5
18
|
export declare function isErrorSorobanResult<T>(assembledTx: AssembledTransaction<T>): boolean;
|
|
6
19
|
export declare function signAndSendSoroban<T>(assembledTx: AssembledTransaction<T>): Promise<SentTransaction<T>>;
|
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
import { rpc } from "@stellar/stellar-sdk";
|
|
2
2
|
var Api = rpc.Api;
|
|
3
|
+
/**
|
|
4
|
+
* Fallback inclusion fee (in stroops) used when fee stats are unavailable.
|
|
5
|
+
* Matches the stellar-sdk `BASE_FEE` default.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_INCLUSION_FEE = 100;
|
|
8
|
+
/**
|
|
9
|
+
* Fetches the current network fee stats and derives an inclusion-fee bid (in stroops).
|
|
10
|
+
*
|
|
11
|
+
* We bid `max(p90 * 2, mode, DEFAULT_INCLUSION_FEE)`: the p90 * 2 headroom protects
|
|
12
|
+
* against congestion while the actual charge stays the clearing price, so overbidding
|
|
13
|
+
* is safe. On any RPC error we fall back to {@link DEFAULT_INCLUSION_FEE}.
|
|
14
|
+
*
|
|
15
|
+
* @param rpcUrl Soroban RPC url (the `getFeeStats` endpoint exposes both distributions)
|
|
16
|
+
* @param kind `sorobanInclusionFee` for Soroban txs, `inclusionFee` for classic Stellar txs
|
|
17
|
+
*/
|
|
18
|
+
async function getInclusionFeeBid(rpcUrl, kind) {
|
|
19
|
+
try {
|
|
20
|
+
const server = new rpc.Server(rpcUrl);
|
|
21
|
+
const stats = await server.getFeeStats();
|
|
22
|
+
const distribution = stats[kind];
|
|
23
|
+
const candidates = [Number(distribution.p90) * 2, Number(distribution.mode)].filter((value) => Number.isFinite(value) && value > 0);
|
|
24
|
+
return Math.ceil(Math.max(...candidates, DEFAULT_INCLUSION_FEE));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return DEFAULT_INCLUSION_FEE;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Inclusion-fee bid (in stroops) for Soroban (smart-contract) transactions.
|
|
32
|
+
*/
|
|
33
|
+
export function getSorobanInclusionFee(rpcUrl) {
|
|
34
|
+
return getInclusionFeeBid(rpcUrl, "sorobanInclusionFee");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Inclusion-fee bid (in stroops) for classic Stellar transactions (e.g. changeTrust).
|
|
38
|
+
*/
|
|
39
|
+
export function getStellarInclusionFee(rpcUrl) {
|
|
40
|
+
return getInclusionFeeBid(rpcUrl, "inclusionFee");
|
|
41
|
+
}
|
|
3
42
|
export function getViewResultSoroban(assembledTx) {
|
|
4
43
|
const { simulation, options } = assembledTx;
|
|
5
44
|
if (!simulation) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/services/models/srb/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAE,MAAM,sBAAsB,CAAC;AACrD,IAAO,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;AAIrB,MAAM,UAAU,oBAAoB,CAAI,WAAoC;IAC1E,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;IAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,GAAG,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,IAAI,UAAU,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QACD,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAI,WAAoC;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IACnC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,WAAoC;IAC9E,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { contract, rpc } from \"@stellar/stellar-sdk\";\nimport Api = rpc.Api;\nimport AssembledTransaction = contract.AssembledTransaction;\nimport SentTransaction = contract.SentTransaction;\n\nexport function getViewResultSoroban<T>(assembledTx: AssembledTransaction<T>): T | undefined {\n const { simulation, options } = assembledTx;\n if (!simulation) {\n throw new Error(\"Soroban assembled transaction does not have simulation\");\n }\n\n if (Api.isSimulationSuccess(simulation)) {\n if (simulation.result == null) {\n return;\n }\n return options.parseResultXdr(simulation.result.retval);\n } else {\n throw new Error(simulation.error);\n }\n}\n\nexport function isErrorSorobanResult<T>(assembledTx: AssembledTransaction<T>): boolean {\n const { simulation } = assembledTx;\n if (!simulation) {\n throw new Error(\"Soroban assembled transaction does not have simulation\");\n }\n return Api.isSimulationError(simulation);\n}\n\nexport async function signAndSendSoroban<T>(assembledTx: AssembledTransaction<T>): Promise<SentTransaction<T>> {\n await assembledTx.simulate({ restore: true });\n return assembledTx.signAndSend();\n}\n"]}
|
|
1
|
+
{"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,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;IAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,GAAG,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,IAAI,UAAU,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QACD,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAI,WAAoC;IAC1E,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IACnC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,WAAoC;IAC9E,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { contract, rpc } from \"@stellar/stellar-sdk\";\nimport Api = rpc.Api;\nimport AssembledTransaction = contract.AssembledTransaction;\nimport SentTransaction = contract.SentTransaction;\n\n/**\n * Fallback inclusion fee (in stroops) used when fee stats are unavailable.\n * Matches the stellar-sdk `BASE_FEE` default.\n */\nexport const DEFAULT_INCLUSION_FEE = 100;\n\n/**\n * Fetches the current network fee stats and derives an inclusion-fee bid (in stroops).\n *\n * We bid `max(p90 * 2, mode, DEFAULT_INCLUSION_FEE)`: the p90 * 2 headroom protects\n * against congestion while the actual charge stays the clearing price, so overbidding\n * is safe. On any RPC error we fall back to {@link DEFAULT_INCLUSION_FEE}.\n *\n * @param rpcUrl Soroban RPC url (the `getFeeStats` endpoint exposes both distributions)\n * @param kind `sorobanInclusionFee` for Soroban txs, `inclusionFee` for classic Stellar txs\n */\nasync function getInclusionFeeBid(rpcUrl: string, kind: \"sorobanInclusionFee\" | \"inclusionFee\"): Promise<number> {\n try {\n const server = new rpc.Server(rpcUrl);\n const stats = await server.getFeeStats();\n const distribution = stats[kind];\n const candidates = [Number(distribution.p90) * 2, Number(distribution.mode)].filter(\n (value) => Number.isFinite(value) && value > 0\n );\n return Math.ceil(Math.max(...candidates, DEFAULT_INCLUSION_FEE));\n } catch {\n return DEFAULT_INCLUSION_FEE;\n }\n}\n\n/**\n * Inclusion-fee bid (in stroops) for Soroban (smart-contract) transactions.\n */\nexport function getSorobanInclusionFee(rpcUrl: string): Promise<number> {\n return getInclusionFeeBid(rpcUrl, \"sorobanInclusionFee\");\n}\n\n/**\n * Inclusion-fee bid (in stroops) for classic Stellar transactions (e.g. changeTrust).\n */\nexport function getStellarInclusionFee(rpcUrl: string): Promise<number> {\n return getInclusionFeeBid(rpcUrl, \"inclusionFee\");\n}\n\nexport function getViewResultSoroban<T>(assembledTx: AssembledTransaction<T>): T | undefined {\n const { simulation, options } = assembledTx;\n if (!simulation) {\n throw new Error(\"Soroban assembled transaction does not have simulation\");\n }\n\n if (Api.isSimulationSuccess(simulation)) {\n if (simulation.result == null) {\n return;\n }\n return options.parseResultXdr(simulation.result.retval);\n } else {\n throw new Error(simulation.error);\n }\n}\n\nexport function isErrorSorobanResult<T>(assembledTx: AssembledTransaction<T>): boolean {\n const { simulation } = assembledTx;\n if (!simulation) {\n throw new Error(\"Soroban assembled transaction does not have simulation\");\n }\n return Api.isSimulationError(simulation);\n}\n\nexport async function signAndSendSoroban<T>(assembledTx: AssembledTransaction<T>): Promise<SentTransaction<T>> {\n await assembledTx.simulate({ restore: true });\n return assembledTx.signAndSend();\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Asset as StellarAsset,
|
|
1
|
+
import { Asset as StellarAsset, Horizon, Operation, Operation as StellarOperation, rpc as SorobanRpc, TimeoutInfinite, TransactionBuilder, TransactionBuilder as StellarTransactionBuilder, } from "@stellar/stellar-sdk";
|
|
2
2
|
import { ChainSymbol } from "../../chains/chain.enums";
|
|
3
3
|
import { SdkError } from "../../index";
|
|
4
4
|
import { TokenContract } from "../../services/models/srb/token-contract";
|
|
5
|
-
import { getViewResultSoroban, isErrorSorobanResult } from "../../services/models/srb/utils";
|
|
5
|
+
import { getSorobanInclusionFee, getStellarInclusionFee, getViewResultSoroban, isErrorSorobanResult, } from "../../services/models/srb/utils";
|
|
6
6
|
import { withExponentialBackoff } from "../utils";
|
|
7
|
-
const FEE = 100;
|
|
8
7
|
const SEND_TRANSACTION_TIMEOUT = 180;
|
|
9
8
|
export class DefaultSrbUtils {
|
|
10
9
|
nodeRpcUrlsConfig;
|
|
@@ -34,8 +33,9 @@ export class DefaultSrbUtils {
|
|
|
34
33
|
asset: asset,
|
|
35
34
|
limit: params.limit,
|
|
36
35
|
});
|
|
36
|
+
const inclusionFee = await getStellarInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));
|
|
37
37
|
return new StellarTransactionBuilder(stellarAccount, {
|
|
38
|
-
fee:
|
|
38
|
+
fee: inclusionFee.toString(10),
|
|
39
39
|
networkPassphrase: this.params.sorobanNetworkPassphrase,
|
|
40
40
|
})
|
|
41
41
|
.addOperation(changeTrust)
|
|
@@ -68,13 +68,15 @@ export class DefaultSrbUtils {
|
|
|
68
68
|
return await stellar.submitTransaction(transaction);
|
|
69
69
|
}
|
|
70
70
|
async simulateAndCheckRestoreTxRequiredSoroban(xdrTx, sourceAccount) {
|
|
71
|
-
const
|
|
71
|
+
const rpcUrl = this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB);
|
|
72
|
+
const server = new SorobanRpc.Server(rpcUrl);
|
|
72
73
|
const account = await server.getAccount(sourceAccount);
|
|
73
74
|
const transaction = TransactionBuilder.fromXDR(xdrTx, this.params.sorobanNetworkPassphrase);
|
|
74
75
|
const simulation = await server.simulateTransaction(transaction);
|
|
75
76
|
if (SorobanRpc.Api.isSimulationRestore(simulation)) {
|
|
77
|
+
const inclusionFee = await getSorobanInclusionFee(rpcUrl);
|
|
76
78
|
return new TransactionBuilder(account, {
|
|
77
|
-
fee: (
|
|
79
|
+
fee: (inclusionFee + +simulation.restorePreamble.minResourceFee).toString(),
|
|
78
80
|
networkPassphrase: this.params.sorobanNetworkPassphrase,
|
|
79
81
|
})
|
|
80
82
|
.setSorobanData(simulation.restorePreamble.transactionData.build())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,YAAY,EACrB,QAAQ,EAER,OAAO,EACP,SAAS,EACT,SAAS,IAAI,gBAAgB,EAC7B,GAAG,IAAI,UAAU,EACjB,eAAe,EAEf,kBAAkB,EAClB,kBAAkB,IAAI,yBAAyB,GAChD,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAA2B,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAyDlD,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,MAAM,OAAO,eAAe;IAEf;IACA;IAFX,YACW,iBAAoC,EACpC,MAA+B;QAD/B,sBAAiB,GAAjB,i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;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,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,YAAY,EAErB,OAAO,EACP,SAAS,EACT,SAAS,IAAI,gBAAgB,EAC7B,GAAG,IAAI,UAAU,EACjB,eAAe,EAEf,kBAAkB,EAClB,kBAAkB,IAAI,yBAAyB,GAChD,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAA2B,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,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IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,GAAG,CAAC,oBAAoB,CAAC,SAAS,EACvE,aAAa,CACd,CAAC;QAEF,IAAI,yBAAyB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,QAAQ,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,QAAQ,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,WAAW,CAAC,GAAG,CAAC;SAC9D,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import {\n Asset as StellarAsset,\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 {\n getSorobanInclusionFee,\n getStellarInclusionFee,\n getViewResultSoroban,\n isErrorSorobanResult,\n} 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 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 const inclusionFee = await getStellarInclusionFee(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB));\n return new StellarTransactionBuilder(stellarAccount, {\n fee: inclusionFee.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 rpcUrl = this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SRB);\n const server = new SorobanRpc.Server(rpcUrl);\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 const inclusionFee = await getSorobanInclusionFee(rpcUrl);\n return new TransactionBuilder(account, {\n fee: (inclusionFee + +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.32.
|
|
1
|
+
export declare const VERSION = "3.32.1";
|
package/dist/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "3.32.
|
|
1
|
+
export const VERSION = "3.32.1";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/dist/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = \"3.32.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = \"3.32.1\";\n"]}
|