@allbridge/bridge-core-sdk 3.36.0-beta.1 → 3.36.0-beta.3

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.
Files changed (103) hide show
  1. package/dist/browser/index.js +2 -2
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/index.js.map +4 -4
  5. package/dist/esm/index.js +2 -2
  6. package/dist/esm/index.js.map +4 -4
  7. package/dist/src/client/core-api/api-client-caching.d.ts +6 -1
  8. package/dist/src/client/core-api/api-client-caching.js +11 -0
  9. package/dist/src/client/core-api/api-client-caching.js.map +1 -1
  10. package/dist/src/client/core-api/api-client.d.ts +27 -1
  11. package/dist/src/client/core-api/api-client.js +68 -2
  12. package/dist/src/client/core-api/api-client.js.map +1 -1
  13. package/dist/src/client/core-api/core-api-mapper.d.ts +3 -1
  14. package/dist/src/client/core-api/core-api-mapper.js +6 -3
  15. package/dist/src/client/core-api/core-api-mapper.js.map +1 -1
  16. package/dist/src/client/core-api/core-api.model.d.ts +118 -3
  17. package/dist/src/client/core-api/core-api.model.js +9 -0
  18. package/dist/src/client/core-api/core-api.model.js.map +1 -1
  19. package/dist/src/client/core-api/core-client-base.d.ts +7 -1
  20. package/dist/src/client/core-api/core-client-base.js +9 -0
  21. package/dist/src/client/core-api/core-client-base.js.map +1 -1
  22. package/dist/src/client/core-api/core-client-filtered.d.ts +4 -1
  23. package/dist/src/client/core-api/core-client-filtered.js +9 -0
  24. package/dist/src/client/core-api/core-client-filtered.js.map +1 -1
  25. package/dist/src/client/core-api/core-client-pool-info-caching.d.ts +4 -1
  26. package/dist/src/client/core-api/core-client-pool-info-caching.js +9 -0
  27. package/dist/src/client/core-api/core-client-pool-info-caching.js.map +1 -1
  28. package/dist/src/exceptions/exceptions.d.ts +41 -0
  29. package/dist/src/exceptions/exceptions.js +52 -0
  30. package/dist/src/exceptions/exceptions.js.map +1 -1
  31. package/dist/src/index.d.ts +19 -6
  32. package/dist/src/index.js +6 -1
  33. package/dist/src/index.js.map +1 -1
  34. package/dist/src/models/index.d.ts +4 -2
  35. package/dist/src/models/index.js.map +1 -1
  36. package/dist/src/services/bridge/alg/index.d.ts +5 -1
  37. package/dist/src/services/bridge/alg/index.js +7 -0
  38. package/dist/src/services/bridge/alg/index.js.map +1 -1
  39. package/dist/src/services/bridge/evm/index.d.ts +12 -2
  40. package/dist/src/services/bridge/evm/index.js +32 -0
  41. package/dist/src/services/bridge/evm/index.js.map +1 -1
  42. package/dist/src/services/bridge/index.d.ts +10 -3
  43. package/dist/src/services/bridge/index.js +27 -3
  44. package/dist/src/services/bridge/index.js.map +1 -1
  45. package/dist/src/services/bridge/models/bridge.d.ts +17 -1
  46. package/dist/src/services/bridge/models/bridge.js +6 -0
  47. package/dist/src/services/bridge/models/bridge.js.map +1 -1
  48. package/dist/src/services/bridge/models/bridge.model.d.ts +25 -0
  49. package/dist/src/services/bridge/models/bridge.model.js.map +1 -1
  50. package/dist/src/services/bridge/raw-bridge-transaction-builder.d.ts +8 -1
  51. package/dist/src/services/bridge/raw-bridge-transaction-builder.js +11 -1
  52. package/dist/src/services/bridge/raw-bridge-transaction-builder.js.map +1 -1
  53. package/dist/src/services/bridge/sol/bridge-tx-service.js +3 -0
  54. package/dist/src/services/bridge/sol/bridge-tx-service.js.map +1 -1
  55. package/dist/src/services/bridge/sol/index.d.ts +14 -1
  56. package/dist/src/services/bridge/sol/index.js +47 -2
  57. package/dist/src/services/bridge/sol/index.js.map +1 -1
  58. package/dist/src/services/bridge/sol/payer-with-token-service.js +3 -0
  59. package/dist/src/services/bridge/sol/payer-with-token-service.js.map +1 -1
  60. package/dist/src/services/bridge/spender.js +4 -0
  61. package/dist/src/services/bridge/spender.js.map +1 -1
  62. package/dist/src/services/bridge/srb/index.d.ts +9 -1
  63. package/dist/src/services/bridge/srb/index.js +45 -3
  64. package/dist/src/services/bridge/srb/index.js.map +1 -1
  65. package/dist/src/services/bridge/stx/index.d.ts +6 -2
  66. package/dist/src/services/bridge/stx/index.js +7 -0
  67. package/dist/src/services/bridge/stx/index.js.map +1 -1
  68. package/dist/src/services/bridge/sui/index.d.ts +8 -1
  69. package/dist/src/services/bridge/sui/index.js +24 -0
  70. package/dist/src/services/bridge/sui/index.js.map +1 -1
  71. package/dist/src/services/bridge/trx/index.d.ts +11 -1
  72. package/dist/src/services/bridge/trx/index.js +25 -0
  73. package/dist/src/services/bridge/trx/index.js.map +1 -1
  74. package/dist/src/services/bridge/utils.js +4 -1
  75. package/dist/src/services/bridge/utils.js.map +1 -1
  76. package/dist/src/services/index.d.ts +10 -0
  77. package/dist/src/services/index.js +36 -1
  78. package/dist/src/services/index.js.map +1 -1
  79. package/dist/src/services/near-intents/index.d.ts +62 -0
  80. package/dist/src/services/near-intents/index.js +115 -0
  81. package/dist/src/services/near-intents/index.js.map +1 -0
  82. package/dist/src/services/near-intents/models.d.ts +169 -0
  83. package/dist/src/services/near-intents/models.js +2 -0
  84. package/dist/src/services/near-intents/models.js.map +1 -0
  85. package/dist/src/services/near-intents/utils.d.ts +34 -0
  86. package/dist/src/services/near-intents/utils.js +53 -0
  87. package/dist/src/services/near-intents/utils.js.map +1 -0
  88. package/dist/src/services/token/evm/index.js +3 -0
  89. package/dist/src/services/token/evm/index.js.map +1 -1
  90. package/dist/src/services/token/sol/index.js +3 -0
  91. package/dist/src/services/token/sol/index.js.map +1 -1
  92. package/dist/src/services/token/srb/index.js +11 -0
  93. package/dist/src/services/token/srb/index.js.map +1 -1
  94. package/dist/src/services/token/sui/index.js +5 -0
  95. package/dist/src/services/token/sui/index.js.map +1 -1
  96. package/dist/src/services/token/trx/index.js +3 -0
  97. package/dist/src/services/token/trx/index.js.map +1 -1
  98. package/dist/src/tokens-info/tokens-info.model.d.ts +23 -1
  99. package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
  100. package/dist/src/version.d.ts +1 -1
  101. package/dist/src/version.js +1 -1
  102. package/dist/src/version.js.map +1 -1
  103. package/package.json +1 -1
@@ -0,0 +1,169 @@
1
+ import { NearIntentsSwapType } from "../../client/core-api/core-api.model";
2
+ import { TokenWithChainDetails } from "../../tokens-info";
3
+ import { RawTransaction } from "../models";
4
+ /**
5
+ * Params of a NEAR Intents quote, see `nearIntents.getQuote`
6
+ */
7
+ export interface NearIntentsQuoteParams {
8
+ /**
9
+ * The float amount:
10
+ * the amount to send (in source token units) for `EXACT_INPUT`,
11
+ * the amount to receive (in destination token units) for `EXACT_OUTPUT`.
12
+ */
13
+ amount: string;
14
+ /**
15
+ * {@link TokenWithChainDetails |The token info object} on the source chain.
16
+ */
17
+ sourceToken: TokenWithChainDetails;
18
+ /**
19
+ * {@link TokenWithChainDetails |The token info object} on the destination chain.
20
+ */
21
+ destinationToken: TokenWithChainDetails;
22
+ /**
23
+ * Optional. `EXACT_INPUT` by default.
24
+ */
25
+ swapType?: NearIntentsSwapType;
26
+ }
27
+ /**
28
+ * A NEAR Intents quote. Amounts are float strings.
29
+ */
30
+ export interface NearIntentsQuote {
31
+ /**
32
+ * The float amount to send, in source token units
33
+ */
34
+ amountIn: string;
35
+ /**
36
+ * The expected float amount to receive, in destination token units
37
+ */
38
+ amountOut: string;
39
+ /**
40
+ * The minimum float amount to receive after slippage, in destination token units
41
+ */
42
+ minAmountOut: string;
43
+ /**
44
+ * Estimated transfer time, seconds
45
+ */
46
+ timeEstimate: number;
47
+ /**
48
+ * True when the server computed the amounts from its per-route model of recent NEAR Intents quotes
49
+ * instead of requesting a live quote for this exact amount (keeps repeated quotes fast, e.g. while
50
+ * the user types). An estimated quote is fine for display, but the real amounts may differ slightly.
51
+ * `nearIntents.createDeposit` and `buildSendTransaction` always get a live quote, so the amounts
52
+ * they return are the binding ones.
53
+ */
54
+ estimated: boolean;
55
+ /**
56
+ * USD value of {@link amountIn}; absent on an estimated quote for a token without a known price
57
+ */
58
+ amountInUsd?: string;
59
+ /**
60
+ * USD value of {@link amountOut}; absent on an estimated quote for a token without a known price
61
+ */
62
+ amountOutUsd?: string;
63
+ }
64
+ /**
65
+ * Params of a NEAR Intents deposit, see `nearIntents.createDeposit`
66
+ */
67
+ export interface NearIntentsCreateDepositParams extends NearIntentsQuoteParams {
68
+ /**
69
+ * The account address the transfer is sent from; refunds go back to it.
70
+ */
71
+ fromAccountAddress: string;
72
+ /**
73
+ * The account address on the destination chain to receive the tokens.
74
+ */
75
+ toAccountAddress: string;
76
+ }
77
+ /**
78
+ * A NEAR Intents deposit: the one-shot address the source tokens must be sent to before {@link deadline}.
79
+ * Amounts are float strings.
80
+ */
81
+ export interface NearIntentsDeposit {
82
+ /**
83
+ * The address to send {@link amountIn} of the source token to
84
+ */
85
+ depositAddress: string;
86
+ /**
87
+ * The memo the deposit transfer must carry. Optional, defined for chains that need it (e.g. Stellar)
88
+ */
89
+ depositMemo?: string;
90
+ /**
91
+ * The float amount to send, in source token units
92
+ */
93
+ amountIn: string;
94
+ /**
95
+ * The expected float amount to receive, in destination token units
96
+ */
97
+ amountOut: string;
98
+ /**
99
+ * The minimum float amount to receive after slippage, in destination token units
100
+ */
101
+ minAmountOut: string;
102
+ /**
103
+ * The deposit must be sent before this time; funds arriving later may be lost
104
+ */
105
+ deadline: Date;
106
+ /**
107
+ * The time after which the deposit address becomes inactive. Optional
108
+ */
109
+ timeWhenInactive?: Date;
110
+ /**
111
+ * Estimated transfer time, seconds
112
+ */
113
+ timeEstimate: number;
114
+ }
115
+ /**
116
+ * Params of `nearIntents.submitDeposit`
117
+ */
118
+ export interface NearIntentsSubmitDepositParams {
119
+ depositAddress: string;
120
+ depositMemo?: string;
121
+ /**
122
+ * The hash of the deposit transaction on the source chain
123
+ */
124
+ txId: string;
125
+ }
126
+ /**
127
+ * Params of `nearIntents.buildSendTransaction`
128
+ */
129
+ export interface NearIntentsSendParams {
130
+ /**
131
+ * The float amount of tokens to send
132
+ */
133
+ amount: string;
134
+ /**
135
+ * The account address to transfer tokens from; refunds go back to it.
136
+ */
137
+ fromAccountAddress: string;
138
+ /**
139
+ * The account address on the destination chain to receive the tokens.
140
+ */
141
+ toAccountAddress: string;
142
+ /**
143
+ * {@link TokenWithChainDetails |The token info object} on the source chain.
144
+ */
145
+ sourceToken: TokenWithChainDetails;
146
+ /**
147
+ * {@link TokenWithChainDetails |The token info object} on the destination chain.
148
+ */
149
+ destinationToken: TokenWithChainDetails;
150
+ /**
151
+ * A deposit created with `nearIntents.createDeposit`. Optional.
152
+ * If not defined, a new deposit is created for {@link amount} (`EXACT_INPUT`).
153
+ * When defined, its `amountIn` must equal {@link amount}.
154
+ */
155
+ nearIntentsDeposit?: NearIntentsDeposit;
156
+ }
157
+ /**
158
+ * Result of `nearIntents.buildSendTransaction`
159
+ */
160
+ export interface NearIntentsSendTransaction {
161
+ /**
162
+ * The transfer of the source tokens to the deposit address, to be signed and sent before `deposit.deadline`
163
+ */
164
+ rawTransaction: RawTransaction;
165
+ /**
166
+ * The deposit the transaction pays into
167
+ */
168
+ deposit: NearIntentsDeposit;
169
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/services/near-intents/models.ts"],"names":[],"mappings":"","sourcesContent":["import { NearIntentsSwapType } from \"../../client/core-api/core-api.model\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { RawTransaction } from \"../models\";\n\n/**\n * Params of a NEAR Intents quote, see `nearIntents.getQuote`\n */\nexport interface NearIntentsQuoteParams {\n /**\n * The float amount:\n * the amount to send (in source token units) for `EXACT_INPUT`,\n * the amount to receive (in destination token units) for `EXACT_OUTPUT`.\n */\n amount: string;\n /**\n * {@link TokenWithChainDetails |The token info object} on the source chain.\n */\n sourceToken: TokenWithChainDetails;\n /**\n * {@link TokenWithChainDetails |The token info object} on the destination chain.\n */\n destinationToken: TokenWithChainDetails;\n /**\n * Optional. `EXACT_INPUT` by default.\n */\n swapType?: NearIntentsSwapType;\n}\n\n/**\n * A NEAR Intents quote. Amounts are float strings.\n */\nexport interface NearIntentsQuote {\n /**\n * The float amount to send, in source token units\n */\n amountIn: string;\n /**\n * The expected float amount to receive, in destination token units\n */\n amountOut: string;\n /**\n * The minimum float amount to receive after slippage, in destination token units\n */\n minAmountOut: string;\n /**\n * Estimated transfer time, seconds\n */\n timeEstimate: number;\n /**\n * True when the server computed the amounts from its per-route model of recent NEAR Intents quotes\n * instead of requesting a live quote for this exact amount (keeps repeated quotes fast, e.g. while\n * the user types). An estimated quote is fine for display, but the real amounts may differ slightly.\n * `nearIntents.createDeposit` and `buildSendTransaction` always get a live quote, so the amounts\n * they return are the binding ones.\n */\n estimated: boolean;\n /**\n * USD value of {@link amountIn}; absent on an estimated quote for a token without a known price\n */\n amountInUsd?: string;\n /**\n * USD value of {@link amountOut}; absent on an estimated quote for a token without a known price\n */\n amountOutUsd?: string;\n}\n\n/**\n * Params of a NEAR Intents deposit, see `nearIntents.createDeposit`\n */\nexport interface NearIntentsCreateDepositParams extends NearIntentsQuoteParams {\n /**\n * The account address the transfer is sent from; refunds go back to it.\n */\n fromAccountAddress: string;\n /**\n * The account address on the destination chain to receive the tokens.\n */\n toAccountAddress: string;\n}\n\n/**\n * A NEAR Intents deposit: the one-shot address the source tokens must be sent to before {@link deadline}.\n * Amounts are float strings.\n */\nexport interface NearIntentsDeposit {\n /**\n * The address to send {@link amountIn} of the source token to\n */\n depositAddress: string;\n /**\n * The memo the deposit transfer must carry. Optional, defined for chains that need it (e.g. Stellar)\n */\n depositMemo?: string;\n /**\n * The float amount to send, in source token units\n */\n amountIn: string;\n /**\n * The expected float amount to receive, in destination token units\n */\n amountOut: string;\n /**\n * The minimum float amount to receive after slippage, in destination token units\n */\n minAmountOut: string;\n /**\n * The deposit must be sent before this time; funds arriving later may be lost\n */\n deadline: Date;\n /**\n * The time after which the deposit address becomes inactive. Optional\n */\n timeWhenInactive?: Date;\n /**\n * Estimated transfer time, seconds\n */\n timeEstimate: number;\n}\n\n/**\n * Params of `nearIntents.submitDeposit`\n */\nexport interface NearIntentsSubmitDepositParams {\n depositAddress: string;\n depositMemo?: string;\n /**\n * The hash of the deposit transaction on the source chain\n */\n txId: string;\n}\n\n/**\n * Params of `nearIntents.buildSendTransaction`\n */\nexport interface NearIntentsSendParams {\n /**\n * The float amount of tokens to send\n */\n amount: string;\n /**\n * The account address to transfer tokens from; refunds go back to it.\n */\n fromAccountAddress: string;\n /**\n * The account address on the destination chain to receive the tokens.\n */\n toAccountAddress: string;\n /**\n * {@link TokenWithChainDetails |The token info object} on the source chain.\n */\n sourceToken: TokenWithChainDetails;\n /**\n * {@link TokenWithChainDetails |The token info object} on the destination chain.\n */\n destinationToken: TokenWithChainDetails;\n /**\n * A deposit created with `nearIntents.createDeposit`. Optional.\n * If not defined, a new deposit is created for {@link amount} (`EXACT_INPUT`).\n * When defined, its `amountIn` must equal {@link amount}.\n */\n nearIntentsDeposit?: NearIntentsDeposit;\n}\n\n/**\n * Result of `nearIntents.buildSendTransaction`\n */\nexport interface NearIntentsSendTransaction {\n /**\n * The transfer of the source tokens to the deposit address, to be signed and sent before `deposit.deadline`\n */\n rawTransaction: RawTransaction;\n /**\n * The deposit the transaction pays into\n */\n deposit: NearIntentsDeposit;\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import { SdkError } from "../../exceptions";
2
+ import { TokenWithChainDetails } from "../../tokens-info";
3
+ import { SendParams } from "../bridge/models";
4
+ /**
5
+ * Thrown by the chain bridge services that cannot build a NEAR Intents deposit transfer yet.
6
+ * @internal
7
+ */
8
+ export declare function nearIntentsChainNotSupportedError(chainSymbol: string): SdkError;
9
+ /**
10
+ * Thrown by the deprecated `bridge.send` for a NEAR Intents transfer from a chain whose bridge service
11
+ * cannot sign and send a transaction itself.
12
+ * @internal
13
+ */
14
+ export declare function nearIntentsSendNotSupportedError(chainSymbol: string): SdkError;
15
+ /**
16
+ * Thrown when a NEAR Intents transfer reaches a bridge-contract code path.
17
+ * @internal
18
+ */
19
+ export declare function nearIntentsNotABridgeContractError(): SdkError;
20
+ /**
21
+ * Thrown by allowance and approve calls for `Messenger.NEAR_INTENTS`.
22
+ * @internal
23
+ */
24
+ export declare function nearIntentsNoApprovalError(): SdkError;
25
+ /**
26
+ * Throws {@link NearIntentsDoesNotSupportedError} unless both tokens carry `nearIntents`.
27
+ * @internal
28
+ */
29
+ export declare function assertNearIntentsRoute(sourceToken: TokenWithChainDetails, destinationToken: TokenWithChainDetails): void;
30
+ /**
31
+ * NEAR Intents transfers have no relayer fee and no extra gas: rejects a positive `fee` or `extraGas`.
32
+ * @internal
33
+ */
34
+ export declare function assertNearIntentsSendParams(params: SendParams): void;
@@ -0,0 +1,53 @@
1
+ import { Big } from "big.js";
2
+ import { InvalidGasFeePaymentOptionError, NearIntentsDoesNotSupportedError, SdkError } from "../../exceptions";
3
+ /**
4
+ * Thrown by the chain bridge services that cannot build a NEAR Intents deposit transfer yet.
5
+ * @internal
6
+ */
7
+ export function nearIntentsChainNotSupportedError(chainSymbol) {
8
+ return new SdkError(`NEAR Intents transfers from ${chainSymbol} are not supported yet`);
9
+ }
10
+ /**
11
+ * Thrown by the deprecated `bridge.send` for a NEAR Intents transfer from a chain whose bridge service
12
+ * cannot sign and send a transaction itself.
13
+ * @internal
14
+ */
15
+ export function nearIntentsSendNotSupportedError(chainSymbol) {
16
+ return new SdkError(`bridge.send cannot send NEAR Intents transfers from ${chainSymbol}: use bridge.rawTxBuilder.send and sign the transaction`);
17
+ }
18
+ /**
19
+ * Thrown when a NEAR Intents transfer reaches a bridge-contract code path.
20
+ * @internal
21
+ */
22
+ export function nearIntentsNotABridgeContractError() {
23
+ return new SdkError("NEAR Intents transfers do not go through a bridge contract: use rawTxBuilder.send or nearIntents.buildSendTransaction");
24
+ }
25
+ /**
26
+ * Thrown by allowance and approve calls for `Messenger.NEAR_INTENTS`.
27
+ * @internal
28
+ */
29
+ export function nearIntentsNoApprovalError() {
30
+ return new SdkError("NEAR Intents transfers need no approval");
31
+ }
32
+ /**
33
+ * Throws {@link NearIntentsDoesNotSupportedError} unless both tokens carry `nearIntents`.
34
+ * @internal
35
+ */
36
+ export function assertNearIntentsRoute(sourceToken, destinationToken) {
37
+ if (!sourceToken.nearIntents || !destinationToken.nearIntents) {
38
+ throw new NearIntentsDoesNotSupportedError("Such route does not support NEAR Intents protocol");
39
+ }
40
+ }
41
+ /**
42
+ * NEAR Intents transfers have no relayer fee and no extra gas: rejects a positive `fee` or `extraGas`.
43
+ * @internal
44
+ */
45
+ export function assertNearIntentsSendParams(params) {
46
+ if (params.extraGas && Big(params.extraGas).gt(0)) {
47
+ throw new InvalidGasFeePaymentOptionError("NEAR Intents transfers do not support extra gas");
48
+ }
49
+ if (params.fee && Big(params.fee).gt(0)) {
50
+ throw new InvalidGasFeePaymentOptionError("NEAR Intents transfers have no relayer fee: omit 'fee' or pass 0");
51
+ }
52
+ }
53
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/near-intents/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,gCAAgC,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI/G;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAAC,WAAmB;IACnE,OAAO,IAAI,QAAQ,CAAC,+BAA+B,WAAW,wBAAwB,CAAC,CAAC;AAC1F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAAC,WAAmB;IAClE,OAAO,IAAI,QAAQ,CACjB,uDAAuD,WAAW,yDAAyD,CAC5H,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kCAAkC;IAChD,OAAO,IAAI,QAAQ,CACjB,uHAAuH,CACxH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,QAAQ,CAAC,yCAAyC,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAkC,EAAE,gBAAuC;IAChH,IAAI,CAAC,WAAW,CAAC,WAAW,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAC9D,MAAM,IAAI,gCAAgC,CAAC,mDAAmD,CAAC,CAAC;IAClG,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAkB;IAC5D,IAAI,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,+BAA+B,CAAC,iDAAiD,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,+BAA+B,CAAC,kEAAkE,CAAC,CAAC;IAChH,CAAC;AACH,CAAC","sourcesContent":["import { Big } from \"big.js\";\nimport { InvalidGasFeePaymentOptionError, NearIntentsDoesNotSupportedError, SdkError } from \"../../exceptions\";\nimport { TokenWithChainDetails } from \"../../tokens-info\";\nimport { SendParams } from \"../bridge/models\";\n\n/**\n * Thrown by the chain bridge services that cannot build a NEAR Intents deposit transfer yet.\n * @internal\n */\nexport function nearIntentsChainNotSupportedError(chainSymbol: string): SdkError {\n return new SdkError(`NEAR Intents transfers from ${chainSymbol} are not supported yet`);\n}\n\n/**\n * Thrown by the deprecated `bridge.send` for a NEAR Intents transfer from a chain whose bridge service\n * cannot sign and send a transaction itself.\n * @internal\n */\nexport function nearIntentsSendNotSupportedError(chainSymbol: string): SdkError {\n return new SdkError(\n `bridge.send cannot send NEAR Intents transfers from ${chainSymbol}: use bridge.rawTxBuilder.send and sign the transaction`\n );\n}\n\n/**\n * Thrown when a NEAR Intents transfer reaches a bridge-contract code path.\n * @internal\n */\nexport function nearIntentsNotABridgeContractError(): SdkError {\n return new SdkError(\n \"NEAR Intents transfers do not go through a bridge contract: use rawTxBuilder.send or nearIntents.buildSendTransaction\"\n );\n}\n\n/**\n * Thrown by allowance and approve calls for `Messenger.NEAR_INTENTS`.\n * @internal\n */\nexport function nearIntentsNoApprovalError(): SdkError {\n return new SdkError(\"NEAR Intents transfers need no approval\");\n}\n\n/**\n * Throws {@link NearIntentsDoesNotSupportedError} unless both tokens carry `nearIntents`.\n * @internal\n */\nexport function assertNearIntentsRoute(sourceToken: TokenWithChainDetails, destinationToken: TokenWithChainDetails) {\n if (!sourceToken.nearIntents || !destinationToken.nearIntents) {\n throw new NearIntentsDoesNotSupportedError(\"Such route does not support NEAR Intents protocol\");\n }\n}\n\n/**\n * NEAR Intents transfers have no relayer fee and no extra gas: rejects a positive `fee` or `extraGas`.\n * @internal\n */\nexport function assertNearIntentsSendParams(params: SendParams) {\n if (params.extraGas && Big(params.extraGas).gt(0)) {\n throw new InvalidGasFeePaymentOptionError(\"NEAR Intents transfers do not support extra gas\");\n }\n if (params.fee && Big(params.fee).gt(0)) {\n throw new InvalidGasFeePaymentOptionError(\"NEAR Intents transfers have no relayer fee: omit 'fee' or pass 0\");\n }\n}\n"]}
@@ -25,6 +25,9 @@ export class EvmTokenService extends ChainTokenService {
25
25
  return tokenContract.methods.allowance(owner, spender).call();
26
26
  }
27
27
  async getTokenBalance(params) {
28
+ if (params.token.isNative) {
29
+ return (await this.web3.eth.getBalance(params.account)).toString();
30
+ }
28
31
  return await this.getERC20Contract(params.token.tokenAddress).methods.balanceOf(params.account).call();
29
32
  }
30
33
  async getNativeTokenBalance(params) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/evm/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAKrE,OAAO,KAAK,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,WAAW,E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AAO,OAAO,CAAC,OAAO,CAAC;YACrB,IAAI,EAAE,KAAK;YACX,EAAE,EAAE,YAAY;YAChB,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,aAAa,CAAC,SAAS,EAAE;SAChC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,cAA8B,EAAE,WAAmB;QAClF,MAAM,iBAAiB,GAAoB,cAAiC,CAAC;QAC7E,kBAAkB;QAClB,MAAM,UAAU,GAGZ,EAAC,oBAAoB,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAC,CAAC;QAC/D,IAAK,WAA2B,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;YACrD,iBAAiB,CAAC,GAAG,GAAG,iBAAiB,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,iBAAiB,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC;YAC9D,GAAG,iBAAiB;YACpB,GAAG,UAAU;SACd,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC9C,CAAC;IAEO,gBAAgB,CAAC,eAAuB;QAC9C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAA+B,CAAC;IAC9F,CAAC;CACF","sourcesContent":["import BN from \"bn.js\";\nimport { Contract, Transaction as Web3Transaction } from \"web3\";\nimport { ChainSymbol, ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { GetTokenBalanceParams, EssentialWeb3, TransactionResponse } from \"../../../models\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction } from \"../../models\";\nimport ERC20 from \"../../models/abi/ERC20\";\nimport { amountToHex } from \"../../utils\";\nimport { ApproveParamsDto, GetAllowanceParamsDto, ChainTokenService } from \"../models\";\n\nexport const MAX_AMOUNT = \"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\n\nconst USDT_TOKEN_ADDRESS = \"0xdac17f958d2ee523a2206206994597c13d831ec7\";\nconst POLYGON_GAS_LIMIT = 100_000;\n\nexport class EvmTokenService extends ChainTokenService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n const tokenAddress = params.token.tokenAddress;\n const owner = params.owner;\n const spender = params.spender;\n return this.getAllowanceByTokenAddress(tokenAddress, owner, spender);\n }\n\n getAllowanceByTokenAddress(tokenAddress: string, owner: string, spender: string): Promise<string> {\n const tokenContract = this.getERC20Contract(tokenAddress);\n return tokenContract.methods.allowance(owner, spender).call();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n return await this.getERC20Contract(params.token.tokenAddress).methods.balanceOf(params.account).call();\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (await this.web3.eth.getBalance(params.account)).toString();\n }\n\n async approve(params: ApproveParamsDto): Promise<TransactionResponse> {\n if (this.isUsdt(params.tokenAddress)) {\n const allowance = await this.getAllowanceByTokenAddress(params.tokenAddress, params.owner, params.spender);\n if (allowance !== \"0\") {\n const rawTransaction = await this.buildRawTransactionApprove({\n ...params,\n amount: \"0\",\n });\n await this.sendRawTransaction(rawTransaction, params.chainSymbol);\n }\n }\n const rawTransaction = await this.buildRawTransactionApprove(params);\n return await this.sendRawTransaction(rawTransaction, params.chainSymbol);\n }\n\n isUsdt(tokenAddress: string): boolean {\n return tokenAddress.toLowerCase() === USDT_TOKEN_ADDRESS;\n }\n\n buildRawTransactionApprove(params: ApproveParamsDto): Promise<RawTransaction> {\n const { tokenAddress, spender, owner, amount } = params;\n const tokenContract = this.getERC20Contract(tokenAddress);\n\n const approveMethod = tokenContract.methods.approve(\n spender,\n amount == undefined ? MAX_AMOUNT : amountToHex(amount)\n );\n\n return Promise.resolve({\n from: owner,\n to: tokenAddress,\n value: \"0\",\n data: approveMethod.encodeABI(),\n });\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction, chainSymbol: string) {\n const transactionConfig: Web3Transaction = rawTransaction as Web3Transaction;\n // prettier-ignore\n const feeOptions: {\n maxPriorityFeePerGas?: number | string | BN;\n maxFeePerGas?: number | string | BN\n } = {maxPriorityFeePerGas: undefined, maxFeePerGas: undefined};\n if ((chainSymbol as ChainSymbol) === ChainSymbol.POL) {\n transactionConfig.gas = POLYGON_GAS_LIMIT;\n } else {\n transactionConfig.gas = await this.web3.eth.estimateGas(rawTransaction);\n }\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...transactionConfig,\n ...feeOptions,\n });\n return { txId: transactionHash.toString() };\n }\n\n private getERC20Contract(contractAddress: string) {\n return new this.web3.eth.Contract(ERC20.abi, contractAddress) as Contract<typeof ERC20.abi>;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/evm/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAKrE,OAAO,KAAK,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAA2C,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEvF,MAAM,CAAC,MAAM,UAAU,GAAG,oEAAoE,CAAC;AAE/F,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,MAAM,OAAO,eAAgB,SAAQ,iBAAiB;IAI3C;IACA;IAJT,SAAS,GAAkB,SAAS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AE,GAAG;YACV,IAAI,EAAE,aAAa,CAAC,SAAS,EAAE;SAChC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,cAA8B,EAAE,WAAmB;QAClF,MAAM,iBAAiB,GAAoB,cAAiC,CAAC;QAC7E,kBAAkB;QAClB,MAAM,UAAU,GAGZ,EAAC,oBAAoB,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAC,CAAC;QAC/D,IAAK,WAA2B,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;YACrD,iBAAiB,CAAC,GAAG,GAAG,iBAAiB,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,iBAAiB,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC;YAC9D,GAAG,iBAAiB;YACpB,GAAG,UAAU;SACd,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC9C,CAAC;IAEO,gBAAgB,CAAC,eAAuB;QAC9C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAA+B,CAAC;IAC9F,CAAC;CACF","sourcesContent":["import BN from \"bn.js\";\nimport { Contract, Transaction as Web3Transaction } from \"web3\";\nimport { ChainSymbol, ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { GetTokenBalanceParams, EssentialWeb3, TransactionResponse } from \"../../../models\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction } from \"../../models\";\nimport ERC20 from \"../../models/abi/ERC20\";\nimport { amountToHex } from \"../../utils\";\nimport { ApproveParamsDto, GetAllowanceParamsDto, ChainTokenService } from \"../models\";\n\nexport const MAX_AMOUNT = \"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\n\nconst USDT_TOKEN_ADDRESS = \"0xdac17f958d2ee523a2206206994597c13d831ec7\";\nconst POLYGON_GAS_LIMIT = 100_000;\n\nexport class EvmTokenService extends ChainTokenService {\n chainType: ChainType.EVM = ChainType.EVM;\n\n constructor(\n public web3: EssentialWeb3,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n const tokenAddress = params.token.tokenAddress;\n const owner = params.owner;\n const spender = params.spender;\n return this.getAllowanceByTokenAddress(tokenAddress, owner, spender);\n }\n\n getAllowanceByTokenAddress(tokenAddress: string, owner: string, spender: string): Promise<string> {\n const tokenContract = this.getERC20Contract(tokenAddress);\n return tokenContract.methods.allowance(owner, spender).call();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (params.token.isNative) {\n return (await this.web3.eth.getBalance(params.account)).toString();\n }\n return await this.getERC20Contract(params.token.tokenAddress).methods.balanceOf(params.account).call();\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (await this.web3.eth.getBalance(params.account)).toString();\n }\n\n async approve(params: ApproveParamsDto): Promise<TransactionResponse> {\n if (this.isUsdt(params.tokenAddress)) {\n const allowance = await this.getAllowanceByTokenAddress(params.tokenAddress, params.owner, params.spender);\n if (allowance !== \"0\") {\n const rawTransaction = await this.buildRawTransactionApprove({\n ...params,\n amount: \"0\",\n });\n await this.sendRawTransaction(rawTransaction, params.chainSymbol);\n }\n }\n const rawTransaction = await this.buildRawTransactionApprove(params);\n return await this.sendRawTransaction(rawTransaction, params.chainSymbol);\n }\n\n isUsdt(tokenAddress: string): boolean {\n return tokenAddress.toLowerCase() === USDT_TOKEN_ADDRESS;\n }\n\n buildRawTransactionApprove(params: ApproveParamsDto): Promise<RawTransaction> {\n const { tokenAddress, spender, owner, amount } = params;\n const tokenContract = this.getERC20Contract(tokenAddress);\n\n const approveMethod = tokenContract.methods.approve(\n spender,\n amount == undefined ? MAX_AMOUNT : amountToHex(amount)\n );\n\n return Promise.resolve({\n from: owner,\n to: tokenAddress,\n value: \"0\",\n data: approveMethod.encodeABI(),\n });\n }\n\n private async sendRawTransaction(rawTransaction: RawTransaction, chainSymbol: string) {\n const transactionConfig: Web3Transaction = rawTransaction as Web3Transaction;\n // prettier-ignore\n const feeOptions: {\n maxPriorityFeePerGas?: number | string | BN;\n maxFeePerGas?: number | string | BN\n } = {maxPriorityFeePerGas: undefined, maxFeePerGas: undefined};\n if ((chainSymbol as ChainSymbol) === ChainSymbol.POL) {\n transactionConfig.gas = POLYGON_GAS_LIMIT;\n } else {\n transactionConfig.gas = await this.web3.eth.estimateGas(rawTransaction);\n }\n const { transactionHash } = await this.web3.eth.sendTransaction({\n ...transactionConfig,\n ...feeOptions,\n });\n return { txId: transactionHash.toString() };\n }\n\n private getERC20Contract(contractAddress: string) {\n return new this.web3.eth.Contract(ERC20.abi, contractAddress) as Contract<typeof ERC20.abi>;\n }\n}\n"]}
@@ -36,6 +36,9 @@ export class SolanaTokenService extends ChainTokenService {
36
36
  }
37
37
  async getTokenBalance(params) {
38
38
  const { account, token } = params;
39
+ if (token.isNative) {
40
+ return this.getNativeTokenBalance({ account, chainSymbol: token.chainSymbol });
41
+ }
39
42
  try {
40
43
  const associatedAccount = getAssociatedAccount(new PublicKey(account), new PublicKey(token.tokenAddress));
41
44
  const accountData = await getTokenAccountData(associatedAccount, this.buildAnchorProvider(account));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/sol/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,cAAc,EAAY,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,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AI,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAC1G,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;YACpG,OAAO,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;gBAC/C,OAAO,GAAG,CAAC;YACb,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,MAAmC;QAC7D,OAAO,CACL,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACpG,CAAC,QAAQ,EAAE,CAAC;IACf,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { AnchorProvider, Provider } from \"@coral-xyz/anchor\";\nimport { Connection, PublicKey } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { getTokenAccountData } from \"../../utils/sol\";\nimport { getAssociatedAccount } from \"../../utils/sol/accounts\";\nimport { ApproveParamsDto, GetAllowanceParamsDto, GetTokenBalanceParams } from \"../models\";\nimport { ChainTokenService } from \"../models/token\";\n\nexport class SolanaTokenService extends ChainTokenService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n\n constructor(\n public solanaRpcUrl: string,\n public api: AllbridgeCoreClient\n ) {\n super();\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 private buildAnchorProvider(accountAddress: string): Provider {\n const connection = new Connection(this.solanaRpcUrl, \"confirmed\");\n\n const publicKey = new PublicKey(accountAddress);\n\n return new AnchorProvider(\n connection,\n // @ts-expect-error enough wallet for fetch actions\n { publicKey: publicKey },\n {\n preflightCommitment: \"confirmed\",\n commitment: \"confirmed\",\n }\n );\n }\n\n getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n const { account, token } = params;\n try {\n const associatedAccount = getAssociatedAccount(new PublicKey(account), new PublicKey(token.tokenAddress));\n const accountData = await getTokenAccountData(associatedAccount, this.buildAnchorProvider(account));\n return accountData.amount.toString();\n } catch (e) {\n if (e instanceof Error) {\n e.message.startsWith(\"Account does not exist\");\n return \"0\";\n }\n throw e;\n }\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (\n await this.buildAnchorProvider(params.account).connection.getBalance(new PublicKey(params.account))\n ).toString();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/sol/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,cAAc,EAAY,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAA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,CAAC,CAAC,CAAC;YAC1G,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;YACpG,OAAO,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;gBAC/C,OAAO,GAAG,CAAC;YACb,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,MAAmC;QAC7D,OAAO,CACL,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACpG,CAAC,QAAQ,EAAE,CAAC;IACf,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { AnchorProvider, Provider } from \"@coral-xyz/anchor\";\nimport { Connection, PublicKey } from \"@solana/web3.js\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError } from \"../../../exceptions\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { getTokenAccountData } from \"../../utils/sol\";\nimport { getAssociatedAccount } from \"../../utils/sol/accounts\";\nimport { ApproveParamsDto, GetAllowanceParamsDto, GetTokenBalanceParams } from \"../models\";\nimport { ChainTokenService } from \"../models/token\";\n\nexport class SolanaTokenService extends ChainTokenService {\n chainType: ChainType.SOLANA = ChainType.SOLANA;\n\n constructor(\n public solanaRpcUrl: string,\n public api: AllbridgeCoreClient\n ) {\n super();\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 private buildAnchorProvider(accountAddress: string): Provider {\n const connection = new Connection(this.solanaRpcUrl, \"confirmed\");\n\n const publicKey = new PublicKey(accountAddress);\n\n return new AnchorProvider(\n connection,\n // @ts-expect-error enough wallet for fetch actions\n { publicKey: publicKey },\n {\n preflightCommitment: \"confirmed\",\n commitment: \"confirmed\",\n }\n );\n }\n\n getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n const { account, token } = params;\n if (token.isNative) {\n return this.getNativeTokenBalance({ account, chainSymbol: token.chainSymbol });\n }\n try {\n const associatedAccount = getAssociatedAccount(new PublicKey(account), new PublicKey(token.tokenAddress));\n const accountData = await getTokenAccountData(associatedAccount, this.buildAnchorProvider(account));\n return accountData.amount.toString();\n } catch (e) {\n if (e instanceof Error) {\n e.message.startsWith(\"Account does not exist\");\n return \"0\";\n }\n throw e;\n }\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (\n await this.buildAnchorProvider(params.account).connection.getBalance(new PublicKey(params.account))\n ).toString();\n }\n}\n"]}
@@ -20,6 +20,17 @@ export class SrbTokenService extends ChainTokenService {
20
20
  throw new MethodNotSupportedError();
21
21
  }
22
22
  async getTokenBalance(params) {
23
+ if (params.token.isNative) {
24
+ try {
25
+ return await this.getNativeTokenBalance({ account: params.account, chainSymbol: params.token.chainSymbol });
26
+ }
27
+ catch (err) {
28
+ if (err instanceof NotFoundError) {
29
+ return "0";
30
+ }
31
+ throw err;
32
+ }
33
+ }
23
34
  if (!params.token.originTokenAddress) {
24
35
  throw new SdkError("OriginTokenAddress missing");
25
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/sr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I,aAAa,EAAE,OAAO,EAAE,CAAC;YAC3B,OAAO,uBAAuB,CAC5B,aAAa,CAAC,OAAO,EACrB,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CACrF,CAAC,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO;QACL,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAED,0BAA0B;QACxB,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;CACF","sourcesContent":["import { Horizon, NotFoundError } from \"@stellar/stellar-sdk\";\nimport { Chains } from \"../../../chains\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions, ChainType, SdkError } from \"../../../index\";\nimport { GetTokenBalanceParams, MethodNotSupportedError, TransactionResponse } from \"../../../models\";\nimport { convertFloatAmountToInt } from \"../../../utils/calculation\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport { ChainTokenService } from \"../models\";\n\nimport BalanceLineAsset = Horizon.HorizonApi.BalanceLineAsset;\nimport BalanceLineNative = Horizon.HorizonApi.BalanceLineNative;\n\nexport class SrbTokenService extends ChainTokenService {\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 getAllowance(): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (!params.token.originTokenAddress) {\n throw new SdkError(\"OriginTokenAddress missing\");\n }\n const [symbol, srbTokenAddress] = params.token.originTokenAddress.split(\":\");\n\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n let stellarAccount;\n try {\n stellarAccount = await stellar.loadAccount(params.account);\n } catch (err) {\n if (err instanceof NotFoundError) {\n return \"0\";\n }\n throw err;\n }\n const balances = stellarAccount.balances;\n\n const balanceInfo = balances.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 if (balanceInfo?.balance) {\n return convertFloatAmountToInt(\n balanceInfo.balance,\n Chains.getChainDecimalsByType(Chains.getChainProperty(params.token.chainSymbol).chainType)\n ).toFixed();\n }\n return \"0\";\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const stellarAccount = await stellar.loadAccount(params.account);\n const balances = stellarAccount.balances;\n\n const nativeBalance = balances.find((balance): balance is BalanceLineNative => balance.asset_type === \"native\");\n if (nativeBalance?.balance) {\n return convertFloatAmountToInt(\n nativeBalance.balance,\n Chains.getChainDecimalsByType(Chains.getChainProperty(params.chainSymbol).chainType)\n ).toFixed();\n }\n return \"0\";\n }\n\n approve(): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n buildRawTransactionApprove(): Promise<RawTransaction> {\n throw new MethodNotSupportedError();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/srb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAA2B,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAA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AC;QAEzC,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAgC,EAAE,CAAC,OAAO,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;QAChH,IAAI,aAAa,EAAE,OAAO,EAAE,CAAC;YAC3B,OAAO,uBAAuB,CAC5B,aAAa,CAAC,OAAO,EACrB,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CACrF,CAAC,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO;QACL,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAED,0BAA0B;QACxB,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;CACF","sourcesContent":["import { Horizon, NotFoundError } from \"@stellar/stellar-sdk\";\nimport { Chains } from \"../../../chains\";\nimport { ChainSymbol } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { AllbridgeCoreSdkOptions, ChainType, SdkError } from \"../../../index\";\nimport { GetTokenBalanceParams, MethodNotSupportedError, TransactionResponse } from \"../../../models\";\nimport { convertFloatAmountToInt } from \"../../../utils/calculation\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { NodeRpcUrlsConfig } from \"../../index\";\nimport { RawTransaction } from \"../../models\";\nimport { ChainTokenService } from \"../models\";\n\nimport BalanceLineAsset = Horizon.HorizonApi.BalanceLineAsset;\nimport BalanceLineNative = Horizon.HorizonApi.BalanceLineNative;\n\nexport class SrbTokenService extends ChainTokenService {\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 getAllowance(): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (params.token.isNative) {\n try {\n return await this.getNativeTokenBalance({ account: params.account, chainSymbol: params.token.chainSymbol });\n } catch (err) {\n if (err instanceof NotFoundError) {\n return \"0\";\n }\n throw err;\n }\n }\n if (!params.token.originTokenAddress) {\n throw new SdkError(\"OriginTokenAddress missing\");\n }\n const [symbol, srbTokenAddress] = params.token.originTokenAddress.split(\":\");\n\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n let stellarAccount;\n try {\n stellarAccount = await stellar.loadAccount(params.account);\n } catch (err) {\n if (err instanceof NotFoundError) {\n return \"0\";\n }\n throw err;\n }\n const balances = stellarAccount.balances;\n\n const balanceInfo = balances.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 if (balanceInfo?.balance) {\n return convertFloatAmountToInt(\n balanceInfo.balance,\n Chains.getChainDecimalsByType(Chains.getChainProperty(params.token.chainSymbol).chainType)\n ).toFixed();\n }\n return \"0\";\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n const stellar = new Horizon.Server(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.STLR));\n const stellarAccount = await stellar.loadAccount(params.account);\n const balances = stellarAccount.balances;\n\n const nativeBalance = balances.find((balance): balance is BalanceLineNative => balance.asset_type === \"native\");\n if (nativeBalance?.balance) {\n return convertFloatAmountToInt(\n nativeBalance.balance,\n Chains.getChainDecimalsByType(Chains.getChainProperty(params.chainSymbol).chainType)\n ).toFixed();\n }\n return \"0\";\n }\n\n approve(): Promise<TransactionResponse> {\n throw new MethodNotSupportedError();\n }\n\n buildRawTransactionApprove(): Promise<RawTransaction> {\n throw new MethodNotSupportedError();\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
3
+ import { SUI_TYPE_ARG } from "@mysten/sui/utils";
3
4
  import { ChainType } from "../../../chains/chain.enums";
4
5
  import { MethodNotSupportedError, SdkError } from "../../../exceptions";
5
6
  import { fetchAllPagesRecursive } from "../../utils/sui/paginated";
@@ -30,6 +31,10 @@ export class SuiTokenService extends ChainTokenService {
30
31
  throw new MethodNotSupportedError();
31
32
  }
32
33
  async getTokenBalance(params) {
34
+ if (params.token.isNative) {
35
+ const balance = await this.suiClient.getBalance({ owner: params.account, coinType: SUI_TYPE_ARG });
36
+ return balance.totalBalance;
37
+ }
33
38
  if (!params.token.originTokenAddress) {
34
39
  throw new SdkError("SUI token must contain 'originTokenAddress'");
35
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/sui/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAc,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAoB,iBAAiB,EAAgD,MAAM,WAAW,CAAC;AAE9G,MAAM,OAAO,eAAgB,SAAQ,iBAAiB;IAK3C;IACE;IACF;IANT,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IACjC,SAAS,CAAmB;IAEpC,YACS,SAAiB,EACf,MAA+B,EACjC,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,cAAS,GAAT,SAAS,CAAQ;QACf,WAAM,GAAN,MAAM,CAAyB;QACjC,QAAG,GAAH,GAAG,CAAqB;QAG/B,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC;YACpC,GAAG,EAAE,IAAI,C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C;IACrG,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { CoinStruct, SuiJsonRpcClient } from \"@mysten/sui/jsonRpc\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { fetchAllPagesRecursive } from \"../../utils/sui/paginated\";\nimport { ApproveParamsDto, ChainTokenService, GetAllowanceParamsDto, GetTokenBalanceParams } from \"../models\";\n\nexport class SuiTokenService extends ChainTokenService {\n chainType: ChainType.SUI = ChainType.SUI;\n private suiClient: SuiJsonRpcClient;\n\n constructor(\n public suiRpcUrl: string,\n readonly params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.suiClient = new SuiJsonRpcClient({\n url: this.suiRpcUrl,\n network: params.suiIsTestnet ? \"testnet\" : \"mainnet\",\n });\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 getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (!params.token.originTokenAddress) {\n throw new SdkError(\"SUI token must contain 'originTokenAddress'\");\n }\n const balance = await this.suiClient.getBalance({\n owner: params.account,\n coinType: params.token.originTokenAddress,\n });\n return balance.totalBalance;\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n const coinsData: CoinStruct[] = await fetchAllPagesRecursive((cursor: string | null | undefined) =>\n this.suiClient.getCoins({\n owner: params.account,\n cursor,\n })\n );\n if (coinsData.length === 0) {\n return \"0\";\n }\n return coinsData.reduce((total, element) => total + BigInt(element.balance), BigInt(0)).toString();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/sui/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAc,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAoB,iBAAiB,EAAgD,MAAM,WAAW,CAAC;AAE9G,MAAM,OAAO,eAAgB,SAAQ,iBAAiB;IAK3C;IACE;IACF;IANT,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IACjC,SAAS,CAAmB;IAEpC,YACS,SAAiB,EACf,MAA+B,EACjC,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAJD,cAAS,GAAT,SAAS,CAAQ;QACf,WAAM,GAAN,MAAM,CAAyB;QACjC,QAAG,GAAH,GAAG,CAAqB;QAG/B,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC;YACpC,GAAG,EAAE,IAAI,CAAC,SAAS;YACnB,OAAO,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;SACrD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,MAAwB;QAC9B,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAED,0BAA0B,CAAC,MAAwB;QACjD,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAED,YAAY,CAAC,MAA6B;QACxC,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC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ARG } from \"@mysten/sui/utils\";\nimport { ChainType } from \"../../../chains/chain.enums\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { MethodNotSupportedError, SdkError } from \"../../../exceptions\";\nimport { AllbridgeCoreSdkOptions } from \"../../../index\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, TransactionResponse } from \"../../models\";\nimport { fetchAllPagesRecursive } from \"../../utils/sui/paginated\";\nimport { ApproveParamsDto, ChainTokenService, GetAllowanceParamsDto, GetTokenBalanceParams } from \"../models\";\n\nexport class SuiTokenService extends ChainTokenService {\n chainType: ChainType.SUI = ChainType.SUI;\n private suiClient: SuiJsonRpcClient;\n\n constructor(\n public suiRpcUrl: string,\n readonly params: AllbridgeCoreSdkOptions,\n public api: AllbridgeCoreClient\n ) {\n super();\n this.suiClient = new SuiJsonRpcClient({\n url: this.suiRpcUrl,\n network: params.suiIsTestnet ? \"testnet\" : \"mainnet\",\n });\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 getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n throw new MethodNotSupportedError();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (params.token.isNative) {\n const balance = await this.suiClient.getBalance({ owner: params.account, coinType: SUI_TYPE_ARG });\n return balance.totalBalance;\n }\n if (!params.token.originTokenAddress) {\n throw new SdkError(\"SUI token must contain 'originTokenAddress'\");\n }\n const balance = await this.suiClient.getBalance({\n owner: params.account,\n coinType: params.token.originTokenAddress,\n });\n return balance.totalBalance;\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n const coinsData: CoinStruct[] = await fetchAllPagesRecursive((cursor: string | null | undefined) =>\n this.suiClient.getCoins({\n owner: params.account,\n cursor,\n })\n );\n if (coinsData.length === 0) {\n return \"0\";\n }\n return coinsData.reduce((total, element) => total + BigInt(element.balance), BigInt(0)).toString();\n }\n}\n"]}
@@ -21,6 +21,9 @@ export class TronTokenService extends ChainTokenService {
21
21
  return allowance.toString();
22
22
  }
23
23
  async getTokenBalance(params) {
24
+ if (params.token.isNative) {
25
+ return this.getNativeTokenBalance({ account: params.account, chainSymbol: params.token.chainSymbol });
26
+ }
24
27
  const contract = await this.getContract(params.token.tokenAddress);
25
28
  const balance = await contract.balanceOf(params.account).call();
26
29
  return balance.toString();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/services/token/trx/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAA8C,MAAM,iBAAiB,CAAC;AAGxF,OAAO,KAAK,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG,oEAAoE,CAAC;AAE/F,MAAM,OAAO,gBAAiB,SAAQ,iBAAiB;IAI5C;IACA;IAJT,SAAS,GAAkB,SAAS,CAAC,GAAG,CAAC;IAEzC,YACS,OAAgB,EAChB,GAAwB;QAE/B,KAAK,EAAE,CAAC;QAHD,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAqB;IAGjC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA6B;QAC9C,MAAM,EACJ,KAAK,EAAE,EAAE,YAAY,EAAE,EACvB,KAAK,GACN,GAAG,MAAM,CAAC;QACX,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,OA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CAAC;QAClB,MAAM,eAAe,GAAG,0BAA0B,CAAC;QACnD,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1F,CAAC;IAEO,WAAW,CAAC,eAAuB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,eAAuB,EACvB,eAAuB,EACvB,UAA0C,EAC1C,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,UAAU,EACV,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,QAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { ChainType, GetTokenBalanceParams, TransactionResponse } from \"../../../models\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport ERC20 from \"../../models/abi/ERC20\";\nimport { amountToHex } from \"../../utils\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { ApproveParamsDto, GetAllowanceParamsDto } from \"../models\";\nimport { ChainTokenService } from \"../models/token\";\n\nexport const MAX_AMOUNT = \"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\n\nexport class TronTokenService extends ChainTokenService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n const {\n token: { tokenAddress },\n owner,\n } = params;\n const tokenContract = await this.getContract(tokenAddress);\n const allowance = await tokenContract.methods.allowance(owner, params.spender).call();\n return allowance.toString();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n const contract = await this.getContract(params.token.tokenAddress);\n const balance = await contract.balanceOf(params.account).call();\n return balance.toString();\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (await this.tronWeb.trx.getBalance(params.account)).toString();\n }\n\n async approve(params: ApproveParamsDto): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionApprove(params);\n return await sendRawTransaction(this.tronWeb, rawTransaction);\n }\n\n async buildRawTransactionApprove(params: ApproveParamsDto): Promise<RawTransaction> {\n const { tokenAddress, spender, owner, amount } = params;\n const amountHex = amount == undefined ? MAX_AMOUNT : amountToHex(amount);\n\n const parameter = [\n { type: \"address\", value: spender },\n { type: \"uint256\", value: amountHex },\n ];\n const value = \"0\";\n const methodSignature = \"approve(address,uint256)\";\n return this.buildRawTransaction(tokenAddress, methodSignature, parameter, value, owner);\n }\n\n private getContract(contractAddress: string): any {\n return this.tronWeb.contract(ERC20.abi, contractAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
1
+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AAK,CAAC,CAAC;IAC1F,CAAC;IAEO,WAAW,CAAC,eAAuB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAC/B,eAAuB,EACvB,eAAuB,EACvB,UAA0C,EAC1C,KAAa,EACb,WAAmB;QAEnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAClF,eAAe,EACf,eAAe,EACf;YACE,SAAS,EAAE,CAAC,KAAK;SAClB,EACD,UAAU,EACV,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,QAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { TronWeb } from \"tronweb\";\nimport { AllbridgeCoreClient } from \"../../../client/core-api/core-client-base\";\nimport { SdkError } from \"../../../exceptions\";\nimport { ChainType, GetTokenBalanceParams, TransactionResponse } from \"../../../models\";\nimport { GetNativeTokenBalanceParams } from \"../../bridge/models\";\nimport { RawTransaction, SmartContractMethodParameter } from \"../../models\";\nimport ERC20 from \"../../models/abi/ERC20\";\nimport { amountToHex } from \"../../utils\";\nimport { sendRawTransaction } from \"../../utils/trx\";\nimport { ApproveParamsDto, GetAllowanceParamsDto } from \"../models\";\nimport { ChainTokenService } from \"../models/token\";\n\nexport const MAX_AMOUNT = \"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\n\nexport class TronTokenService extends ChainTokenService {\n chainType: ChainType.TRX = ChainType.TRX;\n\n constructor(\n public tronWeb: TronWeb,\n public api: AllbridgeCoreClient\n ) {\n super();\n }\n\n async getAllowance(params: GetAllowanceParamsDto): Promise<string> {\n const {\n token: { tokenAddress },\n owner,\n } = params;\n const tokenContract = await this.getContract(tokenAddress);\n const allowance = await tokenContract.methods.allowance(owner, params.spender).call();\n return allowance.toString();\n }\n\n async getTokenBalance(params: GetTokenBalanceParams): Promise<string> {\n if (params.token.isNative) {\n return this.getNativeTokenBalance({ account: params.account, chainSymbol: params.token.chainSymbol });\n }\n const contract = await this.getContract(params.token.tokenAddress);\n const balance = await contract.balanceOf(params.account).call();\n return balance.toString();\n }\n\n async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise<string> {\n return (await this.tronWeb.trx.getBalance(params.account)).toString();\n }\n\n async approve(params: ApproveParamsDto): Promise<TransactionResponse> {\n const rawTransaction = await this.buildRawTransactionApprove(params);\n return await sendRawTransaction(this.tronWeb, rawTransaction);\n }\n\n async buildRawTransactionApprove(params: ApproveParamsDto): Promise<RawTransaction> {\n const { tokenAddress, spender, owner, amount } = params;\n const amountHex = amount == undefined ? MAX_AMOUNT : amountToHex(amount);\n\n const parameter = [\n { type: \"address\", value: spender },\n { type: \"uint256\", value: amountHex },\n ];\n const value = \"0\";\n const methodSignature = \"approve(address,uint256)\";\n return this.buildRawTransaction(tokenAddress, methodSignature, parameter, value, owner);\n }\n\n private getContract(contractAddress: string): any {\n return this.tronWeb.contract(ERC20.abi, contractAddress);\n }\n\n private async buildRawTransaction(\n contractAddress: string,\n methodSignature: string,\n parameters: SmartContractMethodParameter[],\n value: string,\n fromAddress: string\n ): Promise<RawTransaction> {\n const transactionObject = await this.tronWeb.transactionBuilder.triggerSmartContract(\n contractAddress,\n methodSignature,\n {\n callValue: +value,\n },\n parameters,\n fromAddress\n );\n if (!transactionObject?.result?.result) {\n throw new SdkError(\"Unknown error: \" + JSON.stringify(transactionObject, null, 2));\n }\n return transactionObject.transaction;\n }\n}\n"]}
@@ -145,6 +145,19 @@ export interface Token {
145
145
  * Optional. Defined if the token is supported by {@link Messenger.X_RESERVE}
146
146
  */
147
147
  xReserve?: XReserveTokenInfo;
148
+ /**
149
+ * NEAR Intents configuration of the token, see {@link NearIntentsTokenInfo}.
150
+ * Optional. Defined if the token is supported by {@link Messenger.NEAR_INTENTS};
151
+ * a route is supported when it is defined on both source and destination tokens.
152
+ */
153
+ nearIntents?: NearIntentsTokenInfo;
154
+ /**
155
+ * True when the token is the native gas token of the chain (e.g. ETH on Ethereum),
156
+ * listed under a sentinel `tokenAddress`. Native tokens are transferred as a value transfer and need no approval.
157
+ * Currently only served for {@link Messenger.NEAR_INTENTS} routes.
158
+ * Optional. `undefined` means a regular token contract.
159
+ */
160
+ isNative?: boolean;
148
161
  /**
149
162
  * Internal identifier for the same token across different chains.
150
163
  *
@@ -211,6 +224,15 @@ export interface XReserveTokenInfo {
211
224
  */
212
225
  protocolAddress?: string;
213
226
  }
227
+ /**
228
+ * NEAR Intents configuration of a token, see {@link Messenger.NEAR_INTENTS}
229
+ */
230
+ export interface NearIntentsTokenInfo {
231
+ /**
232
+ * NEAR Intents (1Click) asset id, opaque (e.g. `nep141:eth-0xa0b8...eb48.omft.near`)
233
+ */
234
+ assetId: string;
235
+ }
214
236
  export interface SuiAddresses {
215
237
  /** @deprecated Do not use. */
216
238
  bridgeAddress: string;
@@ -253,7 +275,7 @@ export interface TokenWithChainDetails extends Token, Omit<ChainDetails, "name">
253
275
  */
254
276
  chainName: string;
255
277
  }
256
- export type TokenCoreFields = Pick<TokenWithChainDetails, "tokenAddress" | "chainSymbol" | "decimals" | "originTokenAddress">;
278
+ export type TokenCoreFields = Pick<TokenWithChainDetails, "tokenAddress" | "chainSymbol" | "decimals" | "originTokenAddress" | "isNative">;
257
279
  export interface TokenWithChainDetailsWithFlags extends TokenWithChainDetails {
258
280
  flags: {
259
281
  swap: boolean;
@@ -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\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 * @deprecated Do not use.\n */\n bridgeAddress: string;\n /**\n * OFT Bridge contract address (the contract to approve for {@link Messenger.OFT})\n * Optional. Defined if the chain supports OFT\n */\n oftBridgeAddress?: string;\n /**\n * Yield contract address\n * @deprecated Do not use.\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 * @deprecated Do not use.\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 (bridge contract to approve for {@link Messenger.CCTP})</br>\n * Optional. Defined if the token is supported by CCTP\n */\n cctpAddress?: string;\n /**\n * Token fee share for CCTP</br>\n * Optional. Defined if the token is supported by CCTP\n */\n cctpFeeShare?: string;\n /**\n * Token CCTP V2 address (bridge contract to approve for {@link Messenger.CCTP_V2})</br>\n * Optional. Defined if the token is supported by CCTP V2\n */\n cctpV2Address?: string;\n /**\n * Token fee share for CCTP V2</br>\n * Optional. Defined if the token is supported by CCTP V2\n */\n cctpV2FeeShare?: string;\n /**\n * xReserve bridge configuration for token, see {@link XReserveTokenInfo}.\n * Optional. Defined if the token is supported by {@link Messenger.X_RESERVE}\n */\n xReserve?: XReserveTokenInfo;\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 the token is supported by {@link Messenger.OFT}.\n * The bridge contract to approve is {@link ChainDetails.oftBridgeAddress}.\n */\n oftId?: string;\n /**\n * Token fee share\n * @deprecated Do not use.\n */\n feeShare: string;\n /**\n * Token APR\n * @deprecated Do not use.\n */\n apr: string;\n /**\n * Token APR based on last 7 days\n * @deprecated Do not use.\n */\n apr7d: string;\n /**\n * Token APR based on last 30 days\n * @deprecated Do not use.\n */\n apr30d: string;\n /**\n * Token LP rate\n * @deprecated Do not use.\n */\n lpRate: string;\n\n /**\n * @deprecated Do not use.\n */\n yieldId?: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\n/**\n * xReserve route configuration of a token, see {@link Messenger.X_RESERVE}\n */\nexport interface XReserveTokenInfo {\n /**\n * xReserve bridge contract address (the contract to approve)\n */\n bridgeAddress: string;\n /**\n * Constant part of the fee, in the smallest denomination of the token\n */\n feeConst: string;\n /**\n * Share of the transferred amount charged as a fee\n */\n feeShare: string;\n /**\n * xReserve protocol contract address\n */\n protocolAddress?: string;\n}\n\nexport interface SuiAddresses {\n /** @deprecated Do not use. */\n bridgeAddress: string;\n /** @deprecated Do not use. */\n bridgeAddressOrigin?: string;\n /** @deprecated Do not use. */\n bridgeObjectAddress: string;\n\n /** @deprecated Do not use. */\n allbridgeMessengerAddress: string;\n /** @deprecated Do not use. */\n allbridgeMessengerAddressOrigin?: string;\n /** @deprecated Do not use. */\n allbridgeMessengerObjectAddress: string;\n\n gasOracleAddress: string;\n gasOracleAddressOrigin?: string;\n gasOracleObjectAddress: string;\n\n utilsAddress: string;\n\n /** @deprecated Do not use. */\n wormholeMessengerAddress: string;\n /** @deprecated Do not use. */\n wormholeMessengerAddressOrigin?: string;\n /** @deprecated Do not use. */\n wormholeMessengerObjectAddress: string;\n /** @deprecated Do not use. */\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: {\n swap: boolean;\n /** @deprecated Do not use. */\n pool: boolean;\n };\n}\n\n/**\n * General Pool Interface\n * @deprecated Do not use.\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\n/**\n * @deprecated Do not use.\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\n/**\n * @deprecated Do not use.\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 * @deprecated Do not use.\n */\n bridgeAddress: string;\n /**\n * OFT Bridge contract address (the contract to approve for {@link Messenger.OFT})\n * Optional. Defined if the chain supports OFT\n */\n oftBridgeAddress?: string;\n /**\n * Yield contract address\n * @deprecated Do not use.\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 * @deprecated Do not use.\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 (bridge contract to approve for {@link Messenger.CCTP})</br>\n * Optional. Defined if the token is supported by CCTP\n */\n cctpAddress?: string;\n /**\n * Token fee share for CCTP</br>\n * Optional. Defined if the token is supported by CCTP\n */\n cctpFeeShare?: string;\n /**\n * Token CCTP V2 address (bridge contract to approve for {@link Messenger.CCTP_V2})</br>\n * Optional. Defined if the token is supported by CCTP V2\n */\n cctpV2Address?: string;\n /**\n * Token fee share for CCTP V2</br>\n * Optional. Defined if the token is supported by CCTP V2\n */\n cctpV2FeeShare?: string;\n /**\n * xReserve bridge configuration for token, see {@link XReserveTokenInfo}.\n * Optional. Defined if the token is supported by {@link Messenger.X_RESERVE}\n */\n xReserve?: XReserveTokenInfo;\n /**\n * NEAR Intents configuration of the token, see {@link NearIntentsTokenInfo}.\n * Optional. Defined if the token is supported by {@link Messenger.NEAR_INTENTS};\n * a route is supported when it is defined on both source and destination tokens.\n */\n nearIntents?: NearIntentsTokenInfo;\n /**\n * True when the token is the native gas token of the chain (e.g. ETH on Ethereum),\n * listed under a sentinel `tokenAddress`. Native tokens are transferred as a value transfer and need no approval.\n * Currently only served for {@link Messenger.NEAR_INTENTS} routes.\n * Optional. `undefined` means a regular token contract.\n */\n isNative?: boolean;\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 the token is supported by {@link Messenger.OFT}.\n * The bridge contract to approve is {@link ChainDetails.oftBridgeAddress}.\n */\n oftId?: string;\n /**\n * Token fee share\n * @deprecated Do not use.\n */\n feeShare: string;\n /**\n * Token APR\n * @deprecated Do not use.\n */\n apr: string;\n /**\n * Token APR based on last 7 days\n * @deprecated Do not use.\n */\n apr7d: string;\n /**\n * Token APR based on last 30 days\n * @deprecated Do not use.\n */\n apr30d: string;\n /**\n * Token LP rate\n * @deprecated Do not use.\n */\n lpRate: string;\n\n /**\n * @deprecated Do not use.\n */\n yieldId?: number;\n /**\n * Sui addresses\n * Optional. Defined for SUI\n */\n suiAddresses?: SuiAddresses;\n}\n\n/**\n * xReserve route configuration of a token, see {@link Messenger.X_RESERVE}\n */\nexport interface XReserveTokenInfo {\n /**\n * xReserve bridge contract address (the contract to approve)\n */\n bridgeAddress: string;\n /**\n * Constant part of the fee, in the smallest denomination of the token\n */\n feeConst: string;\n /**\n * Share of the transferred amount charged as a fee\n */\n feeShare: string;\n /**\n * xReserve protocol contract address\n */\n protocolAddress?: string;\n}\n\n/**\n * NEAR Intents configuration of a token, see {@link Messenger.NEAR_INTENTS}\n */\nexport interface NearIntentsTokenInfo {\n /**\n * NEAR Intents (1Click) asset id, opaque (e.g. `nep141:eth-0xa0b8...eb48.omft.near`)\n */\n assetId: string;\n}\n\nexport interface SuiAddresses {\n /** @deprecated Do not use. */\n bridgeAddress: string;\n /** @deprecated Do not use. */\n bridgeAddressOrigin?: string;\n /** @deprecated Do not use. */\n bridgeObjectAddress: string;\n\n /** @deprecated Do not use. */\n allbridgeMessengerAddress: string;\n /** @deprecated Do not use. */\n allbridgeMessengerAddressOrigin?: string;\n /** @deprecated Do not use. */\n allbridgeMessengerObjectAddress: string;\n\n gasOracleAddress: string;\n gasOracleAddressOrigin?: string;\n gasOracleObjectAddress: string;\n\n utilsAddress: string;\n\n /** @deprecated Do not use. */\n wormholeMessengerAddress: string;\n /** @deprecated Do not use. */\n wormholeMessengerAddressOrigin?: string;\n /** @deprecated Do not use. */\n wormholeMessengerObjectAddress: string;\n /** @deprecated Do not use. */\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\" | \"isNative\"\n>;\n\nexport interface TokenWithChainDetailsWithFlags extends TokenWithChainDetails {\n flags: {\n swap: boolean;\n /** @deprecated Do not use. */\n pool: boolean;\n };\n}\n\n/**\n * General Pool Interface\n * @deprecated Do not use.\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\n/**\n * @deprecated Do not use.\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\n/**\n * @deprecated Do not use.\n */\nexport type PoolInfoMap = Record<string, PoolInfo>;\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "3.36.0-beta.1";
1
+ export declare const VERSION = "3.36.0-beta.3";
@@ -1,2 +1,2 @@
1
- export const VERSION = "3.36.0-beta.1";
1
+ export const VERSION = "3.36.0-beta.3";
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["export const VERSION = \"3.36.0-beta.1\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["export const VERSION = \"3.36.0-beta.3\";\n"]}