@allbridge/bridge-core-sdk 3.27.0-alpha.2 → 3.27.0-alpha.20
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 +3 -3
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +4 -4
- package/dist/src/chains/chain.enums.d.ts +7 -2
- package/dist/src/chains/chain.enums.js +5 -0
- package/dist/src/chains/chain.enums.js.map +1 -1
- package/dist/src/chains/index.js +6 -0
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/client/core-api/api-client.js +1 -0
- package/dist/src/client/core-api/api-client.js.map +1 -1
- package/dist/src/client/core-api/core-api-mapper.js +32 -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 +13 -2
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/configs/mainnet.js +1 -0
- package/dist/src/configs/mainnet.js.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.js +5 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +12 -4
- package/dist/src/models/index.js +4 -0
- 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 +79 -43
- package/dist/src/services/bridge/alg/index.js.map +1 -1
- package/dist/src/services/bridge/evm/index.d.ts +1 -0
- package/dist/src/services/bridge/evm/index.js +103 -33
- package/dist/src/services/bridge/evm/index.js.map +1 -1
- package/dist/src/services/bridge/index.d.ts +2 -2
- package/dist/src/services/bridge/index.js +15 -4
- package/dist/src/services/bridge/index.js.map +1 -1
- package/dist/src/services/bridge/models/bridge.model.d.ts +12 -4
- package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js +1 -1
- package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
- package/dist/src/services/bridge/srb/index.js +36 -28
- package/dist/src/services/bridge/srb/index.js.map +1 -1
- package/dist/src/services/bridge/stx/index.d.ts +16 -0
- package/dist/src/services/bridge/stx/index.js +136 -0
- package/dist/src/services/bridge/stx/index.js.map +1 -0
- package/dist/src/services/bridge/sui/index.js +166 -138
- package/dist/src/services/bridge/sui/index.js.map +1 -1
- package/dist/src/services/bridge/trx/index.js +98 -70
- package/dist/src/services/bridge/trx/index.js.map +1 -1
- package/dist/src/services/bridge/utils.d.ts +3 -1
- package/dist/src/services/bridge/utils.js +92 -8
- package/dist/src/services/bridge/utils.js.map +1 -1
- package/dist/src/services/liquidity-pool/alg/index.js +10 -17
- package/dist/src/services/liquidity-pool/alg/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/index.js +5 -0
- package/dist/src/services/liquidity-pool/index.js.map +1 -1
- package/dist/src/services/liquidity-pool/stx/index.d.ts +21 -0
- package/dist/src/services/liquidity-pool/stx/index.js +141 -0
- package/dist/src/services/liquidity-pool/stx/index.js.map +1 -0
- package/dist/src/services/models/abi/PayerWithAbr.d.ts +203 -0
- package/dist/src/services/models/abi/PayerWithAbr.js +266 -0
- package/dist/src/services/models/abi/PayerWithAbr.js.map +1 -0
- package/dist/src/services/models/alg/BridgeClient.d.ts +158 -133
- package/dist/src/services/models/alg/BridgeClient.js +182 -130
- package/dist/src/services/models/alg/BridgeClient.js.map +1 -1
- package/dist/src/services/models/alg/PaddingUtilClient.d.ts +639 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js +425 -0
- package/dist/src/services/models/alg/PaddingUtilClient.js.map +1 -0
- package/dist/src/services/models/alg/PoolClient.d.ts +204 -201
- package/dist/src/services/models/alg/PoolClient.js +234 -215
- package/dist/src/services/models/alg/PoolClient.js.map +1 -1
- package/dist/src/services/models/index.d.ts +2 -1
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/services/models/stx/clarigen-types.d.ts +657 -0
- package/dist/src/services/models/stx/clarigen-types.js +2296 -0
- package/dist/src/services/models/stx/clarigen-types.js.map +1 -0
- package/dist/src/services/token/index.js +7 -2
- package/dist/src/services/token/index.js.map +1 -1
- package/dist/src/services/token/models/token.model.d.ts +4 -4
- package/dist/src/services/token/models/token.model.js.map +1 -1
- package/dist/src/services/token/stx/index.d.ts +20 -0
- package/dist/src/services/token/stx/index.js +59 -0
- package/dist/src/services/token/stx/index.js.map +1 -0
- package/dist/src/services/utils/alg/index.d.ts +1 -10
- package/dist/src/services/utils/alg/index.js +0 -20
- package/dist/src/services/utils/alg/index.js.map +1 -1
- package/dist/src/services/utils/stx/get-token-name.d.ts +2 -0
- package/dist/src/services/utils/stx/get-token-name.js +15 -0
- package/dist/src/services/utils/stx/get-token-name.js.map +1 -0
- package/dist/src/services/utils/stx/post-conditions.d.ts +3 -0
- package/dist/src/services/utils/stx/post-conditions.js +27 -0
- package/dist/src/services/utils/stx/post-conditions.js.map +1 -0
- package/dist/src/services/yield/index.js +4 -0
- package/dist/src/services/yield/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +21 -0
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/utils/utils.d.ts +2 -0
- package/dist/src/utils/utils.js +11 -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 +6 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StxTokenService = void 0;
|
|
4
|
+
const core_1 = require("@clarigen/core");
|
|
5
|
+
const network_1 = require("@stacks/network");
|
|
6
|
+
const chain_enums_1 = require("../../../chains/chain.enums");
|
|
7
|
+
const exceptions_1 = require("../../../exceptions");
|
|
8
|
+
const clarigen_types_1 = require("../../models/stx/clarigen-types");
|
|
9
|
+
const models_1 = require("../models");
|
|
10
|
+
class StxTokenService extends models_1.ChainTokenService {
|
|
11
|
+
nodeRpcUrl;
|
|
12
|
+
params;
|
|
13
|
+
api;
|
|
14
|
+
chainType = chain_enums_1.ChainType.STX;
|
|
15
|
+
client;
|
|
16
|
+
constructor(nodeRpcUrl, params, api) {
|
|
17
|
+
super();
|
|
18
|
+
this.nodeRpcUrl = nodeRpcUrl;
|
|
19
|
+
this.params = params;
|
|
20
|
+
this.api = api;
|
|
21
|
+
const network = (0, network_1.createNetwork)({
|
|
22
|
+
network: this.params.stxIsTestnet ? "testnet" : "mainnet",
|
|
23
|
+
client: { baseUrl: this.nodeRpcUrl },
|
|
24
|
+
apiKey: this.params.stxHeroApiKey,
|
|
25
|
+
});
|
|
26
|
+
this.client = new core_1.ClarigenClient(network, this.params.stxHeroApiKey);
|
|
27
|
+
}
|
|
28
|
+
async getTokenBalance(params) {
|
|
29
|
+
const token = (0, core_1.contractFactory)(clarigen_types_1.stacksContracts.ftToken, params.token.tokenAddress);
|
|
30
|
+
const response = await this.client.roOk(token.getBalance({ owner: params.account }));
|
|
31
|
+
return response.toString();
|
|
32
|
+
}
|
|
33
|
+
async getNativeTokenBalance(params) {
|
|
34
|
+
const url = `${this.nodeRpcUrl}/extended/v1/address/${params.account}/stx`;
|
|
35
|
+
const res = await fetch(url, {
|
|
36
|
+
headers: this.params.stxHeroApiKey ? { "x-api-key": this.params.stxHeroApiKey } : undefined,
|
|
37
|
+
});
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
throw new Error(`Failed to fetch account: ${res.status}`);
|
|
40
|
+
}
|
|
41
|
+
const data = (await res.json());
|
|
42
|
+
const balance = data.balance;
|
|
43
|
+
return BigInt(balance).toString();
|
|
44
|
+
}
|
|
45
|
+
getAllowance(_params) {
|
|
46
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
47
|
+
}
|
|
48
|
+
checkAllowance(_params) {
|
|
49
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
50
|
+
}
|
|
51
|
+
approve(_params) {
|
|
52
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
53
|
+
}
|
|
54
|
+
buildRawTransactionApprove(_params) {
|
|
55
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.StxTokenService = StxTokenService;
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/stx/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,6CAAgD;AAChD,6DAAwD;AAExD,oDAA8D;AAI9D,oEAA+E;AAC/E,sCAMmB;AAEnB,MAAa,eAAgB,SAAQ,0BAAiB;IAM3C;IACA;IACA;IAPT,SAAS,GAAkB,uBAAS,CAAC,GAAG,CAAC;IAEjC,MAAM,CAAiB;IAE/B,YACS,UAAkB,EAClB,MAA+B,EAC/B,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAyB;QAC/B,QAAG,GAAH,GAAG,CAAqB;QAG/B,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACzD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;SAClC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAc,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,MAA6B;QACjD,MAAM,KAAK,GAAG,IAAA,sBAAe,EAAC,gCAAS,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,C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{ ClarigenClient, contractFactory } from \"@clarigen/core\";\nimport { createNetwork } from \"@stacks/network\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { stacksContracts as contracts } from \"../../models/stx/clarigen-types\";\nimport {\n ApproveParamsDto,\n ChainTokenService,\n CheckAllowanceParamsDto,\n GetAllowanceParamsDto,\n GetTokenBalanceParams,\n} from \"../models\";\n\nexport class StxTokenService extends ChainTokenService {\n chainType: ChainType.STX = ChainType.STX;\n\n private client: ClarigenClient;\n\n constructor(\n public nodeRpcUrl: string,\n public params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n const network = createNetwork({\n network: this.params.stxIsTestnet ? \"testnet\" : \"mainnet\",\n client: { baseUrl: this.nodeRpcUrl },\n apiKey: this.params.stxHeroApiKey,\n });\n this.client = new ClarigenClient(network, this.params.stxHeroApiKey);\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n const token = contractFactory(contracts.ftToken, params.token.tokenAddress);\n\n const response = await this.client.roOk(token.getBalance({ owner: params.account }));\n return response.toString();\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n const url = `${this.nodeRpcUrl}/extended/v1/address/${params.account}/stx`;\n\n const res = await fetch(url, {\n headers: this.params.stxHeroApiKey ? { \"x-api-key\": this.params.stxHeroApiKey } : undefined,\n });\n if (!res.ok) {\n throw new Error(`Failed to fetch account: ${res.status}`);\n }\n const data = (await res.json()) as { balance: string };\n const balance = data.balance;\n return BigInt(balance).toString();\n }\n\n getAllowance(_params: GetAllowanceParamsDto): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n checkAllowance(_params: CheckAllowanceParamsDto): Promise<boolean> {\n throw new MethodNotSupportedError();\n }\n\n approve(_params: ApproveParamsDto): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n buildRawTransactionApprove(_params: ApproveParamsDto): Promise<RawTransaction> {\n throw new MethodNotSupportedError();\n }\n}\n"]}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { AlgorandClient } from "@algorandfoundation/algokit-utils";
|
|
2
2
|
import { AlgoAmount } from "@algorandfoundation/algokit-utils/types/amount";
|
|
3
|
-
import {
|
|
4
|
-
import algosdk, { Address, Algodv2, Transaction } from "algosdk";
|
|
3
|
+
import { Address, Algodv2, Transaction } from "algosdk";
|
|
5
4
|
import { RawAlgTransaction } from "../../models";
|
|
6
|
-
export declare const mNoop: algosdk.ABIMethod;
|
|
7
|
-
export declare function addBudgetNoops(opts: {
|
|
8
|
-
composer: TransactionComposer;
|
|
9
|
-
appId: bigint;
|
|
10
|
-
sender: string | Address;
|
|
11
|
-
signer?: any;
|
|
12
|
-
count: number;
|
|
13
|
-
}): void;
|
|
14
5
|
export declare function feeForInner(innerCount: number): AlgoAmount;
|
|
15
6
|
export declare function populateAndEncodeTxs(txs: Transaction[], sender: Address, algod: Algodv2): Promise<RawAlgTransaction>;
|
|
16
7
|
export declare function encodeTxs(...txs: Transaction[]): RawAlgTransaction;
|
|
@@ -23,8 +23,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.mNoop = void 0;
|
|
27
|
-
exports.addBudgetNoops = addBudgetNoops;
|
|
28
26
|
exports.feeForInner = feeForInner;
|
|
29
27
|
exports.populateAndEncodeTxs = populateAndEncodeTxs;
|
|
30
28
|
exports.encodeTxs = encodeTxs;
|
|
@@ -32,24 +30,6 @@ exports.checkAssetOptIn = checkAssetOptIn;
|
|
|
32
30
|
exports.checkAppOptIn = checkAppOptIn;
|
|
33
31
|
const algokit_utils_1 = require("@algorandfoundation/algokit-utils");
|
|
34
32
|
const algosdk_1 = __importStar(require("algosdk"));
|
|
35
|
-
exports.mNoop = new algosdk_1.ABIMethod({
|
|
36
|
-
name: "noop",
|
|
37
|
-
args: [],
|
|
38
|
-
returns: { type: "void" },
|
|
39
|
-
});
|
|
40
|
-
function addBudgetNoops(opts) {
|
|
41
|
-
const { composer, appId, sender, signer, count } = opts;
|
|
42
|
-
for (let i = 0; i < count; i++) {
|
|
43
|
-
composer.addAppCallMethodCall({
|
|
44
|
-
appId,
|
|
45
|
-
method: exports.mNoop,
|
|
46
|
-
args: [],
|
|
47
|
-
sender,
|
|
48
|
-
signer,
|
|
49
|
-
note: `noop_${i}`,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
33
|
function feeForInner(innerCount) {
|
|
54
34
|
return (innerCount * 1000).microAlgos(); // 1000 μAlgos per tx
|
|
55
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/utils/alg/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/utils/alg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA,kCAEC;AAED,oDAaC;AAED,8BAGC;AAED,0CAeC;AAED,sCAeC;AAnED,qEAA6F;AAE7F,mDAMiB;AAGjB,SAAgB,WAAW,CAAC,UAAkB;IAC5C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,qBAAqB;AAChE,CAAC;AAEM,KAAK,UAAU,oBAAoB,CACxC,GAAkB,EAClB,MAAe,EACf,KAAc;IAEd,MAAM,GAAG,GAAG,IAAI,mCAAyB,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,IAAA,2CAAiC,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,UAAU,CAAC,EA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K,OAAO,CAAC,CAAC;QACnE,OAAO,SAAS,KAAK,SAAS,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,KAAsB,EACtB,MAAc,EACd,QAAwB;IAExB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC;IACxC,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;QAC7D,OAAO,SAAS,KAAK,SAAS,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { AlgorandClient, populateAppCallResources } from \"@algorandfoundation/algokit-utils\";\nimport { AlgoAmount } from \"@algorandfoundation/algokit-utils/types/amount\";\nimport algosdk, {\n Address,\n Algodv2,\n AtomicTransactionComposer,\n makeBasicAccountTransactionSigner,\n Transaction,\n} from \"algosdk\";\nimport { RawAlgTransaction } from \"../../models\";\n\nexport function feeForInner(innerCount: number): AlgoAmount {\n return (innerCount * 1000).microAlgos(); // 1000 μAlgos per tx\n}\n\nexport async function populateAndEncodeTxs(\n txs: Transaction[],\n sender: Address,\n algod: Algodv2\n): Promise<RawAlgTransaction> {\n const atc = new AtomicTransactionComposer();\n const txnSigner = makeBasicAccountTransactionSigner({ addr: sender, sk: new Uint8Array(64) });\n txs.forEach((txn) => {\n atc.addTransaction({ txn, signer: txnSigner });\n });\n const populatedAtc = await populateAppCallResources(atc, algod);\n const populatedTxs = populatedAtc.buildGroup().map((tx) => tx.txn);\n return encodeTxs(...populatedTxs);\n}\n\nexport function encodeTxs(...txs: Transaction[]): RawAlgTransaction {\n const blobs = txs.map((tx) => algosdk.encodeUnsignedTransaction(tx));\n return blobs.map((b) => Buffer.from(b).toString(\"hex\"));\n}\n\nexport async function checkAssetOptIn(\n assetId: string | bigint,\n sender: string,\n algorand: AlgorandClient\n): Promise<boolean> {\n if (typeof assetId === \"string\") {\n assetId = BigInt(assetId);\n }\n const info = await algorand.account.getInformation(sender);\n const assets = info.assets;\n if (assets) {\n const isOptedIn = assets.find(({ assetId: id }) => id === assetId);\n return isOptedIn !== undefined;\n }\n return false;\n}\n\nexport async function checkAppOptIn(\n appId: string | bigint,\n sender: string,\n algorand: AlgorandClient\n): Promise<boolean> {\n if (typeof appId === \"string\") {\n appId = BigInt(appId);\n }\n const info = await algorand.account.getInformation(sender);\n const localStates = info.appsLocalState;\n if (localStates) {\n const isOptedIn = localStates.find(({ id }) => id === appId);\n return isOptedIn !== undefined;\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenName = getTokenName;
|
|
4
|
+
const exceptions_1 = require("../../../exceptions");
|
|
5
|
+
function getTokenName(token) {
|
|
6
|
+
if (!token.originTokenAddress) {
|
|
7
|
+
throw new exceptions_1.SdkError("STX token must contain 'originTokenAddress'");
|
|
8
|
+
}
|
|
9
|
+
const [_address, name] = token.originTokenAddress.split("::");
|
|
10
|
+
if (!name) {
|
|
11
|
+
throw new exceptions_1.SdkError("STX token must contain 'originTokenAddress' ends with '::<tokenName>'");
|
|
12
|
+
}
|
|
13
|
+
return name;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=get-token-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-token-name.js","sourceRoot":"","sources":["../../../../../src/services/utils/stx/get-token-name.ts"],"names":[],"mappings":";;AAGA,oCASC;AAZD,oDAA+C;AAG/C,SAAgB,YAAY,CAAC,KAA4B;IACvD,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC9B,MAAM,IAAI,qBAAQ,CAAC,6CAA6C,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,qBAAQ,CAAC,uEAAuE,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { SdkError } from \"../../../exceptions\";\nimport { TokenWithChainDetails } from \"../../../tokens-info\";\n\nexport function getTokenName(token: TokenWithChainDetails): string {\n if (!token.originTokenAddress) {\n throw new SdkError(\"STX token must contain 'originTokenAddress'\");\n }\n const [_address, name] = token.originTokenAddress.split(\"::\");\n if (!name) {\n throw new SdkError(\"STX token must contain 'originTokenAddress' ends with '::<tokenName>'\");\n }\n return name;\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FungibleComparator, FungiblePostCondition, StxPostCondition } from "@stacks/transactions";
|
|
2
|
+
export declare function getFungiblePostCondition(amount: string | bigint | number, condition: `${FungibleComparator}`, accountAddress: string, tokenAddress: string, tokenName: string): FungiblePostCondition;
|
|
3
|
+
export declare function getStxPostCondition(amount: string | bigint | number, condition: `${FungibleComparator}`, accountAddress: string): StxPostCondition;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFungiblePostCondition = getFungiblePostCondition;
|
|
4
|
+
exports.getStxPostCondition = getStxPostCondition;
|
|
5
|
+
const transactions_1 = require("@stacks/transactions");
|
|
6
|
+
function getFungiblePostCondition(amount, condition, accountAddress, tokenAddress, tokenName) {
|
|
7
|
+
const [assetAddress, assetContractName] = (0, transactions_1.parseContractId)(tokenAddress);
|
|
8
|
+
if (!assetAddress || !assetContractName) {
|
|
9
|
+
throw new Error(`Unable to parse stx token ${tokenAddress}`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
type: "ft-postcondition",
|
|
13
|
+
address: accountAddress,
|
|
14
|
+
condition,
|
|
15
|
+
asset: `${assetAddress}.${assetContractName}::${tokenName}`,
|
|
16
|
+
amount,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getStxPostCondition(amount, condition, accountAddress) {
|
|
20
|
+
return {
|
|
21
|
+
type: "stx-postcondition",
|
|
22
|
+
address: accountAddress,
|
|
23
|
+
condition,
|
|
24
|
+
amount,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=post-conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-conditions.js","sourceRoot":"","sources":["../../../../../src/services/utils/stx/post-conditions.ts"],"names":[],"mappings":";;AAQA,4DAkBC;AAED,kDAWC;AAvCD,uDAM8B;AAE9B,SAAgB,wBAAwB,CACtC,MAAgC,EAChC,SAAkC,EAClC,cAAsB,EACtB,YAAoB,EACpB,SAAiB;IAEjB,MAAM,CAAC,YAAY,EAAE,iBAAiB,CAAC,GAAG,IAAA,8BAAe,EAAC,YAAgC,CAAC,CAAC;IAC5F,IAAI,CAAC,YAAY,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,6BAA6B,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,cAAc;QACvB,SAAS;QACT,KAAK,EAAE,GAAG,YAAY,IAAI,iBAAiB,KAAK,SAAS,EAAE;QAC3D,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CACjC,MAAgC,EAChC,SAAkC,EAClC,cAAsB;IAEtB,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,cAAc;QACvB,SAAS;QACT,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n ContractIdString,\n FungibleComparator,\n FungiblePostCondition,\n parseContractId,\n StxPostCondition,\n} from \"@stacks/transactions\";\n\nexport function getFungiblePostCondition(\n amount: string | bigint | number,\n condition: `${FungibleComparator}`,\n accountAddress: string,\n tokenAddress: string,\n tokenName: string\n): FungiblePostCondition {\n const [assetAddress, assetContractName] = parseContractId(tokenAddress as ContractIdString);\n if (!assetAddress || !assetContractName) {\n throw new Error(`Unable to parse stx token ${tokenAddress}`);\n }\n return {\n type: \"ft-postcondition\",\n address: accountAddress,\n condition,\n asset: `${assetAddress}.${assetContractName}::${tokenName}`,\n amount,\n };\n}\n\nexport function getStxPostCondition(\n amount: string | bigint | number,\n condition: `${FungibleComparator}`,\n accountAddress: string\n): StxPostCondition {\n return {\n type: \"stx-postcondition\",\n address: accountAddress,\n condition,\n amount,\n };\n}\n"]}
|
|
@@ -41,6 +41,7 @@ class DefaultYieldService {
|
|
|
41
41
|
apr30d: "",
|
|
42
42
|
apr7d: "",
|
|
43
43
|
bridgeId: chainData.bridgeId,
|
|
44
|
+
paddingUtilId: chainData.paddingUtilId,
|
|
44
45
|
bridgeAddress: chainData.bridgeAddress,
|
|
45
46
|
chainId: chainData.chainId,
|
|
46
47
|
chainName: chainData.name,
|
|
@@ -132,6 +133,9 @@ function getChainYieldService(chainSymbol, api, nodeRpcUrlsConfig, ownerAddress,
|
|
|
132
133
|
case index_1.ChainType.ALG: {
|
|
133
134
|
throw new exceptions_1.MethodNotSupportedError();
|
|
134
135
|
}
|
|
136
|
+
case index_1.ChainType.STX: {
|
|
137
|
+
throw new exceptions_1.MethodNotSupportedError();
|
|
138
|
+
}
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../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gBACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChE,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;gBACtD,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;gBACjC,OAAO,IAAI,sBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { MethodNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3, TokenWithChainDetails } from \"../../index\";\nimport { convertIntAmountToFloat } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../index\";\nimport { Provider } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { EvmYieldService } from \"./evm\";\nimport {\n ChainYieldService,\n CYDToken,\n TokenWithChainDetailsYield,\n YieldBalanceParams,\n YieldCheckAllowanceParams,\n YieldGetAllowanceParams,\n YieldGetEstimatedAmountOnDepositParams,\n YieldGetWithdrawProportionAmountParams,\n YieldWithdrawAmount,\n} from \"./models\";\nimport { DefaultRawYieldTransactionBuilder, RawYieldTransactionBuilder } from \"./raw-yield-transaction-builder\";\nimport { TronYieldService } from \"./trx\";\nimport { isYieldSupported } from \"./validations\";\n\nexport interface YieldService {\n rawTxBuilder: RawYieldTransactionBuilder;\n\n /**\n * Returns a list of supported {@link CYDToken}.\n */\n getCYDTokens(): Promise<CYDToken[]>;\n\n /**\n * Get amount of tokens approved for Yield\n * @param provider - will be used to access the network\n * @param params See {@link YieldGetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: YieldGetAllowanceParams, provider?: Provider): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param params See {@link YieldCheckAllowanceParams}\n * @param provider - will be used to access the network\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: YieldCheckAllowanceParams, provider?: Provider): Promise<boolean>;\n\n /**\n * Get token balance\n * @param params\n * @param provider\n * @returns Token balance\n */\n balanceOf(params: YieldBalanceParams, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of CYD tokens that will be deposited\n * @param params - will be used to access the network\n * @param provider - will be used to access the network\n * @returns amount\n */\n getEstimatedAmountOnDeposit(params: YieldGetEstimatedAmountOnDepositParams, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amounts of tokens ({@link YieldWithdrawAmount}) will be withdrawn\n * @param params\n * @param provider - will be used to access the network\n * @returns amounts\n */\n getWithdrawAmounts(\n params: YieldGetWithdrawProportionAmountParams,\n provider?: Provider\n ): Promise<YieldWithdrawAmount[]>;\n}\n\nexport class DefaultYieldService implements YieldService {\n public rawTxBuilder: RawYieldTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawYieldTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getCYDTokens(): Promise<CYDToken[]> {\n const result: CYDToken[] = [];\n const chainMap = await this.api.getChainDetailsMap(\"pool\");\n\n Object.values(chainMap).forEach((chainData) => {\n if (chainData.yieldAddress) {\n const cydToken = chainData.tokens.find((t) => t.tokenAddress === chainData.yieldAddress);\n const tokens: TokenWithChainDetailsYield[] = chainData.tokens.filter(isYieldSupported);\n if (tokens.length > 0) {\n const cydDefined: TokenWithChainDetails = cydToken ?? {\n allbridgeChainId: chainData.allbridgeChainId,\n apr: \"\",\n apr30d: \"\",\n apr7d: \"\",\n bridgeId: chainData.bridgeId,\n bridgeAddress: chainData.bridgeAddress,\n chainId: chainData.chainId,\n chainName: chainData.name,\n chainSymbol: chainData.chainSymbol,\n chainType: chainData.chainType,\n confirmations: chainData.confirmations,\n decimals: 3,\n feeShare: \"\",\n lpRate: \"\",\n name: \"Core Yield\",\n poolAddress: \"\",\n symbol: \"CYD\",\n tokenAddress: chainData.yieldAddress,\n transferTime: {},\n txCostAmount: { maxAmount: \"0\", swap: \"0\", transfer: \"0\" },\n yieldAddress: chainData.yieldAddress,\n };\n result.push({\n ...cydDefined,\n yieldAddress: chainData.yieldAddress,\n tokens: tokens,\n });\n }\n }\n });\n\n return result;\n }\n\n async getAllowance(params: YieldGetAllowanceParams, provider?: Provider): Promise<string> {\n return await this.tokenService.getAllowance({ ...params, spender: params.token.yieldAddress }, provider);\n }\n\n async checkAllowance(params: YieldCheckAllowanceParams, provider?: Provider): Promise<boolean> {\n return this.tokenService.checkAllowance({ ...params, spender: params.token.yieldAddress }, provider);\n }\n\n async balanceOf(params: YieldBalanceParams, provider?: Provider): Promise<string> {\n return getChainYieldService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.owner,\n provider\n ).balanceOf(params);\n }\n\n async getEstimatedAmountOnDeposit(\n params: YieldGetEstimatedAmountOnDepositParams,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n return getChainYieldService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.token.yieldAddress,\n provider\n ).getEstimatedAmountOnDeposit(params);\n }\n\n async getWithdrawAmounts(\n params: YieldGetWithdrawProportionAmountParams,\n provider?: Provider\n ): Promise<YieldWithdrawAmount[]> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, SYSTEM_PRECISION);\n const proportionAmounts = await getChainYieldService(\n params.cydToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.owner,\n provider\n ).getWithdrawProportionAmount(params);\n return params.cydToken.tokens\n .filter((token) => proportionAmounts[token.yieldId] !== undefined)\n .map((token) => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n amount: convertIntAmountToFloat(proportionAmounts[token.yieldId]!, token.decimals).toFixed(),\n token: token,\n }));\n }\n}\n\nexport function getChainYieldService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n ownerAddress: string,\n provider?: Provider\n): ChainYieldService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmYieldService(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 EvmYieldService(web3, api);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronYieldService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });\n tronWeb.setAddress(ownerAddress);\n return new TronYieldService(tronWeb, api);\n }\n }\n case ChainType.SOLANA: {\n throw new MethodNotSupportedError();\n }\n case ChainType.SRB: {\n throw new MethodNotSupportedError();\n }\n case ChainType.SUI: {\n throw new MethodNotSupportedError();\n }\n case ChainType.ALG: {\n throw new MethodNotSupportedError();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/yield/index.ts"],"names":[],"mappings":";;;AAkMA,oDA4CC;AA9OD,qCAAkC;AAClC,+BAAmD;AACnD,yCAAsC;AAGtC,iDAA2D;AAC3D,uCAAuG;AACvG,yDAAkE;AAClE,iEAAqE;AACrE,6CAAiF;AAIjF,+BAAwC;AAYxC,mFAAgH;AAChH,+BAAyC;AACzC,+CAAiD;AAsDjD,MAAa,mBAAmB;IAIpB;IACA;IACA;IACA;IANH,YAAY,CAA6B;IAEhD,YACU,GAAgC,EAChC,iBAAoC,EACpC,MAA+B,EAC/B,YAA0B;QAH1B,QAAG,GAAH,GAAG,CAA6B;QAChC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,WAAM,GAAN,MAAM,CAAyB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,YAAY,GAAG,IAAI,iEAAiC,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;IAC1G,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,MAAM,GAAe,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAE3D,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YAC5C,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;gBAC3B,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CA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E,gBAAS,CAAC,GAAG,EAAE,CAAC;gBAC5E,OAAO,IAAI,qBAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,IAAI,sBAAgB,CAAC,QAAmB,EAAE,GAAG,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChE,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;gBACtD,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;gBACjC,OAAO,IAAI,sBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QACD,KAAK,iBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;QACD,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,MAAM,IAAI,oCAAuB,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { FMT_BYTES, FMT_NUMBER, Web3 } from \"web3\";\nimport { Chains } from \"../../chains\";\nimport { AllbridgeCoreClient } from \"../../client/core-api/core-client-base\";\nimport { AllbridgeCoreClientFiltered } from \"../../client/core-api/core-client-filtered\";\nimport { MethodNotSupportedError } from \"../../exceptions\";\nimport { AllbridgeCoreSdkOptions, ChainType, EssentialWeb3, TokenWithChainDetails } from \"../../index\";\nimport { convertIntAmountToFloat } from \"../../utils/calculation\";\nimport { SYSTEM_PRECISION } from \"../../utils/calculation/constants\";\nimport { validateAmountDecimals, validateAmountGtZero } from \"../../utils/utils\";\nimport { NodeRpcUrlsConfig } from \"../index\";\nimport { Provider } from \"../models\";\nimport { TokenService } from \"../token\";\nimport { EvmYieldService } from \"./evm\";\nimport {\n ChainYieldService,\n CYDToken,\n TokenWithChainDetailsYield,\n YieldBalanceParams,\n YieldCheckAllowanceParams,\n YieldGetAllowanceParams,\n YieldGetEstimatedAmountOnDepositParams,\n YieldGetWithdrawProportionAmountParams,\n YieldWithdrawAmount,\n} from \"./models\";\nimport { DefaultRawYieldTransactionBuilder, RawYieldTransactionBuilder } from \"./raw-yield-transaction-builder\";\nimport { TronYieldService } from \"./trx\";\nimport { isYieldSupported } from \"./validations\";\n\nexport interface YieldService {\n rawTxBuilder: RawYieldTransactionBuilder;\n\n /**\n * Returns a list of supported {@link CYDToken}.\n */\n getCYDTokens(): Promise<CYDToken[]>;\n\n /**\n * Get amount of tokens approved for Yield\n * @param provider - will be used to access the network\n * @param params See {@link YieldGetAllowanceParams}\n * @returns the amount of approved tokens\n */\n getAllowance(params: YieldGetAllowanceParams, provider?: Provider): Promise<string>;\n\n /**\n * Check if the amount of approved tokens is enough\n * @param params See {@link YieldCheckAllowanceParams}\n * @param provider - will be used to access the network\n * @returns true if the amount of approved tokens is enough to make a transfer\n */\n checkAllowance(params: YieldCheckAllowanceParams, provider?: Provider): Promise<boolean>;\n\n /**\n * Get token balance\n * @param params\n * @param provider\n * @returns Token balance\n */\n balanceOf(params: YieldBalanceParams, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amount of CYD tokens that will be deposited\n * @param params - will be used to access the network\n * @param provider - will be used to access the network\n * @returns amount\n */\n getEstimatedAmountOnDeposit(params: YieldGetEstimatedAmountOnDepositParams, provider?: Provider): Promise<string>;\n\n /**\n * Calculates the amounts of tokens ({@link YieldWithdrawAmount}) will be withdrawn\n * @param params\n * @param provider - will be used to access the network\n * @returns amounts\n */\n getWithdrawAmounts(\n params: YieldGetWithdrawProportionAmountParams,\n provider?: Provider\n ): Promise<YieldWithdrawAmount[]>;\n}\n\nexport class DefaultYieldService implements YieldService {\n public rawTxBuilder: RawYieldTransactionBuilder;\n\n constructor(\n private api: AllbridgeCoreClientFiltered,\n private nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n private params: AllbridgeCoreSdkOptions,\n private tokenService: TokenService\n ) {\n this.rawTxBuilder = new DefaultRawYieldTransactionBuilder(api, nodeRpcUrlsConfig, params, tokenService);\n }\n\n async getCYDTokens(): Promise<CYDToken[]> {\n const result: CYDToken[] = [];\n const chainMap = await this.api.getChainDetailsMap(\"pool\");\n\n Object.values(chainMap).forEach((chainData) => {\n if (chainData.yieldAddress) {\n const cydToken = chainData.tokens.find((t) => t.tokenAddress === chainData.yieldAddress);\n const tokens: TokenWithChainDetailsYield[] = chainData.tokens.filter(isYieldSupported);\n if (tokens.length > 0) {\n const cydDefined: TokenWithChainDetails = cydToken ?? {\n allbridgeChainId: chainData.allbridgeChainId,\n apr: \"\",\n apr30d: \"\",\n apr7d: \"\",\n bridgeId: chainData.bridgeId,\n paddingUtilId: chainData.paddingUtilId,\n bridgeAddress: chainData.bridgeAddress,\n chainId: chainData.chainId,\n chainName: chainData.name,\n chainSymbol: chainData.chainSymbol,\n chainType: chainData.chainType,\n confirmations: chainData.confirmations,\n decimals: 3,\n feeShare: \"\",\n lpRate: \"\",\n name: \"Core Yield\",\n poolAddress: \"\",\n symbol: \"CYD\",\n tokenAddress: chainData.yieldAddress,\n transferTime: {},\n txCostAmount: { maxAmount: \"0\", swap: \"0\", transfer: \"0\" },\n yieldAddress: chainData.yieldAddress,\n };\n result.push({\n ...cydDefined,\n yieldAddress: chainData.yieldAddress,\n tokens: tokens,\n });\n }\n }\n });\n\n return result;\n }\n\n async getAllowance(params: YieldGetAllowanceParams, provider?: Provider): Promise<string> {\n return await this.tokenService.getAllowance({ ...params, spender: params.token.yieldAddress }, provider);\n }\n\n async checkAllowance(params: YieldCheckAllowanceParams, provider?: Provider): Promise<boolean> {\n return this.tokenService.checkAllowance({ ...params, spender: params.token.yieldAddress }, provider);\n }\n\n async balanceOf(params: YieldBalanceParams, provider?: Provider): Promise<string> {\n return getChainYieldService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.owner,\n provider\n ).balanceOf(params);\n }\n\n async getEstimatedAmountOnDeposit(\n params: YieldGetEstimatedAmountOnDepositParams,\n provider?: Provider\n ): Promise<string> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, params.token.decimals);\n return getChainYieldService(\n params.token.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.token.yieldAddress,\n provider\n ).getEstimatedAmountOnDeposit(params);\n }\n\n async getWithdrawAmounts(\n params: YieldGetWithdrawProportionAmountParams,\n provider?: Provider\n ): Promise<YieldWithdrawAmount[]> {\n validateAmountGtZero(params.amount);\n validateAmountDecimals(\"amount\", params.amount, SYSTEM_PRECISION);\n const proportionAmounts = await getChainYieldService(\n params.cydToken.chainSymbol,\n this.api,\n this.nodeRpcUrlsConfig,\n params.owner,\n provider\n ).getWithdrawProportionAmount(params);\n return params.cydToken.tokens\n .filter((token) => proportionAmounts[token.yieldId] !== undefined)\n .map((token) => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n amount: convertIntAmountToFloat(proportionAmounts[token.yieldId]!, token.decimals).toFixed(),\n token: token,\n }));\n }\n}\n\nexport function getChainYieldService(\n chainSymbol: string,\n api: AllbridgeCoreClient,\n nodeRpcUrlsConfig: NodeRpcUrlsConfig,\n ownerAddress: string,\n provider?: Provider\n): ChainYieldService {\n switch (Chains.getChainProperty(chainSymbol).chainType) {\n case ChainType.EVM: {\n if (provider) {\n return new EvmYieldService(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 EvmYieldService(web3, api);\n }\n }\n case ChainType.TRX: {\n if (provider) {\n return new TronYieldService(provider as TronWeb, api);\n } else {\n const nodeRpcUrl = nodeRpcUrlsConfig.getNodeRpcUrl(chainSymbol);\n const tronWeb = new TronWeb({ fullHost: nodeRpcUrl });\n tronWeb.setAddress(ownerAddress);\n return new TronYieldService(tronWeb, api);\n }\n }\n case ChainType.SOLANA: {\n throw new MethodNotSupportedError();\n }\n case ChainType.SRB: {\n throw new MethodNotSupportedError();\n }\n case ChainType.SUI: {\n throw new MethodNotSupportedError();\n }\n case ChainType.ALG: {\n throw new MethodNotSupportedError();\n }\n case ChainType.STX: {\n throw new MethodNotSupportedError();\n }\n }\n}\n"]}
|
|
@@ -9,6 +9,17 @@ import { Messenger } from "../client/core-api/core-api.model";
|
|
|
9
9
|
*/
|
|
10
10
|
export type ChainDetailsMap = Record<string, ChainDetailsWithTokens>;
|
|
11
11
|
export type ChainDetailsMapWithFlags = Record<string, ChainDetailsWithTokensWithFlags>;
|
|
12
|
+
export interface AbrPayerChainInfo {
|
|
13
|
+
/**
|
|
14
|
+
* ABR proxy for paying fees with ABR
|
|
15
|
+
*/
|
|
16
|
+
payerAddress: string;
|
|
17
|
+
abrToken: TokenCoreFields;
|
|
18
|
+
/**
|
|
19
|
+
* Availability to pay by abr
|
|
20
|
+
*/
|
|
21
|
+
payerAvailability: AbrPayerAvailability;
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* Contains some blockchain details
|
|
14
25
|
*/
|
|
@@ -21,6 +32,10 @@ export interface ChainDetails extends BasicChainProperties {
|
|
|
21
32
|
* Algo Bridge appId
|
|
22
33
|
*/
|
|
23
34
|
bridgeId?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Algo Padding appId
|
|
37
|
+
*/
|
|
38
|
+
paddingUtilId?: string;
|
|
24
39
|
/**
|
|
25
40
|
* Bridge contract address
|
|
26
41
|
*/
|
|
@@ -34,6 +49,10 @@ export interface ChainDetails extends BasicChainProperties {
|
|
|
34
49
|
* Yield contract address
|
|
35
50
|
*/
|
|
36
51
|
yieldAddress?: string;
|
|
52
|
+
/**
|
|
53
|
+
* ABR payer chain info
|
|
54
|
+
*/
|
|
55
|
+
abrPayer?: AbrPayerChainInfo;
|
|
37
56
|
/**
|
|
38
57
|
* Average transfer time to other blockchains
|
|
39
58
|
*/
|
|
@@ -187,6 +206,7 @@ export interface TokenWithChainDetails extends Token, Omit<ChainDetails, "name">
|
|
|
187
206
|
*/
|
|
188
207
|
chainName: string;
|
|
189
208
|
}
|
|
209
|
+
export type TokenCoreFields = Pick<TokenWithChainDetails, "tokenAddress" | "chainSymbol" | "decimals" | "originTokenAddress">;
|
|
190
210
|
export interface TokenWithChainDetailsWithFlags extends TokenWithChainDetails {
|
|
191
211
|
flags: {
|
|
192
212
|
swap: boolean;
|
|
@@ -230,6 +250,7 @@ export interface PoolInfo {
|
|
|
230
250
|
*/
|
|
231
251
|
imbalance: string;
|
|
232
252
|
}
|
|
253
|
+
export type AbrPayerAvailability = Partial<Record<Messenger, boolean>>;
|
|
233
254
|
/**
|
|
234
255
|
* Type representing transfer times for various blockchain chains.
|
|
235
256
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens-info.model.js","sourceRoot":"","sources":["../../../src/tokens-info/tokens-info.model.ts"],"names":[],"mappings":"","sourcesContent":["import { BasicChainProperties } from \"../chains/models\";\nimport { Messenger } from \"../client/core-api/core-api.model\";\n\n/**\n * Type representing a map of blockchain chain symbols to their corresponding details, including token information.\n *\n * @typedef {Record<string, ChainDetailsWithTokens>} ChainDetailsMap\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {ChainDetailsWithTokens} chainDetails - The detailed information of the specified chain, including token information.\n */\nexport type ChainDetailsMap = Record<string, ChainDetailsWithTokens>;\n\nexport type ChainDetailsMapWithFlags = Record<string, ChainDetailsWithTokensWithFlags>;\n\n/**\n * Contains some blockchain details\n */\nexport interface ChainDetails extends BasicChainProperties {\n /**\n * Allbridge's Id\n */\n allbridgeChainId: number;\n /**\n * Algo Bridge appId\n */\n bridgeId?: string;\n /**\n * Bridge contract address\n */\n bridgeAddress: string;\n /**\n * OFT Bridge contract address\n * Optional. Defined if the chain supports OFT\n */\n oftBridgeAddress?: string;\n /**\n * Yield contract address\n */\n yieldAddress?: string;\n /**\n * Average transfer time to other blockchains\n */\n transferTime: TransferTime;\n /**\n * Transfers costs\n */\n txCostAmount: TxCostAmount;\n /**\n * Number of confirmations required\n */\n confirmations: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\n/**\n * Contains tokens list\n */\nexport interface ChainDetailsWithTokens extends ChainDetails {\n /**\n * Tokens\n */\n tokens: TokenWithChainDetails[];\n}\n\n/**\n * Contains tokens list\n */\nexport interface ChainDetailsWithTokensWithFlags extends ChainDetails {\n /**\n * Tokens\n */\n tokens: TokenWithChainDetailsWithFlags[];\n}\n\n/**\n * Contains token information\n */\nexport interface Token {\n /**\n * Token symbol\n */\n symbol: string;\n /**\n * Token name\n */\n name: string;\n /**\n * Token decimals\n */\n decimals: number;\n /**\n * Token pool address\n */\n poolAddress: string;\n /**\n * Token address\n */\n tokenAddress: string;\n /**\n * Token origin address\n */\n originTokenAddress?: string;\n /**\n * Token CCTP address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpAddress?: string;\n /**\n * Token CCTP V2 address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpFeeShare?: string;\n /**\n * Token CCTP address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpV2Address?: string;\n /**\n * Token CCTP V2 address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpV2FeeShare?: string;\n /**\n * Internal identifier for the same token across different chains.\n *\n * Used to link representations of a token deployed on multiple networks (e.g., Ethereum, BSC).\n * Tokens with the same `oftId` are considered to be equivalent.\n *\n * Optional. Defined if OFT supported by token\n */\n oftId?: string;\n /**\n * Token fee share\n */\n feeShare: string;\n /**\n * @Deprecated use {@link apr7d}</br>\n * Token APR\n */\n apr: string;\n /**\n * Token APR based on last 7 days\n */\n apr7d: string;\n /**\n * Token APR based on last 30 days\n */\n apr30d: string;\n /**\n * Token LP rate\n */\n lpRate: string;\n\n yieldId?: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\nexport interface SuiAddresses {\n bridgeAddress: string;\n bridgeAddressOrigin?: string;\n bridgeObjectAddress: string;\n\n allbridgeMessengerAddress: string;\n allbridgeMessengerAddressOrigin?: string;\n allbridgeMessengerObjectAddress: string;\n\n gasOracleAddress: string;\n gasOracleAddressOrigin?: string;\n gasOracleObjectAddress: string;\n\n utilsAddress: string;\n\n wormholeMessengerAddress: string;\n wormholeMessengerAddressOrigin?: string;\n wormholeMessengerObjectAddress: string;\n wormholeStateObjectAddress: string;\n\n cctpAddress: string;\n cctpAddressOrigin?: string;\n cctpObjectAddress: string;\n\n cctpDenyListObjectAddress: string;\n cctpMessageTransmitterStateObjectAddress: string;\n cctpTokenMessengerMinterStateObjectAddress: string;\n cctpTreasuryObjectAddress: string;\n}\n\n/**\n * General Token Interface\n */\nexport interface TokenWithChainDetails extends Token, Omit<ChainDetails, \"name\"> {\n /**\n * Blockchain network name\n */\n chainName: string;\n}\n\nexport interface TokenWithChainDetailsWithFlags extends TokenWithChainDetails {\n flags: { swap: boolean; pool: boolean };\n}\n\n/**\n * General Pool Interface\n */\nexport interface PoolInfo {\n /**\n * Pool A value\n */\n aValue: string;\n /**\n * Pool D value\n */\n dValue: string;\n /**\n * Pool token balance\n */\n tokenBalance: string;\n /**\n * Pool virtual USD balance\n */\n vUsdBalance: string;\n /**\n * Pool total liquidity amount\n */\n totalLpAmount: string;\n /**\n * Current accumulated reward per share shifted by P bits\n */\n accRewardPerShareP: string;\n /**\n * P value, needed for accRewardPerShareP\n */\n p: number;\n /**\n * Pool imbalance\n */\n imbalance: string;\n}\n\n/**\n * Type representing transfer times for various blockchain chains.\n *\n * @typedef {Record<string, MessengerTransferTime>} TransferTime\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {MessengerTransferTime} transferTime - The average transfer time details for the specified chain.\n */\nexport type TransferTime = Record<string, MessengerTransferTime>;\n\n/**\n * Contains Avg transaction time withing different messenger protocols\n */\nexport type MessengerTransferTime = {\n [messenger in Messenger]?: number;\n};\n\nexport interface PoolKeyObject {\n chainSymbol: string;\n poolAddress: string;\n}\n\n/**\n * Contains transfer costs\n */\nexport interface TxCostAmount {\n /**\n * The maximum gas amount that can be received as extra gas for one transfer\n */\n maxAmount: string;\n /**\n * Swap cost\n */\n swap: string;\n /**\n * Transfer cost\n */\n transfer: string;\n}\n\nexport type PoolInfoMap = Record<string, PoolInfo>;\n"]}
|
|
1
|
+
{"version":3,"file":"tokens-info.model.js","sourceRoot":"","sources":["../../../src/tokens-info/tokens-info.model.ts"],"names":[],"mappings":"","sourcesContent":["import { BasicChainProperties } from \"../chains/models\";\nimport { Messenger } from \"../client/core-api/core-api.model\";\n\n/**\n * Type representing a map of blockchain chain symbols to their corresponding details, including token information.\n *\n * @typedef {Record<string, ChainDetailsWithTokens>} ChainDetailsMap\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {ChainDetailsWithTokens} chainDetails - The detailed information of the specified chain, including token information.\n */\nexport type ChainDetailsMap = Record<string, ChainDetailsWithTokens>;\n\nexport type ChainDetailsMapWithFlags = Record<string, ChainDetailsWithTokensWithFlags>;\n\nexport interface AbrPayerChainInfo {\n /**\n * ABR proxy for paying fees with ABR\n */\n payerAddress: string;\n abrToken: TokenCoreFields;\n /**\n * Availability to pay by abr\n */\n payerAvailability: AbrPayerAvailability;\n}\n\n/**\n * Contains some blockchain details\n */\nexport interface ChainDetails extends BasicChainProperties {\n /**\n * Allbridge's Id\n */\n allbridgeChainId: number;\n /**\n * Algo Bridge appId\n */\n bridgeId?: string;\n /**\n * Algo Padding appId\n */\n paddingUtilId?: string;\n /**\n * Bridge contract address\n */\n bridgeAddress: string;\n /**\n * OFT Bridge contract address\n * Optional. Defined if the chain supports OFT\n */\n oftBridgeAddress?: string;\n /**\n * Yield contract address\n */\n yieldAddress?: string;\n /**\n * ABR payer chain info\n */\n abrPayer?: AbrPayerChainInfo;\n /**\n * Average transfer time to other blockchains\n */\n transferTime: TransferTime;\n /**\n * Transfers costs\n */\n txCostAmount: TxCostAmount;\n /**\n * Number of confirmations required\n */\n confirmations: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\n/**\n * Contains tokens list\n */\nexport interface ChainDetailsWithTokens extends ChainDetails {\n /**\n * Tokens\n */\n tokens: TokenWithChainDetails[];\n}\n\n/**\n * Contains tokens list\n */\nexport interface ChainDetailsWithTokensWithFlags extends ChainDetails {\n /**\n * Tokens\n */\n tokens: TokenWithChainDetailsWithFlags[];\n}\n\n/**\n * Contains token information\n */\nexport interface Token {\n /**\n * Token symbol\n */\n symbol: string;\n /**\n * Token name\n */\n name: string;\n /**\n * Token decimals\n */\n decimals: number;\n /**\n * Token pool address\n */\n poolAddress: string;\n /**\n * Token address\n */\n tokenAddress: string;\n /**\n * Token origin address\n */\n originTokenAddress?: string;\n /**\n * Token CCTP address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpAddress?: string;\n /**\n * Token CCTP V2 address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpFeeShare?: string;\n /**\n * Token CCTP address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpV2Address?: string;\n /**\n * Token CCTP V2 address</br>\n * Optional. Defined if CCTP supported by token\n */\n cctpV2FeeShare?: string;\n /**\n * Internal identifier for the same token across different chains.\n *\n * Used to link representations of a token deployed on multiple networks (e.g., Ethereum, BSC).\n * Tokens with the same `oftId` are considered to be equivalent.\n *\n * Optional. Defined if OFT supported by token\n */\n oftId?: string;\n /**\n * Token fee share\n */\n feeShare: string;\n /**\n * @Deprecated use {@link apr7d}</br>\n * Token APR\n */\n apr: string;\n /**\n * Token APR based on last 7 days\n */\n apr7d: string;\n /**\n * Token APR based on last 30 days\n */\n apr30d: string;\n /**\n * Token LP rate\n */\n lpRate: string;\n\n yieldId?: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\nexport interface SuiAddresses {\n bridgeAddress: string;\n bridgeAddressOrigin?: string;\n bridgeObjectAddress: string;\n\n allbridgeMessengerAddress: string;\n allbridgeMessengerAddressOrigin?: string;\n allbridgeMessengerObjectAddress: string;\n\n gasOracleAddress: string;\n gasOracleAddressOrigin?: string;\n gasOracleObjectAddress: string;\n\n utilsAddress: string;\n\n wormholeMessengerAddress: string;\n wormholeMessengerAddressOrigin?: string;\n wormholeMessengerObjectAddress: string;\n wormholeStateObjectAddress: string;\n\n cctpAddress: string;\n cctpAddressOrigin?: string;\n cctpObjectAddress: string;\n\n cctpDenyListObjectAddress: string;\n cctpMessageTransmitterStateObjectAddress: string;\n cctpTokenMessengerMinterStateObjectAddress: string;\n cctpTreasuryObjectAddress: string;\n}\n\n/**\n * General Token Interface\n */\nexport interface TokenWithChainDetails extends Token, Omit<ChainDetails, \"name\"> {\n /**\n * Blockchain network name\n */\n chainName: string;\n}\n\nexport type TokenCoreFields = Pick<\n TokenWithChainDetails,\n \"tokenAddress\" | \"chainSymbol\" | \"decimals\" | \"originTokenAddress\"\n>;\n\nexport interface TokenWithChainDetailsWithFlags extends TokenWithChainDetails {\n flags: { swap: boolean; pool: boolean };\n}\n\n/**\n * General Pool Interface\n */\nexport interface PoolInfo {\n /**\n * Pool A value\n */\n aValue: string;\n /**\n * Pool D value\n */\n dValue: string;\n /**\n * Pool token balance\n */\n tokenBalance: string;\n /**\n * Pool virtual USD balance\n */\n vUsdBalance: string;\n /**\n * Pool total liquidity amount\n */\n totalLpAmount: string;\n /**\n * Current accumulated reward per share shifted by P bits\n */\n accRewardPerShareP: string;\n /**\n * P value, needed for accRewardPerShareP\n */\n p: number;\n /**\n * Pool imbalance\n */\n imbalance: string;\n}\n\nexport type AbrPayerAvailability = Partial<Record<Messenger, boolean>>;\n\n/**\n * Type representing transfer times for various blockchain chains.\n *\n * @typedef {Record<string, MessengerTransferTime>} TransferTime\n * @property {string} chainSymbol - The symbol of the chain representing one of the supported blockchain networks (e.g., \"ETH\" for Ethereum). For more details, see: {@link ChainSymbol}.\n * @property {MessengerTransferTime} transferTime - The average transfer time details for the specified chain.\n */\nexport type TransferTime = Record<string, MessengerTransferTime>;\n\n/**\n * Contains Avg transaction time withing different messenger protocols\n */\nexport type MessengerTransferTime = {\n [messenger in Messenger]?: number;\n};\n\nexport interface PoolKeyObject {\n chainSymbol: string;\n poolAddress: string;\n}\n\n/**\n * Contains transfer costs\n */\nexport interface TxCostAmount {\n /**\n * The maximum gas amount that can be received as extra gas for one transfer\n */\n maxAmount: string;\n /**\n * Swap cost\n */\n swap: string;\n /**\n * Transfer cost\n */\n transfer: string;\n}\n\nexport type PoolInfoMap = Record<string, PoolInfo>;\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Big, BigSource } from "big.js";
|
|
2
2
|
import { AllbridgeCoreClientPoolsExt } from "../client/core-api/core-client-pool-info-caching";
|
|
3
3
|
import { PoolInfo, TokenWithChainDetails } from "../tokens-info";
|
|
4
|
+
export declare function assertNever(x: never, message?: string): never;
|
|
4
5
|
export declare function getPoolInfoByToken(api: AllbridgeCoreClientPoolsExt, sourceChainToken: TokenWithChainDetails): Promise<PoolInfo>;
|
|
5
6
|
export declare function validateAmountGtZero(amount: BigSource): void;
|
|
7
|
+
export declare function validateAmountGteZero(amount: BigSource): void;
|
|
6
8
|
export declare function validateAmountDecimals(argName: string, amountFloat: number | string | Big, decimalRequired: number): void;
|
|
7
9
|
export declare function promiseWithTimeout<T>(promise: Promise<T>, msg: string, timeoutMs: number): Promise<T>;
|
|
8
10
|
export declare function promiseWithTimeoutAndRetries<T>(toTry: () => Promise<T>, msg: string, maxRetries: number, timeoutMs: number): Promise<T>;
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNever = assertNever;
|
|
3
4
|
exports.getPoolInfoByToken = getPoolInfoByToken;
|
|
4
5
|
exports.validateAmountGtZero = validateAmountGtZero;
|
|
6
|
+
exports.validateAmountGteZero = validateAmountGteZero;
|
|
5
7
|
exports.validateAmountDecimals = validateAmountDecimals;
|
|
6
8
|
exports.promiseWithTimeout = promiseWithTimeout;
|
|
7
9
|
exports.promiseWithTimeoutAndRetries = promiseWithTimeoutAndRetries;
|
|
8
10
|
exports.withExponentialBackoff = withExponentialBackoff;
|
|
9
11
|
const big_js_1 = require("big.js");
|
|
10
12
|
const exceptions_1 = require("../exceptions");
|
|
13
|
+
function assertNever(x, message) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
15
|
+
throw new Error(message ?? `Unexpected value: ${x}`);
|
|
16
|
+
}
|
|
11
17
|
async function getPoolInfoByToken(api, sourceChainToken) {
|
|
12
18
|
return await api.getPoolInfoByKey({
|
|
13
19
|
chainSymbol: sourceChainToken.chainSymbol,
|
|
@@ -19,6 +25,11 @@ function validateAmountGtZero(amount) {
|
|
|
19
25
|
throw new exceptions_1.InvalidAmountError("Amount must be greater than zero");
|
|
20
26
|
}
|
|
21
27
|
}
|
|
28
|
+
function validateAmountGteZero(amount) {
|
|
29
|
+
if ((0, big_js_1.Big)(amount).lt(0)) {
|
|
30
|
+
throw new exceptions_1.InvalidAmountError("Amount must be greater or equal than zero");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
function validateAmountDecimals(argName, amountFloat, decimalRequired) {
|
|
23
34
|
const amount = (0, big_js_1.Big)(amountFloat).toFixed();
|
|
24
35
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;AAKA,gDAQC;AAED,oDAIC;AAED,wDAQC;AAED,gDAOC;AAED,oEAgBC;AAMD,wDAwDC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;AAKA,kCAGC;AAED,gDAQC;AAED,oDAIC;AAED,sDAIC;AAED,wDAQC;AAED,gDAOC;AAED,oEAgBC;AAMD,wDAwDC;AAjID,mCAAwC;AAExC,8CAA+F;AAG/F,SAAgB,WAAW,CAAC,CAAQ,EAAE,OAAgB;IACpD,4EAA4E;IAC5E,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,qBAAqB,CAAC,EAAE,CAAC,CAAC;AACvD,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,GAAgC,EAChC,gBAAuC;IAEvC,OAAO,MAAM,GAAG,CAAC,gBAAgB,CAAC;QAChC,WAAW,EAAE,gBAAgB,CAAC,WAAW;QACzC,WAAW,EAAE,gBAAgB,CAAC,WAAW;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAiB;IACpD,IAAI,IAAA,YAAG,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,+BAAkB,CAAC,kCAAkC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;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C,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtD,sBAAsB;QACtB,QAAQ,GAAG,QAAQ,GAAG,iBAAiB,CAAC;QACxC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC;YAC1D,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAClC,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,IAAI,CAAC,0CAA0C,QAAQ,IAAI,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;QACD,aAAa,GAAG,QAAQ,GAAG,aAAa,CAAC;QACzC,YAAY;QACZ,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC;QAC1C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3B,IAAI,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1C,OAAO,CAAC,IAAI,CACV,GAAG,KAAK,YAAY,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,gCAAgC,IAAI,CAAC,SAAS,CAC3F,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,EAC7B,IAAI,EACJ,CAAC,CACF,EAAE,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { Big, BigSource } from \"big.js\";\nimport { AllbridgeCoreClientPoolsExt } from \"../client/core-api/core-client-pool-info-caching\";\nimport { ArgumentInvalidDecimalsError, InvalidAmountError, TimeoutError } from \"../exceptions\";\nimport { PoolInfo, TokenWithChainDetails } from \"../tokens-info\";\n\nexport function assertNever(x: never, message?: string): never {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(message ?? `Unexpected value: ${x}`);\n}\n\nexport async function getPoolInfoByToken(\n api: AllbridgeCoreClientPoolsExt,\n sourceChainToken: TokenWithChainDetails\n): Promise<PoolInfo> {\n return await api.getPoolInfoByKey({\n chainSymbol: sourceChainToken.chainSymbol,\n poolAddress: sourceChainToken.poolAddress,\n });\n}\n\nexport function validateAmountGtZero(amount: BigSource) {\n if (Big(amount).lte(0)) {\n throw new InvalidAmountError(\"Amount must be greater than zero\");\n }\n}\n\nexport function validateAmountGteZero(amount: BigSource) {\n if (Big(amount).lt(0)) {\n throw new InvalidAmountError(\"Amount must be greater or equal than zero\");\n }\n}\n\nexport function validateAmountDecimals(argName: string, amountFloat: number | string | Big, decimalRequired: number) {\n const amount = Big(amountFloat).toFixed();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [integerPart, fractionalPart] = amount.split(\".\");\n\n if (fractionalPart && fractionalPart.length > decimalRequired) {\n throw new ArgumentInvalidDecimalsError(argName, fractionalPart.length, decimalRequired);\n }\n}\n\nexport async function promiseWithTimeout<T>(promise: Promise<T>, msg: string, timeoutMs: number): Promise<T> {\n return (await Promise.race([\n promise,\n new Promise((resolve, reject) => {\n setTimeout(() => reject(new TimeoutError(msg)), timeoutMs);\n }),\n ])) as any as T;\n}\n\nexport async function promiseWithTimeoutAndRetries<T>(\n toTry: () => Promise<T>,\n msg: string,\n maxRetries: number,\n timeoutMs: number\n): Promise<T> {\n if (maxRetries < 1)\n throw new Error(`Bad argument: 'maxRetries' must be greater than 0, but ${maxRetries} was received.`);\n let attemptCount = 0;\n while (true) {\n try {\n return await promiseWithTimeout(toTry(), msg, timeoutMs);\n } catch (ignoreError) {\n if (++attemptCount >= maxRetries) throw new TimeoutError(msg);\n }\n }\n}\n\n/**\n * Keep calling a `fn` for `secondsToWait` seconds, if `keepWaitingIf` is true.\n * Returns an array of all attempts to call the function.\n */\nexport async function withExponentialBackoff<T>(\n fn: (previousFailure?: T) => Promise<T>,\n keepWaitingIf: (result: T) => boolean,\n secondsToWait: number,\n exponentialFactor = 1.5,\n verbose = false\n): Promise<T[]> {\n const attempts: T[] = [];\n\n let count = 0;\n const initialAttempt = await fn();\n attempts.push(initialAttempt);\n if (!keepWaitingIf(initialAttempt)) return attempts;\n\n const waitUntil = new Date(Date.now() + secondsToWait * 1000).valueOf();\n let waitTime = 1000;\n let totalWaitTime = waitTime;\n\n while (Date.now() < waitUntil) {\n const lastAttempt = attempts[attempts.length - 1];\n if (lastAttempt === undefined || !keepWaitingIf(lastAttempt)) break;\n\n count++;\n // Wait a beat\n if (verbose) {\n console.info(\n `Waiting ${waitTime}ms before trying again (bringing the total wait time to ${totalWaitTime}ms so far, of total ${\n secondsToWait * 1000\n }ms)`\n );\n }\n await new Promise((res) => setTimeout(res, waitTime));\n // Exponential backoff\n waitTime = waitTime * exponentialFactor;\n if (new Date(Date.now() + waitTime).valueOf() > waitUntil) {\n waitTime = waitUntil - Date.now();\n if (verbose) {\n console.info(`was gonna wait too long; new waitTime: ${waitTime}ms`);\n }\n }\n totalWaitTime = waitTime + totalWaitTime;\n // Try again\n const nextAttempt = await fn(lastAttempt);\n attempts.push(nextAttempt);\n if (verbose && keepWaitingIf(nextAttempt)) {\n console.info(\n `${count}. Called ${fn.name}; ${attempts.length} prev attempts. Most recent: ${JSON.stringify(\n attempts[attempts.length - 1],\n null,\n 2\n )}`\n );\n }\n }\n\n return attempts;\n}\n"]}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.27.0-alpha.
|
|
1
|
+
export declare const VERSION = "3.27.0-alpha.20";
|
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,iBAAiB,CAAC","sourcesContent":["export const VERSION = \"3.27.0-alpha.20\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbridge/bridge-core-sdk",
|
|
3
|
-
"version": "3.27.0-alpha.
|
|
3
|
+
"version": "3.27.0-alpha.20",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"@semantic-release/changelog": "^6.0.3",
|
|
59
59
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
60
60
|
"@semantic-release/github": "^11.0.3",
|
|
61
|
+
"@semantic-release/gitlab": "^13.2.9",
|
|
61
62
|
"@semantic-release/npm": "^12.0.2",
|
|
62
63
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
63
64
|
"@types/big.js": "^6.2.2",
|
|
@@ -101,12 +102,15 @@
|
|
|
101
102
|
},
|
|
102
103
|
"dependencies": {
|
|
103
104
|
"@algorandfoundation/algokit-utils": "^9.1.2",
|
|
105
|
+
"@clarigen/core": "^3.1.0",
|
|
104
106
|
"@mysten/sui": "1.18.0",
|
|
105
107
|
"@project-serum/anchor": "^0.25.0",
|
|
106
108
|
"@solana/spl-token": "^0.3.8",
|
|
107
109
|
"@solana/web3.js": "^1.98.0",
|
|
110
|
+
"@stacks/network": "^7.2.0",
|
|
111
|
+
"@stacks/transactions": "^7.2.0",
|
|
108
112
|
"@stellar/stellar-sdk": "^14.0.0",
|
|
109
|
-
"algosdk": "^3.5.
|
|
113
|
+
"algosdk": "^3.5.2",
|
|
110
114
|
"assert": "^2.1.0",
|
|
111
115
|
"axios": "^1.7.9",
|
|
112
116
|
"big.js": "^6.2.2",
|