@sodax/sdk 1.1.0-beta → 1.2.1-beta
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/index.cjs +552 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +273 -3
- package/dist/index.d.ts +273 -3
- package/dist/index.mjs +544 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -5763,6 +5763,97 @@ var IntentsAbi = [
|
|
|
5763
5763
|
}
|
|
5764
5764
|
];
|
|
5765
5765
|
|
|
5766
|
+
// src/shared/abis/protocolIntents.abi.ts
|
|
5767
|
+
var ProtocolIntentsAbi = [
|
|
5768
|
+
{
|
|
5769
|
+
type: "function",
|
|
5770
|
+
name: "setAutoSwapPreferences",
|
|
5771
|
+
inputs: [
|
|
5772
|
+
{
|
|
5773
|
+
name: "outputToken",
|
|
5774
|
+
type: "address",
|
|
5775
|
+
internalType: "address"
|
|
5776
|
+
},
|
|
5777
|
+
{
|
|
5778
|
+
name: "dstChain",
|
|
5779
|
+
type: "uint256",
|
|
5780
|
+
internalType: "uint256"
|
|
5781
|
+
},
|
|
5782
|
+
{
|
|
5783
|
+
name: "dstAddress",
|
|
5784
|
+
type: "bytes",
|
|
5785
|
+
internalType: "bytes"
|
|
5786
|
+
}
|
|
5787
|
+
],
|
|
5788
|
+
outputs: [],
|
|
5789
|
+
stateMutability: "nonpayable"
|
|
5790
|
+
},
|
|
5791
|
+
{
|
|
5792
|
+
type: "function",
|
|
5793
|
+
name: "createIntentAutoSwap",
|
|
5794
|
+
inputs: [
|
|
5795
|
+
{
|
|
5796
|
+
name: "user",
|
|
5797
|
+
type: "address",
|
|
5798
|
+
internalType: "address"
|
|
5799
|
+
},
|
|
5800
|
+
{
|
|
5801
|
+
name: "fromToken",
|
|
5802
|
+
type: "address",
|
|
5803
|
+
internalType: "address"
|
|
5804
|
+
},
|
|
5805
|
+
{
|
|
5806
|
+
name: "amount",
|
|
5807
|
+
type: "uint256",
|
|
5808
|
+
internalType: "uint256"
|
|
5809
|
+
},
|
|
5810
|
+
{
|
|
5811
|
+
name: "minOutputAmount",
|
|
5812
|
+
type: "uint256",
|
|
5813
|
+
internalType: "uint256"
|
|
5814
|
+
}
|
|
5815
|
+
],
|
|
5816
|
+
outputs: [],
|
|
5817
|
+
stateMutability: "nonpayable"
|
|
5818
|
+
},
|
|
5819
|
+
{
|
|
5820
|
+
type: "function",
|
|
5821
|
+
name: "getAutoSwapPreferences",
|
|
5822
|
+
inputs: [
|
|
5823
|
+
{
|
|
5824
|
+
name: "user",
|
|
5825
|
+
type: "address",
|
|
5826
|
+
internalType: "address"
|
|
5827
|
+
}
|
|
5828
|
+
],
|
|
5829
|
+
outputs: [
|
|
5830
|
+
{
|
|
5831
|
+
name: "",
|
|
5832
|
+
type: "tuple",
|
|
5833
|
+
internalType: "struct AutoSwapPreferences",
|
|
5834
|
+
components: [
|
|
5835
|
+
{
|
|
5836
|
+
name: "outputToken",
|
|
5837
|
+
type: "address",
|
|
5838
|
+
internalType: "address"
|
|
5839
|
+
},
|
|
5840
|
+
{
|
|
5841
|
+
name: "dstChain",
|
|
5842
|
+
type: "uint256",
|
|
5843
|
+
internalType: "uint256"
|
|
5844
|
+
},
|
|
5845
|
+
{
|
|
5846
|
+
name: "dstAddress",
|
|
5847
|
+
type: "bytes",
|
|
5848
|
+
internalType: "bytes"
|
|
5849
|
+
}
|
|
5850
|
+
]
|
|
5851
|
+
}
|
|
5852
|
+
],
|
|
5853
|
+
stateMutability: "view"
|
|
5854
|
+
}
|
|
5855
|
+
];
|
|
5856
|
+
|
|
5766
5857
|
// src/shared/abis/sonicWalletFactory.abi.ts
|
|
5767
5858
|
var sonicWalletFactoryAbi = [
|
|
5768
5859
|
{ inputs: [{ internalType: "address", name: "target", type: "address" }], name: "AddressEmptyCode", type: "error" },
|
|
@@ -6931,6 +7022,9 @@ var ConfigService = class {
|
|
|
6931
7022
|
getOriginalAssetAddress(chainId, hubAsset) {
|
|
6932
7023
|
return this.hubAssetToOriginalAssetMap.get(chainId)?.get(hubAsset.toLowerCase());
|
|
6933
7024
|
}
|
|
7025
|
+
getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress) {
|
|
7026
|
+
return this.supportedTokensPerChain.get(chainId)?.find((token) => token.address.toLowerCase() === originalAssetAddress.toLowerCase());
|
|
7027
|
+
}
|
|
6934
7028
|
isValidHubAsset(hubAsset) {
|
|
6935
7029
|
return this.supportedHubAssetsSet.has(hubAsset.toLowerCase());
|
|
6936
7030
|
}
|
|
@@ -15088,6 +15182,445 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15088
15182
|
return this.configService.getMoneyMarketReserveAssets();
|
|
15089
15183
|
}
|
|
15090
15184
|
};
|
|
15185
|
+
var PartnerFeeClaimService = class {
|
|
15186
|
+
config;
|
|
15187
|
+
hubProvider;
|
|
15188
|
+
configService;
|
|
15189
|
+
constructor({ config, configService, hubProvider }) {
|
|
15190
|
+
const solverConfig = config ? isConfiguredSolverConfig(config) ? config : getSolverConfig(hubProvider.chainConfig.chain.id) : getSolverConfig(SONIC_MAINNET_CHAIN_ID);
|
|
15191
|
+
this.config = {
|
|
15192
|
+
...solverConfig,
|
|
15193
|
+
relayerApiEndpoint: void 0,
|
|
15194
|
+
protocolIntentsContract: solverConfig.protocolIntentsContract
|
|
15195
|
+
};
|
|
15196
|
+
this.configService = configService;
|
|
15197
|
+
this.hubProvider = hubProvider;
|
|
15198
|
+
}
|
|
15199
|
+
/**
|
|
15200
|
+
* Util methods for dealing with tokens and hub assets
|
|
15201
|
+
*/
|
|
15202
|
+
getAllHubAssets() {
|
|
15203
|
+
return this.configService.getHubAssets();
|
|
15204
|
+
}
|
|
15205
|
+
getOriginalAssetAddress(chainId, hubAsset) {
|
|
15206
|
+
return this.configService.getOriginalAssetAddress(chainId, hubAsset);
|
|
15207
|
+
}
|
|
15208
|
+
getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress) {
|
|
15209
|
+
return this.configService.getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress);
|
|
15210
|
+
}
|
|
15211
|
+
/**
|
|
15212
|
+
* Fetches balances for all hub assets across all chains on Sonic for a given address or provider.
|
|
15213
|
+
*
|
|
15214
|
+
* @param params - Either an EVM address (as a string) or a SonicSpokeProviderType.
|
|
15215
|
+
* If an address, queries balances for that address.
|
|
15216
|
+
* If a SonicSpokeProviderType, uses the connected wallet's address.
|
|
15217
|
+
* @returns A promise resolving to a Result containing a Map from wrapped asset address (on Sonic)
|
|
15218
|
+
* to PartnerFeeClaimAssetBalance, or an Error on failure.
|
|
15219
|
+
*/
|
|
15220
|
+
async fetchAssetsBalances(params) {
|
|
15221
|
+
try {
|
|
15222
|
+
let queryAddress;
|
|
15223
|
+
if ("address" in params) {
|
|
15224
|
+
invariant6(isAddress(params.address), "Address must be a valid EVM address");
|
|
15225
|
+
queryAddress = params.address;
|
|
15226
|
+
} else {
|
|
15227
|
+
invariant6(
|
|
15228
|
+
isSonicSpokeProviderType(params.spokeProvider),
|
|
15229
|
+
"PartnerFeeClaimService only supports Sonic spoke provider"
|
|
15230
|
+
);
|
|
15231
|
+
queryAddress = await params.spokeProvider.walletProvider.getWalletAddress();
|
|
15232
|
+
}
|
|
15233
|
+
const allAssetEntries = [];
|
|
15234
|
+
for (const [chainId, chainAssets] of Object.entries(this.getAllHubAssets())) {
|
|
15235
|
+
for (const [originalTokenAddress, hubAsset] of Object.entries(chainAssets)) {
|
|
15236
|
+
allAssetEntries.push({
|
|
15237
|
+
assetAddress: hubAsset.asset.toLowerCase(),
|
|
15238
|
+
// Use the wrapped asset address on Sonic
|
|
15239
|
+
originalChain: chainId,
|
|
15240
|
+
originalAddress: originalTokenAddress.toLowerCase(),
|
|
15241
|
+
hubAsset: {
|
|
15242
|
+
symbol: hubAsset.symbol,
|
|
15243
|
+
name: hubAsset.name,
|
|
15244
|
+
decimal: hubAsset.decimal
|
|
15245
|
+
}
|
|
15246
|
+
});
|
|
15247
|
+
}
|
|
15248
|
+
}
|
|
15249
|
+
const uniqueAssets = /* @__PURE__ */ new Map();
|
|
15250
|
+
for (const entry of allAssetEntries) {
|
|
15251
|
+
if (!uniqueAssets.has(entry.assetAddress)) {
|
|
15252
|
+
uniqueAssets.set(entry.assetAddress, entry);
|
|
15253
|
+
}
|
|
15254
|
+
}
|
|
15255
|
+
const uniqueAssetEntries = Array.from(uniqueAssets.values());
|
|
15256
|
+
const assetAddresses = uniqueAssetEntries.map((entry) => entry.assetAddress);
|
|
15257
|
+
const balanceResults = await this.hubProvider.publicClient.multicall({
|
|
15258
|
+
contracts: assetAddresses.map((assetAddress) => ({
|
|
15259
|
+
address: assetAddress,
|
|
15260
|
+
abi: erc20Abi$1,
|
|
15261
|
+
functionName: "balanceOf",
|
|
15262
|
+
args: [queryAddress]
|
|
15263
|
+
})),
|
|
15264
|
+
allowFailure: false
|
|
15265
|
+
});
|
|
15266
|
+
const balancesMap = /* @__PURE__ */ new Map();
|
|
15267
|
+
let nonZeroCount = 0;
|
|
15268
|
+
uniqueAssetEntries.forEach((entry, index) => {
|
|
15269
|
+
const balanceResult = balanceResults[index];
|
|
15270
|
+
let balance;
|
|
15271
|
+
if (typeof balanceResult === "bigint") {
|
|
15272
|
+
balance = balanceResult;
|
|
15273
|
+
} else {
|
|
15274
|
+
console.warn(
|
|
15275
|
+
`[PartnerFeeClaimService] Unexpected balance result format for ${entry.hubAsset.symbol} (${entry.assetAddress}):`,
|
|
15276
|
+
balanceResult
|
|
15277
|
+
);
|
|
15278
|
+
balance = 0n;
|
|
15279
|
+
}
|
|
15280
|
+
if (balance > 0n) {
|
|
15281
|
+
nonZeroCount++;
|
|
15282
|
+
balancesMap.set(entry.assetAddress, {
|
|
15283
|
+
symbol: entry.hubAsset.symbol,
|
|
15284
|
+
name: entry.hubAsset.name,
|
|
15285
|
+
address: entry.assetAddress,
|
|
15286
|
+
// Wrapped asset address on Sonic
|
|
15287
|
+
originalChain: entry.originalChain,
|
|
15288
|
+
originalAddress: entry.originalAddress,
|
|
15289
|
+
decimal: entry.hubAsset.decimal,
|
|
15290
|
+
balance
|
|
15291
|
+
});
|
|
15292
|
+
}
|
|
15293
|
+
});
|
|
15294
|
+
return {
|
|
15295
|
+
ok: true,
|
|
15296
|
+
value: balancesMap
|
|
15297
|
+
};
|
|
15298
|
+
} catch (error) {
|
|
15299
|
+
return {
|
|
15300
|
+
ok: false,
|
|
15301
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15302
|
+
};
|
|
15303
|
+
}
|
|
15304
|
+
}
|
|
15305
|
+
/**
|
|
15306
|
+
* Gets the auto swap preferences for a user.
|
|
15307
|
+
*
|
|
15308
|
+
* @param params - Either an EVM address (as a string) or a SonicSpokeProviderType.
|
|
15309
|
+
* If an address, queries preferences for that address.
|
|
15310
|
+
* If a SonicSpokeProviderType, uses the connected wallet's address.
|
|
15311
|
+
* @returns A promise resolving to a Result containing the auto swap preferences, or an Error on failure.
|
|
15312
|
+
* The auto swap preferences include the output token, destination chain, and destination address.
|
|
15313
|
+
*/
|
|
15314
|
+
async getAutoSwapPreferences(params) {
|
|
15315
|
+
try {
|
|
15316
|
+
let queryAddress;
|
|
15317
|
+
if ("address" in params) {
|
|
15318
|
+
invariant6(isAddress(params.address), "Address must be a valid EVM address");
|
|
15319
|
+
queryAddress = params.address;
|
|
15320
|
+
} else {
|
|
15321
|
+
invariant6(
|
|
15322
|
+
isSonicSpokeProviderType(params.spokeProvider),
|
|
15323
|
+
"PartnerFeeClaimService only supports Sonic spoke provider"
|
|
15324
|
+
);
|
|
15325
|
+
queryAddress = await params.spokeProvider.walletProvider.getWalletAddress();
|
|
15326
|
+
}
|
|
15327
|
+
invariant6(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15328
|
+
const autoSwapPreferences = await this.hubProvider.publicClient.readContract({
|
|
15329
|
+
address: this.config.protocolIntentsContract,
|
|
15330
|
+
abi: ProtocolIntentsAbi,
|
|
15331
|
+
functionName: "getAutoSwapPreferences",
|
|
15332
|
+
args: [queryAddress]
|
|
15333
|
+
});
|
|
15334
|
+
const dstChain = autoSwapPreferences.dstChain === 0n ? "not configured" : this.configService.getSpokeChainIdFromIntentRelayChainId(
|
|
15335
|
+
autoSwapPreferences.dstChain
|
|
15336
|
+
);
|
|
15337
|
+
return {
|
|
15338
|
+
ok: true,
|
|
15339
|
+
value: {
|
|
15340
|
+
outputToken: autoSwapPreferences.outputToken,
|
|
15341
|
+
dstChain,
|
|
15342
|
+
dstAddress: autoSwapPreferences.dstAddress
|
|
15343
|
+
}
|
|
15344
|
+
};
|
|
15345
|
+
} catch (error) {
|
|
15346
|
+
return {
|
|
15347
|
+
ok: false,
|
|
15348
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15349
|
+
};
|
|
15350
|
+
}
|
|
15351
|
+
}
|
|
15352
|
+
/**
|
|
15353
|
+
* Sets the auto swap preferences for a user.
|
|
15354
|
+
*
|
|
15355
|
+
* @template S - Type of the Sonic spoke provider
|
|
15356
|
+
* @template R - Whether to return raw transaction data (default: false)
|
|
15357
|
+
* @param {Object} args - The argument object
|
|
15358
|
+
* @param {SetSwapPreferenceParams} args.params - The swap preference parameters
|
|
15359
|
+
* @param {S} args.spokeProvider - The Sonic spoke provider
|
|
15360
|
+
* @param {R} [args.raw] - If true, the raw transaction data will be returned
|
|
15361
|
+
* @returns {Promise<Result<TxReturnType<S, R>, SetSwapPreferenceError>>}
|
|
15362
|
+
* - If `raw` is true or the provider is a raw provider, returns the raw transaction object.
|
|
15363
|
+
* - Otherwise, returns the transaction hash of the submitted transaction.
|
|
15364
|
+
* - If failed, returns an error object with code 'SET_SWAP_PREFERENCE_FAILED'.
|
|
15365
|
+
*/
|
|
15366
|
+
async setSwapPreference({
|
|
15367
|
+
params,
|
|
15368
|
+
spokeProvider,
|
|
15369
|
+
raw
|
|
15370
|
+
}) {
|
|
15371
|
+
try {
|
|
15372
|
+
invariant6(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15373
|
+
invariant6(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15374
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15375
|
+
const rawTx = {
|
|
15376
|
+
from: walletAddress,
|
|
15377
|
+
to: this.config.protocolIntentsContract,
|
|
15378
|
+
value: 0n,
|
|
15379
|
+
data: encodeFunctionData({
|
|
15380
|
+
abi: ProtocolIntentsAbi,
|
|
15381
|
+
functionName: "setAutoSwapPreferences",
|
|
15382
|
+
args: [
|
|
15383
|
+
params.outputToken,
|
|
15384
|
+
BigInt(getIntentRelayChainId(params.dstChain)),
|
|
15385
|
+
encodeAddress(params.dstChain, params.dstAddress)
|
|
15386
|
+
]
|
|
15387
|
+
})
|
|
15388
|
+
};
|
|
15389
|
+
if (raw || isSonicRawSpokeProvider(spokeProvider)) {
|
|
15390
|
+
return {
|
|
15391
|
+
ok: true,
|
|
15392
|
+
value: rawTx
|
|
15393
|
+
};
|
|
15394
|
+
}
|
|
15395
|
+
const txHash = await spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
15396
|
+
return {
|
|
15397
|
+
ok: true,
|
|
15398
|
+
value: txHash
|
|
15399
|
+
};
|
|
15400
|
+
} catch (error) {
|
|
15401
|
+
return {
|
|
15402
|
+
ok: false,
|
|
15403
|
+
error: {
|
|
15404
|
+
code: "SET_SWAP_PREFERENCE_FAILED",
|
|
15405
|
+
data: {
|
|
15406
|
+
payload: params,
|
|
15407
|
+
error
|
|
15408
|
+
}
|
|
15409
|
+
}
|
|
15410
|
+
};
|
|
15411
|
+
}
|
|
15412
|
+
}
|
|
15413
|
+
/**
|
|
15414
|
+
* Checks if a token is already approved to the protocol intents contract for a given address or the connected wallet.
|
|
15415
|
+
*
|
|
15416
|
+
* @param params - Object containing:
|
|
15417
|
+
* - token: The ERC20 token address to check.
|
|
15418
|
+
* - spokeProvider: The SonicSpokeProviderType instance.
|
|
15419
|
+
* - address (optional): The address to check allowance for. If not provided, uses the currently connected wallet.
|
|
15420
|
+
* @returns Promise resolving to a Result. Value is true if token is approved (has max or sufficient allowance), false otherwise. Returns an error if the check fails.
|
|
15421
|
+
*/
|
|
15422
|
+
async isTokenApproved({ token, spokeProvider }) {
|
|
15423
|
+
try {
|
|
15424
|
+
invariant6(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15425
|
+
invariant6(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15426
|
+
const queryAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15427
|
+
if (token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
15428
|
+
return {
|
|
15429
|
+
ok: true,
|
|
15430
|
+
value: true
|
|
15431
|
+
};
|
|
15432
|
+
}
|
|
15433
|
+
const allowedAmount = await this.hubProvider.publicClient.readContract({
|
|
15434
|
+
address: token,
|
|
15435
|
+
abi: erc20Abi$1,
|
|
15436
|
+
functionName: "allowance",
|
|
15437
|
+
args: [queryAddress, this.config.protocolIntentsContract]
|
|
15438
|
+
});
|
|
15439
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
15440
|
+
const isMaxApproved = allowedAmount >= maxUint256 - 1000n;
|
|
15441
|
+
return {
|
|
15442
|
+
ok: true,
|
|
15443
|
+
value: isMaxApproved
|
|
15444
|
+
};
|
|
15445
|
+
} catch (error) {
|
|
15446
|
+
return {
|
|
15447
|
+
ok: false,
|
|
15448
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15449
|
+
};
|
|
15450
|
+
}
|
|
15451
|
+
}
|
|
15452
|
+
/**
|
|
15453
|
+
* Approves a token to the protocol intents contract with maximum allowance
|
|
15454
|
+
* @param {Address} token - The token address to approve
|
|
15455
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15456
|
+
* @param {boolean} raw - Whether to return raw transaction data
|
|
15457
|
+
* @returns {Promise<Result<TxReturnType<SonicSpokeProviderType, R>, Error>>} Transaction hash or raw transaction
|
|
15458
|
+
*/
|
|
15459
|
+
async approveToken({
|
|
15460
|
+
token,
|
|
15461
|
+
spokeProvider,
|
|
15462
|
+
raw
|
|
15463
|
+
}) {
|
|
15464
|
+
try {
|
|
15465
|
+
invariant6(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15466
|
+
invariant6(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15467
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
15468
|
+
const result = await Erc20Service.approve(
|
|
15469
|
+
token,
|
|
15470
|
+
maxUint256,
|
|
15471
|
+
this.config.protocolIntentsContract,
|
|
15472
|
+
spokeProvider,
|
|
15473
|
+
raw
|
|
15474
|
+
);
|
|
15475
|
+
return {
|
|
15476
|
+
ok: true,
|
|
15477
|
+
value: result
|
|
15478
|
+
};
|
|
15479
|
+
} catch (error) {
|
|
15480
|
+
return {
|
|
15481
|
+
ok: false,
|
|
15482
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15483
|
+
};
|
|
15484
|
+
}
|
|
15485
|
+
}
|
|
15486
|
+
/**
|
|
15487
|
+
* Creates an intent to auto swap tokens using the protocol intents contract
|
|
15488
|
+
* @param {PartnerFeeClaimSwapParams} params - The swap parameters
|
|
15489
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15490
|
+
* @param {boolean} raw - Whether to return raw transaction data
|
|
15491
|
+
* @returns {Promise<TxReturnType<SonicSpokeProviderType, R>>} Transaction hash or raw transaction
|
|
15492
|
+
*/
|
|
15493
|
+
async createIntentAutoSwap({
|
|
15494
|
+
params,
|
|
15495
|
+
spokeProvider,
|
|
15496
|
+
raw
|
|
15497
|
+
}) {
|
|
15498
|
+
try {
|
|
15499
|
+
invariant6(isSonicSpokeProvider(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15500
|
+
invariant6(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15501
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15502
|
+
const minOutputAmount = 0n;
|
|
15503
|
+
const rawTx = {
|
|
15504
|
+
from: walletAddress,
|
|
15505
|
+
to: this.config.protocolIntentsContract,
|
|
15506
|
+
value: 0n,
|
|
15507
|
+
data: encodeFunctionData({
|
|
15508
|
+
abi: ProtocolIntentsAbi,
|
|
15509
|
+
functionName: "createIntentAutoSwap",
|
|
15510
|
+
args: [walletAddress, params.fromToken, params.amount, minOutputAmount]
|
|
15511
|
+
})
|
|
15512
|
+
};
|
|
15513
|
+
if (raw || isSonicRawSpokeProvider(spokeProvider)) {
|
|
15514
|
+
return {
|
|
15515
|
+
ok: true,
|
|
15516
|
+
value: rawTx
|
|
15517
|
+
};
|
|
15518
|
+
}
|
|
15519
|
+
const txHash = await spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
15520
|
+
return {
|
|
15521
|
+
ok: true,
|
|
15522
|
+
value: txHash
|
|
15523
|
+
};
|
|
15524
|
+
} catch (error) {
|
|
15525
|
+
return {
|
|
15526
|
+
ok: false,
|
|
15527
|
+
error: {
|
|
15528
|
+
code: "CREATE_INTENT_AUTO_SWAP_FAILED",
|
|
15529
|
+
data: {
|
|
15530
|
+
payload: params,
|
|
15531
|
+
error
|
|
15532
|
+
}
|
|
15533
|
+
}
|
|
15534
|
+
};
|
|
15535
|
+
}
|
|
15536
|
+
}
|
|
15537
|
+
/**
|
|
15538
|
+
* Creates an intent auto swap and handles post-execution
|
|
15539
|
+
* @param {PartnerFeeClaimSwapParams} params - The swap parameters
|
|
15540
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15541
|
+
* @returns {Promise<Result<SolverExecutionResponse, IntentError<IntentErrorCode>>>} Solver execution response
|
|
15542
|
+
*/
|
|
15543
|
+
async swap({
|
|
15544
|
+
params,
|
|
15545
|
+
spokeProvider
|
|
15546
|
+
}) {
|
|
15547
|
+
try {
|
|
15548
|
+
const txHash = await this.createIntentAutoSwap({ params, spokeProvider, raw: false });
|
|
15549
|
+
if (!txHash.ok) {
|
|
15550
|
+
return txHash;
|
|
15551
|
+
}
|
|
15552
|
+
let intentTxHash;
|
|
15553
|
+
try {
|
|
15554
|
+
const receipt = await spokeProvider.publicClient.waitForTransactionReceipt({ hash: txHash.value });
|
|
15555
|
+
intentTxHash = receipt.transactionHash;
|
|
15556
|
+
} catch (error) {
|
|
15557
|
+
return {
|
|
15558
|
+
ok: false,
|
|
15559
|
+
error: {
|
|
15560
|
+
code: "WAIT_INTENT_AUTO_SWAP_FAILED",
|
|
15561
|
+
data: {
|
|
15562
|
+
payload: params,
|
|
15563
|
+
error
|
|
15564
|
+
}
|
|
15565
|
+
}
|
|
15566
|
+
};
|
|
15567
|
+
}
|
|
15568
|
+
const solverExecutionResponse = await SolverApiService.postExecution(
|
|
15569
|
+
{
|
|
15570
|
+
intent_tx_hash: intentTxHash
|
|
15571
|
+
},
|
|
15572
|
+
this.config
|
|
15573
|
+
);
|
|
15574
|
+
if (!solverExecutionResponse.ok) {
|
|
15575
|
+
return solverExecutionResponse;
|
|
15576
|
+
}
|
|
15577
|
+
return {
|
|
15578
|
+
ok: true,
|
|
15579
|
+
value: {
|
|
15580
|
+
srcTxHash: txHash.value,
|
|
15581
|
+
solverExecutionResponse: solverExecutionResponse.value,
|
|
15582
|
+
intentTxHash
|
|
15583
|
+
}
|
|
15584
|
+
};
|
|
15585
|
+
} catch (error) {
|
|
15586
|
+
return {
|
|
15587
|
+
ok: false,
|
|
15588
|
+
error: {
|
|
15589
|
+
code: "UNKNOWN",
|
|
15590
|
+
data: { payload: params, error }
|
|
15591
|
+
}
|
|
15592
|
+
};
|
|
15593
|
+
}
|
|
15594
|
+
}
|
|
15595
|
+
};
|
|
15596
|
+
function isSetSwapPreferenceError(error) {
|
|
15597
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "SET_SWAP_PREFERENCE_FAILED";
|
|
15598
|
+
}
|
|
15599
|
+
function isCreateIntentAutoSwapError(error) {
|
|
15600
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "CREATE_INTENT_AUTO_SWAP_FAILED";
|
|
15601
|
+
}
|
|
15602
|
+
function isWaitIntentAutoSwapError(error) {
|
|
15603
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "WAIT_INTENT_AUTO_SWAP_FAILED";
|
|
15604
|
+
}
|
|
15605
|
+
function isSolverErrorResponse(error) {
|
|
15606
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "SOLVER_ERROR";
|
|
15607
|
+
}
|
|
15608
|
+
function isUnknownIntentAutoSwapError(error) {
|
|
15609
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "UNKNOWN";
|
|
15610
|
+
}
|
|
15611
|
+
|
|
15612
|
+
// src/partner/PartnerService.ts
|
|
15613
|
+
var PartnerService = class {
|
|
15614
|
+
feeClaim;
|
|
15615
|
+
// Partner Fee Claim service for partner fee operations
|
|
15616
|
+
constructor(config) {
|
|
15617
|
+
this.feeClaim = new PartnerFeeClaimService({
|
|
15618
|
+
config: config?.feeClaim,
|
|
15619
|
+
configService: config.configService,
|
|
15620
|
+
hubProvider: config.hubProvider
|
|
15621
|
+
});
|
|
15622
|
+
}
|
|
15623
|
+
};
|
|
15091
15624
|
|
|
15092
15625
|
// src/shared/entities/Sodax.ts
|
|
15093
15626
|
var Sodax = class {
|
|
@@ -15104,6 +15637,8 @@ var Sodax = class {
|
|
|
15104
15637
|
// Bridge service enabling cross-chain transfers
|
|
15105
15638
|
staking;
|
|
15106
15639
|
// Staking service enabling SODA staking operations
|
|
15640
|
+
partners;
|
|
15641
|
+
// Partner service enabling partner fee claim and other partner operations
|
|
15107
15642
|
config;
|
|
15108
15643
|
// Config service enabling configuration data fetching from the backend API or fallbacking to default values
|
|
15109
15644
|
hubProvider;
|
|
@@ -15170,6 +15705,11 @@ var Sodax = class {
|
|
|
15170
15705
|
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
15171
15706
|
configService: this.config
|
|
15172
15707
|
});
|
|
15708
|
+
this.partners = config?.partners ? new PartnerService({
|
|
15709
|
+
feeClaim: config.partners.feeClaim,
|
|
15710
|
+
configService: this.config,
|
|
15711
|
+
hubProvider: this.hubProvider
|
|
15712
|
+
}) : new PartnerService({ configService: this.config, hubProvider: this.hubProvider });
|
|
15173
15713
|
}
|
|
15174
15714
|
/**
|
|
15175
15715
|
* Initializes the Sodax instance with dynamic configuration.
|
|
@@ -15773,6 +16313,9 @@ function isInjectiveRawSpokeProvider(value) {
|
|
|
15773
16313
|
function isSonicRawSpokeProvider(value) {
|
|
15774
16314
|
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "EVM" && value.chainConfig.chain.id === SONIC_MAINNET_CHAIN_ID;
|
|
15775
16315
|
}
|
|
16316
|
+
function isAddressString(value) {
|
|
16317
|
+
return typeof value === "string";
|
|
16318
|
+
}
|
|
15776
16319
|
async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
15777
16320
|
do {
|
|
15778
16321
|
try {
|
|
@@ -20086,6 +20629,6 @@ var BalnSwapService = class {
|
|
|
20086
20629
|
}
|
|
20087
20630
|
};
|
|
20088
20631
|
|
|
20089
|
-
export { BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubService, ICON_TX_RESULT_WAIT_MAX_RETRY, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, convertTransactionInstructionToRaw, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hyper, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSonicRawSpokeProvider, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isUnifiedBnUSDMigrateParams, isWaitUntilIntentExecutedFailed, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, sonicWalletFactoryAbi, spokeAssetManagerAbi, stakedSodaAbi, stakingRouterAbi, submitTransaction, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
20632
|
+
export { BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubService, ICON_TX_RESULT_WAIT_MAX_RETRY, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, PartnerFeeClaimService, PartnerService, ProtocolIntentsAbi, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, convertTransactionInstructionToRaw, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hyper, isAddressString, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isCreateIntentAutoSwapError, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSetSwapPreferenceError, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSolverErrorResponse, isSonicRawSpokeProvider, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isUnifiedBnUSDMigrateParams, isUnknownIntentAutoSwapError, isWaitIntentAutoSwapError, isWaitUntilIntentExecutedFailed, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, sonicWalletFactoryAbi, spokeAssetManagerAbi, stakedSodaAbi, stakingRouterAbi, submitTransaction, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
20090
20633
|
//# sourceMappingURL=index.mjs.map
|
|
20091
20634
|
//# sourceMappingURL=index.mjs.map
|