@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.cjs
CHANGED
|
@@ -5791,6 +5791,97 @@ var IntentsAbi = [
|
|
|
5791
5791
|
}
|
|
5792
5792
|
];
|
|
5793
5793
|
|
|
5794
|
+
// src/shared/abis/protocolIntents.abi.ts
|
|
5795
|
+
var ProtocolIntentsAbi = [
|
|
5796
|
+
{
|
|
5797
|
+
type: "function",
|
|
5798
|
+
name: "setAutoSwapPreferences",
|
|
5799
|
+
inputs: [
|
|
5800
|
+
{
|
|
5801
|
+
name: "outputToken",
|
|
5802
|
+
type: "address",
|
|
5803
|
+
internalType: "address"
|
|
5804
|
+
},
|
|
5805
|
+
{
|
|
5806
|
+
name: "dstChain",
|
|
5807
|
+
type: "uint256",
|
|
5808
|
+
internalType: "uint256"
|
|
5809
|
+
},
|
|
5810
|
+
{
|
|
5811
|
+
name: "dstAddress",
|
|
5812
|
+
type: "bytes",
|
|
5813
|
+
internalType: "bytes"
|
|
5814
|
+
}
|
|
5815
|
+
],
|
|
5816
|
+
outputs: [],
|
|
5817
|
+
stateMutability: "nonpayable"
|
|
5818
|
+
},
|
|
5819
|
+
{
|
|
5820
|
+
type: "function",
|
|
5821
|
+
name: "createIntentAutoSwap",
|
|
5822
|
+
inputs: [
|
|
5823
|
+
{
|
|
5824
|
+
name: "user",
|
|
5825
|
+
type: "address",
|
|
5826
|
+
internalType: "address"
|
|
5827
|
+
},
|
|
5828
|
+
{
|
|
5829
|
+
name: "fromToken",
|
|
5830
|
+
type: "address",
|
|
5831
|
+
internalType: "address"
|
|
5832
|
+
},
|
|
5833
|
+
{
|
|
5834
|
+
name: "amount",
|
|
5835
|
+
type: "uint256",
|
|
5836
|
+
internalType: "uint256"
|
|
5837
|
+
},
|
|
5838
|
+
{
|
|
5839
|
+
name: "minOutputAmount",
|
|
5840
|
+
type: "uint256",
|
|
5841
|
+
internalType: "uint256"
|
|
5842
|
+
}
|
|
5843
|
+
],
|
|
5844
|
+
outputs: [],
|
|
5845
|
+
stateMutability: "nonpayable"
|
|
5846
|
+
},
|
|
5847
|
+
{
|
|
5848
|
+
type: "function",
|
|
5849
|
+
name: "getAutoSwapPreferences",
|
|
5850
|
+
inputs: [
|
|
5851
|
+
{
|
|
5852
|
+
name: "user",
|
|
5853
|
+
type: "address",
|
|
5854
|
+
internalType: "address"
|
|
5855
|
+
}
|
|
5856
|
+
],
|
|
5857
|
+
outputs: [
|
|
5858
|
+
{
|
|
5859
|
+
name: "",
|
|
5860
|
+
type: "tuple",
|
|
5861
|
+
internalType: "struct AutoSwapPreferences",
|
|
5862
|
+
components: [
|
|
5863
|
+
{
|
|
5864
|
+
name: "outputToken",
|
|
5865
|
+
type: "address",
|
|
5866
|
+
internalType: "address"
|
|
5867
|
+
},
|
|
5868
|
+
{
|
|
5869
|
+
name: "dstChain",
|
|
5870
|
+
type: "uint256",
|
|
5871
|
+
internalType: "uint256"
|
|
5872
|
+
},
|
|
5873
|
+
{
|
|
5874
|
+
name: "dstAddress",
|
|
5875
|
+
type: "bytes",
|
|
5876
|
+
internalType: "bytes"
|
|
5877
|
+
}
|
|
5878
|
+
]
|
|
5879
|
+
}
|
|
5880
|
+
],
|
|
5881
|
+
stateMutability: "view"
|
|
5882
|
+
}
|
|
5883
|
+
];
|
|
5884
|
+
|
|
5794
5885
|
// src/shared/abis/sonicWalletFactory.abi.ts
|
|
5795
5886
|
var sonicWalletFactoryAbi = [
|
|
5796
5887
|
{ inputs: [{ internalType: "address", name: "target", type: "address" }], name: "AddressEmptyCode", type: "error" },
|
|
@@ -6959,6 +7050,9 @@ var ConfigService = class {
|
|
|
6959
7050
|
getOriginalAssetAddress(chainId, hubAsset) {
|
|
6960
7051
|
return this.hubAssetToOriginalAssetMap.get(chainId)?.get(hubAsset.toLowerCase());
|
|
6961
7052
|
}
|
|
7053
|
+
getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress) {
|
|
7054
|
+
return this.supportedTokensPerChain.get(chainId)?.find((token) => token.address.toLowerCase() === originalAssetAddress.toLowerCase());
|
|
7055
|
+
}
|
|
6962
7056
|
isValidHubAsset(hubAsset) {
|
|
6963
7057
|
return this.supportedHubAssetsSet.has(hubAsset.toLowerCase());
|
|
6964
7058
|
}
|
|
@@ -15116,6 +15210,445 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15116
15210
|
return this.configService.getMoneyMarketReserveAssets();
|
|
15117
15211
|
}
|
|
15118
15212
|
};
|
|
15213
|
+
var PartnerFeeClaimService = class {
|
|
15214
|
+
config;
|
|
15215
|
+
hubProvider;
|
|
15216
|
+
configService;
|
|
15217
|
+
constructor({ config, configService, hubProvider }) {
|
|
15218
|
+
const solverConfig = config ? isConfiguredSolverConfig(config) ? config : types.getSolverConfig(hubProvider.chainConfig.chain.id) : types.getSolverConfig(types.SONIC_MAINNET_CHAIN_ID);
|
|
15219
|
+
this.config = {
|
|
15220
|
+
...solverConfig,
|
|
15221
|
+
relayerApiEndpoint: void 0,
|
|
15222
|
+
protocolIntentsContract: solverConfig.protocolIntentsContract
|
|
15223
|
+
};
|
|
15224
|
+
this.configService = configService;
|
|
15225
|
+
this.hubProvider = hubProvider;
|
|
15226
|
+
}
|
|
15227
|
+
/**
|
|
15228
|
+
* Util methods for dealing with tokens and hub assets
|
|
15229
|
+
*/
|
|
15230
|
+
getAllHubAssets() {
|
|
15231
|
+
return this.configService.getHubAssets();
|
|
15232
|
+
}
|
|
15233
|
+
getOriginalAssetAddress(chainId, hubAsset) {
|
|
15234
|
+
return this.configService.getOriginalAssetAddress(chainId, hubAsset);
|
|
15235
|
+
}
|
|
15236
|
+
getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress) {
|
|
15237
|
+
return this.configService.getSpokeTokenFromOriginalAssetAddress(chainId, originalAssetAddress);
|
|
15238
|
+
}
|
|
15239
|
+
/**
|
|
15240
|
+
* Fetches balances for all hub assets across all chains on Sonic for a given address or provider.
|
|
15241
|
+
*
|
|
15242
|
+
* @param params - Either an EVM address (as a string) or a SonicSpokeProviderType.
|
|
15243
|
+
* If an address, queries balances for that address.
|
|
15244
|
+
* If a SonicSpokeProviderType, uses the connected wallet's address.
|
|
15245
|
+
* @returns A promise resolving to a Result containing a Map from wrapped asset address (on Sonic)
|
|
15246
|
+
* to PartnerFeeClaimAssetBalance, or an Error on failure.
|
|
15247
|
+
*/
|
|
15248
|
+
async fetchAssetsBalances(params) {
|
|
15249
|
+
try {
|
|
15250
|
+
let queryAddress;
|
|
15251
|
+
if ("address" in params) {
|
|
15252
|
+
invariant6__default.default(viem.isAddress(params.address), "Address must be a valid EVM address");
|
|
15253
|
+
queryAddress = params.address;
|
|
15254
|
+
} else {
|
|
15255
|
+
invariant6__default.default(
|
|
15256
|
+
isSonicSpokeProviderType(params.spokeProvider),
|
|
15257
|
+
"PartnerFeeClaimService only supports Sonic spoke provider"
|
|
15258
|
+
);
|
|
15259
|
+
queryAddress = await params.spokeProvider.walletProvider.getWalletAddress();
|
|
15260
|
+
}
|
|
15261
|
+
const allAssetEntries = [];
|
|
15262
|
+
for (const [chainId, chainAssets] of Object.entries(this.getAllHubAssets())) {
|
|
15263
|
+
for (const [originalTokenAddress, hubAsset] of Object.entries(chainAssets)) {
|
|
15264
|
+
allAssetEntries.push({
|
|
15265
|
+
assetAddress: hubAsset.asset.toLowerCase(),
|
|
15266
|
+
// Use the wrapped asset address on Sonic
|
|
15267
|
+
originalChain: chainId,
|
|
15268
|
+
originalAddress: originalTokenAddress.toLowerCase(),
|
|
15269
|
+
hubAsset: {
|
|
15270
|
+
symbol: hubAsset.symbol,
|
|
15271
|
+
name: hubAsset.name,
|
|
15272
|
+
decimal: hubAsset.decimal
|
|
15273
|
+
}
|
|
15274
|
+
});
|
|
15275
|
+
}
|
|
15276
|
+
}
|
|
15277
|
+
const uniqueAssets = /* @__PURE__ */ new Map();
|
|
15278
|
+
for (const entry of allAssetEntries) {
|
|
15279
|
+
if (!uniqueAssets.has(entry.assetAddress)) {
|
|
15280
|
+
uniqueAssets.set(entry.assetAddress, entry);
|
|
15281
|
+
}
|
|
15282
|
+
}
|
|
15283
|
+
const uniqueAssetEntries = Array.from(uniqueAssets.values());
|
|
15284
|
+
const assetAddresses = uniqueAssetEntries.map((entry) => entry.assetAddress);
|
|
15285
|
+
const balanceResults = await this.hubProvider.publicClient.multicall({
|
|
15286
|
+
contracts: assetAddresses.map((assetAddress) => ({
|
|
15287
|
+
address: assetAddress,
|
|
15288
|
+
abi: viem.erc20Abi,
|
|
15289
|
+
functionName: "balanceOf",
|
|
15290
|
+
args: [queryAddress]
|
|
15291
|
+
})),
|
|
15292
|
+
allowFailure: false
|
|
15293
|
+
});
|
|
15294
|
+
const balancesMap = /* @__PURE__ */ new Map();
|
|
15295
|
+
let nonZeroCount = 0;
|
|
15296
|
+
uniqueAssetEntries.forEach((entry, index) => {
|
|
15297
|
+
const balanceResult = balanceResults[index];
|
|
15298
|
+
let balance;
|
|
15299
|
+
if (typeof balanceResult === "bigint") {
|
|
15300
|
+
balance = balanceResult;
|
|
15301
|
+
} else {
|
|
15302
|
+
console.warn(
|
|
15303
|
+
`[PartnerFeeClaimService] Unexpected balance result format for ${entry.hubAsset.symbol} (${entry.assetAddress}):`,
|
|
15304
|
+
balanceResult
|
|
15305
|
+
);
|
|
15306
|
+
balance = 0n;
|
|
15307
|
+
}
|
|
15308
|
+
if (balance > 0n) {
|
|
15309
|
+
nonZeroCount++;
|
|
15310
|
+
balancesMap.set(entry.assetAddress, {
|
|
15311
|
+
symbol: entry.hubAsset.symbol,
|
|
15312
|
+
name: entry.hubAsset.name,
|
|
15313
|
+
address: entry.assetAddress,
|
|
15314
|
+
// Wrapped asset address on Sonic
|
|
15315
|
+
originalChain: entry.originalChain,
|
|
15316
|
+
originalAddress: entry.originalAddress,
|
|
15317
|
+
decimal: entry.hubAsset.decimal,
|
|
15318
|
+
balance
|
|
15319
|
+
});
|
|
15320
|
+
}
|
|
15321
|
+
});
|
|
15322
|
+
return {
|
|
15323
|
+
ok: true,
|
|
15324
|
+
value: balancesMap
|
|
15325
|
+
};
|
|
15326
|
+
} catch (error) {
|
|
15327
|
+
return {
|
|
15328
|
+
ok: false,
|
|
15329
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15330
|
+
};
|
|
15331
|
+
}
|
|
15332
|
+
}
|
|
15333
|
+
/**
|
|
15334
|
+
* Gets the auto swap preferences for a user.
|
|
15335
|
+
*
|
|
15336
|
+
* @param params - Either an EVM address (as a string) or a SonicSpokeProviderType.
|
|
15337
|
+
* If an address, queries preferences for that address.
|
|
15338
|
+
* If a SonicSpokeProviderType, uses the connected wallet's address.
|
|
15339
|
+
* @returns A promise resolving to a Result containing the auto swap preferences, or an Error on failure.
|
|
15340
|
+
* The auto swap preferences include the output token, destination chain, and destination address.
|
|
15341
|
+
*/
|
|
15342
|
+
async getAutoSwapPreferences(params) {
|
|
15343
|
+
try {
|
|
15344
|
+
let queryAddress;
|
|
15345
|
+
if ("address" in params) {
|
|
15346
|
+
invariant6__default.default(viem.isAddress(params.address), "Address must be a valid EVM address");
|
|
15347
|
+
queryAddress = params.address;
|
|
15348
|
+
} else {
|
|
15349
|
+
invariant6__default.default(
|
|
15350
|
+
isSonicSpokeProviderType(params.spokeProvider),
|
|
15351
|
+
"PartnerFeeClaimService only supports Sonic spoke provider"
|
|
15352
|
+
);
|
|
15353
|
+
queryAddress = await params.spokeProvider.walletProvider.getWalletAddress();
|
|
15354
|
+
}
|
|
15355
|
+
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15356
|
+
const autoSwapPreferences = await this.hubProvider.publicClient.readContract({
|
|
15357
|
+
address: this.config.protocolIntentsContract,
|
|
15358
|
+
abi: ProtocolIntentsAbi,
|
|
15359
|
+
functionName: "getAutoSwapPreferences",
|
|
15360
|
+
args: [queryAddress]
|
|
15361
|
+
});
|
|
15362
|
+
const dstChain = autoSwapPreferences.dstChain === 0n ? "not configured" : this.configService.getSpokeChainIdFromIntentRelayChainId(
|
|
15363
|
+
autoSwapPreferences.dstChain
|
|
15364
|
+
);
|
|
15365
|
+
return {
|
|
15366
|
+
ok: true,
|
|
15367
|
+
value: {
|
|
15368
|
+
outputToken: autoSwapPreferences.outputToken,
|
|
15369
|
+
dstChain,
|
|
15370
|
+
dstAddress: autoSwapPreferences.dstAddress
|
|
15371
|
+
}
|
|
15372
|
+
};
|
|
15373
|
+
} catch (error) {
|
|
15374
|
+
return {
|
|
15375
|
+
ok: false,
|
|
15376
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15377
|
+
};
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
/**
|
|
15381
|
+
* Sets the auto swap preferences for a user.
|
|
15382
|
+
*
|
|
15383
|
+
* @template S - Type of the Sonic spoke provider
|
|
15384
|
+
* @template R - Whether to return raw transaction data (default: false)
|
|
15385
|
+
* @param {Object} args - The argument object
|
|
15386
|
+
* @param {SetSwapPreferenceParams} args.params - The swap preference parameters
|
|
15387
|
+
* @param {S} args.spokeProvider - The Sonic spoke provider
|
|
15388
|
+
* @param {R} [args.raw] - If true, the raw transaction data will be returned
|
|
15389
|
+
* @returns {Promise<Result<TxReturnType<S, R>, SetSwapPreferenceError>>}
|
|
15390
|
+
* - If `raw` is true or the provider is a raw provider, returns the raw transaction object.
|
|
15391
|
+
* - Otherwise, returns the transaction hash of the submitted transaction.
|
|
15392
|
+
* - If failed, returns an error object with code 'SET_SWAP_PREFERENCE_FAILED'.
|
|
15393
|
+
*/
|
|
15394
|
+
async setSwapPreference({
|
|
15395
|
+
params,
|
|
15396
|
+
spokeProvider,
|
|
15397
|
+
raw
|
|
15398
|
+
}) {
|
|
15399
|
+
try {
|
|
15400
|
+
invariant6__default.default(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15401
|
+
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15402
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15403
|
+
const rawTx = {
|
|
15404
|
+
from: walletAddress,
|
|
15405
|
+
to: this.config.protocolIntentsContract,
|
|
15406
|
+
value: 0n,
|
|
15407
|
+
data: viem.encodeFunctionData({
|
|
15408
|
+
abi: ProtocolIntentsAbi,
|
|
15409
|
+
functionName: "setAutoSwapPreferences",
|
|
15410
|
+
args: [
|
|
15411
|
+
params.outputToken,
|
|
15412
|
+
BigInt(types.getIntentRelayChainId(params.dstChain)),
|
|
15413
|
+
encodeAddress(params.dstChain, params.dstAddress)
|
|
15414
|
+
]
|
|
15415
|
+
})
|
|
15416
|
+
};
|
|
15417
|
+
if (raw || isSonicRawSpokeProvider(spokeProvider)) {
|
|
15418
|
+
return {
|
|
15419
|
+
ok: true,
|
|
15420
|
+
value: rawTx
|
|
15421
|
+
};
|
|
15422
|
+
}
|
|
15423
|
+
const txHash = await spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
15424
|
+
return {
|
|
15425
|
+
ok: true,
|
|
15426
|
+
value: txHash
|
|
15427
|
+
};
|
|
15428
|
+
} catch (error) {
|
|
15429
|
+
return {
|
|
15430
|
+
ok: false,
|
|
15431
|
+
error: {
|
|
15432
|
+
code: "SET_SWAP_PREFERENCE_FAILED",
|
|
15433
|
+
data: {
|
|
15434
|
+
payload: params,
|
|
15435
|
+
error
|
|
15436
|
+
}
|
|
15437
|
+
}
|
|
15438
|
+
};
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
/**
|
|
15442
|
+
* Checks if a token is already approved to the protocol intents contract for a given address or the connected wallet.
|
|
15443
|
+
*
|
|
15444
|
+
* @param params - Object containing:
|
|
15445
|
+
* - token: The ERC20 token address to check.
|
|
15446
|
+
* - spokeProvider: The SonicSpokeProviderType instance.
|
|
15447
|
+
* - address (optional): The address to check allowance for. If not provided, uses the currently connected wallet.
|
|
15448
|
+
* @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.
|
|
15449
|
+
*/
|
|
15450
|
+
async isTokenApproved({ token, spokeProvider }) {
|
|
15451
|
+
try {
|
|
15452
|
+
invariant6__default.default(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15453
|
+
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15454
|
+
const queryAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15455
|
+
if (token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
15456
|
+
return {
|
|
15457
|
+
ok: true,
|
|
15458
|
+
value: true
|
|
15459
|
+
};
|
|
15460
|
+
}
|
|
15461
|
+
const allowedAmount = await this.hubProvider.publicClient.readContract({
|
|
15462
|
+
address: token,
|
|
15463
|
+
abi: viem.erc20Abi,
|
|
15464
|
+
functionName: "allowance",
|
|
15465
|
+
args: [queryAddress, this.config.protocolIntentsContract]
|
|
15466
|
+
});
|
|
15467
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
15468
|
+
const isMaxApproved = allowedAmount >= maxUint256 - 1000n;
|
|
15469
|
+
return {
|
|
15470
|
+
ok: true,
|
|
15471
|
+
value: isMaxApproved
|
|
15472
|
+
};
|
|
15473
|
+
} catch (error) {
|
|
15474
|
+
return {
|
|
15475
|
+
ok: false,
|
|
15476
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15477
|
+
};
|
|
15478
|
+
}
|
|
15479
|
+
}
|
|
15480
|
+
/**
|
|
15481
|
+
* Approves a token to the protocol intents contract with maximum allowance
|
|
15482
|
+
* @param {Address} token - The token address to approve
|
|
15483
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15484
|
+
* @param {boolean} raw - Whether to return raw transaction data
|
|
15485
|
+
* @returns {Promise<Result<TxReturnType<SonicSpokeProviderType, R>, Error>>} Transaction hash or raw transaction
|
|
15486
|
+
*/
|
|
15487
|
+
async approveToken({
|
|
15488
|
+
token,
|
|
15489
|
+
spokeProvider,
|
|
15490
|
+
raw
|
|
15491
|
+
}) {
|
|
15492
|
+
try {
|
|
15493
|
+
invariant6__default.default(isSonicSpokeProviderType(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15494
|
+
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15495
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
15496
|
+
const result = await Erc20Service.approve(
|
|
15497
|
+
token,
|
|
15498
|
+
maxUint256,
|
|
15499
|
+
this.config.protocolIntentsContract,
|
|
15500
|
+
spokeProvider,
|
|
15501
|
+
raw
|
|
15502
|
+
);
|
|
15503
|
+
return {
|
|
15504
|
+
ok: true,
|
|
15505
|
+
value: result
|
|
15506
|
+
};
|
|
15507
|
+
} catch (error) {
|
|
15508
|
+
return {
|
|
15509
|
+
ok: false,
|
|
15510
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
15511
|
+
};
|
|
15512
|
+
}
|
|
15513
|
+
}
|
|
15514
|
+
/**
|
|
15515
|
+
* Creates an intent to auto swap tokens using the protocol intents contract
|
|
15516
|
+
* @param {PartnerFeeClaimSwapParams} params - The swap parameters
|
|
15517
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15518
|
+
* @param {boolean} raw - Whether to return raw transaction data
|
|
15519
|
+
* @returns {Promise<TxReturnType<SonicSpokeProviderType, R>>} Transaction hash or raw transaction
|
|
15520
|
+
*/
|
|
15521
|
+
async createIntentAutoSwap({
|
|
15522
|
+
params,
|
|
15523
|
+
spokeProvider,
|
|
15524
|
+
raw
|
|
15525
|
+
}) {
|
|
15526
|
+
try {
|
|
15527
|
+
invariant6__default.default(isSonicSpokeProvider(spokeProvider), "PartnerFeeClaimService only supports Sonic spoke provider");
|
|
15528
|
+
invariant6__default.default(this.config.protocolIntentsContract, "protocolIntentsContract is not configured in solver config");
|
|
15529
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15530
|
+
const minOutputAmount = 0n;
|
|
15531
|
+
const rawTx = {
|
|
15532
|
+
from: walletAddress,
|
|
15533
|
+
to: this.config.protocolIntentsContract,
|
|
15534
|
+
value: 0n,
|
|
15535
|
+
data: viem.encodeFunctionData({
|
|
15536
|
+
abi: ProtocolIntentsAbi,
|
|
15537
|
+
functionName: "createIntentAutoSwap",
|
|
15538
|
+
args: [walletAddress, params.fromToken, params.amount, minOutputAmount]
|
|
15539
|
+
})
|
|
15540
|
+
};
|
|
15541
|
+
if (raw || isSonicRawSpokeProvider(spokeProvider)) {
|
|
15542
|
+
return {
|
|
15543
|
+
ok: true,
|
|
15544
|
+
value: rawTx
|
|
15545
|
+
};
|
|
15546
|
+
}
|
|
15547
|
+
const txHash = await spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
15548
|
+
return {
|
|
15549
|
+
ok: true,
|
|
15550
|
+
value: txHash
|
|
15551
|
+
};
|
|
15552
|
+
} catch (error) {
|
|
15553
|
+
return {
|
|
15554
|
+
ok: false,
|
|
15555
|
+
error: {
|
|
15556
|
+
code: "CREATE_INTENT_AUTO_SWAP_FAILED",
|
|
15557
|
+
data: {
|
|
15558
|
+
payload: params,
|
|
15559
|
+
error
|
|
15560
|
+
}
|
|
15561
|
+
}
|
|
15562
|
+
};
|
|
15563
|
+
}
|
|
15564
|
+
}
|
|
15565
|
+
/**
|
|
15566
|
+
* Creates an intent auto swap and handles post-execution
|
|
15567
|
+
* @param {PartnerFeeClaimSwapParams} params - The swap parameters
|
|
15568
|
+
* @param {SonicSpokeProviderType} spokeProvider - The Sonic spoke provider
|
|
15569
|
+
* @returns {Promise<Result<SolverExecutionResponse, IntentError<IntentErrorCode>>>} Solver execution response
|
|
15570
|
+
*/
|
|
15571
|
+
async swap({
|
|
15572
|
+
params,
|
|
15573
|
+
spokeProvider
|
|
15574
|
+
}) {
|
|
15575
|
+
try {
|
|
15576
|
+
const txHash = await this.createIntentAutoSwap({ params, spokeProvider, raw: false });
|
|
15577
|
+
if (!txHash.ok) {
|
|
15578
|
+
return txHash;
|
|
15579
|
+
}
|
|
15580
|
+
let intentTxHash;
|
|
15581
|
+
try {
|
|
15582
|
+
const receipt = await spokeProvider.publicClient.waitForTransactionReceipt({ hash: txHash.value });
|
|
15583
|
+
intentTxHash = receipt.transactionHash;
|
|
15584
|
+
} catch (error) {
|
|
15585
|
+
return {
|
|
15586
|
+
ok: false,
|
|
15587
|
+
error: {
|
|
15588
|
+
code: "WAIT_INTENT_AUTO_SWAP_FAILED",
|
|
15589
|
+
data: {
|
|
15590
|
+
payload: params,
|
|
15591
|
+
error
|
|
15592
|
+
}
|
|
15593
|
+
}
|
|
15594
|
+
};
|
|
15595
|
+
}
|
|
15596
|
+
const solverExecutionResponse = await SolverApiService.postExecution(
|
|
15597
|
+
{
|
|
15598
|
+
intent_tx_hash: intentTxHash
|
|
15599
|
+
},
|
|
15600
|
+
this.config
|
|
15601
|
+
);
|
|
15602
|
+
if (!solverExecutionResponse.ok) {
|
|
15603
|
+
return solverExecutionResponse;
|
|
15604
|
+
}
|
|
15605
|
+
return {
|
|
15606
|
+
ok: true,
|
|
15607
|
+
value: {
|
|
15608
|
+
srcTxHash: txHash.value,
|
|
15609
|
+
solverExecutionResponse: solverExecutionResponse.value,
|
|
15610
|
+
intentTxHash
|
|
15611
|
+
}
|
|
15612
|
+
};
|
|
15613
|
+
} catch (error) {
|
|
15614
|
+
return {
|
|
15615
|
+
ok: false,
|
|
15616
|
+
error: {
|
|
15617
|
+
code: "UNKNOWN",
|
|
15618
|
+
data: { payload: params, error }
|
|
15619
|
+
}
|
|
15620
|
+
};
|
|
15621
|
+
}
|
|
15622
|
+
}
|
|
15623
|
+
};
|
|
15624
|
+
function isSetSwapPreferenceError(error) {
|
|
15625
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "SET_SWAP_PREFERENCE_FAILED";
|
|
15626
|
+
}
|
|
15627
|
+
function isCreateIntentAutoSwapError(error) {
|
|
15628
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "CREATE_INTENT_AUTO_SWAP_FAILED";
|
|
15629
|
+
}
|
|
15630
|
+
function isWaitIntentAutoSwapError(error) {
|
|
15631
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "WAIT_INTENT_AUTO_SWAP_FAILED";
|
|
15632
|
+
}
|
|
15633
|
+
function isSolverErrorResponse(error) {
|
|
15634
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "SOLVER_ERROR";
|
|
15635
|
+
}
|
|
15636
|
+
function isUnknownIntentAutoSwapError(error) {
|
|
15637
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "UNKNOWN";
|
|
15638
|
+
}
|
|
15639
|
+
|
|
15640
|
+
// src/partner/PartnerService.ts
|
|
15641
|
+
var PartnerService = class {
|
|
15642
|
+
feeClaim;
|
|
15643
|
+
// Partner Fee Claim service for partner fee operations
|
|
15644
|
+
constructor(config) {
|
|
15645
|
+
this.feeClaim = new PartnerFeeClaimService({
|
|
15646
|
+
config: config?.feeClaim,
|
|
15647
|
+
configService: config.configService,
|
|
15648
|
+
hubProvider: config.hubProvider
|
|
15649
|
+
});
|
|
15650
|
+
}
|
|
15651
|
+
};
|
|
15119
15652
|
|
|
15120
15653
|
// src/shared/entities/Sodax.ts
|
|
15121
15654
|
var Sodax = class {
|
|
@@ -15132,6 +15665,8 @@ var Sodax = class {
|
|
|
15132
15665
|
// Bridge service enabling cross-chain transfers
|
|
15133
15666
|
staking;
|
|
15134
15667
|
// Staking service enabling SODA staking operations
|
|
15668
|
+
partners;
|
|
15669
|
+
// Partner service enabling partner fee claim and other partner operations
|
|
15135
15670
|
config;
|
|
15136
15671
|
// Config service enabling configuration data fetching from the backend API or fallbacking to default values
|
|
15137
15672
|
hubProvider;
|
|
@@ -15198,6 +15733,11 @@ var Sodax = class {
|
|
|
15198
15733
|
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
15199
15734
|
configService: this.config
|
|
15200
15735
|
});
|
|
15736
|
+
this.partners = config?.partners ? new PartnerService({
|
|
15737
|
+
feeClaim: config.partners.feeClaim,
|
|
15738
|
+
configService: this.config,
|
|
15739
|
+
hubProvider: this.hubProvider
|
|
15740
|
+
}) : new PartnerService({ configService: this.config, hubProvider: this.hubProvider });
|
|
15201
15741
|
}
|
|
15202
15742
|
/**
|
|
15203
15743
|
* Initializes the Sodax instance with dynamic configuration.
|
|
@@ -15801,6 +16341,9 @@ function isInjectiveRawSpokeProvider(value) {
|
|
|
15801
16341
|
function isSonicRawSpokeProvider(value) {
|
|
15802
16342
|
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "EVM" && value.chainConfig.chain.id === types.SONIC_MAINNET_CHAIN_ID;
|
|
15803
16343
|
}
|
|
16344
|
+
function isAddressString(value) {
|
|
16345
|
+
return typeof value === "string";
|
|
16346
|
+
}
|
|
15804
16347
|
async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
15805
16348
|
do {
|
|
15806
16349
|
try {
|
|
@@ -20168,6 +20711,9 @@ exports.MAX_UINT256 = MAX_UINT256;
|
|
|
20168
20711
|
exports.MigrationService = MigrationService;
|
|
20169
20712
|
exports.MoneyMarketDataService = MoneyMarketDataService;
|
|
20170
20713
|
exports.MoneyMarketService = MoneyMarketService;
|
|
20714
|
+
exports.PartnerFeeClaimService = PartnerFeeClaimService;
|
|
20715
|
+
exports.PartnerService = PartnerService;
|
|
20716
|
+
exports.ProtocolIntentsAbi = ProtocolIntentsAbi;
|
|
20171
20717
|
exports.RAY = RAY;
|
|
20172
20718
|
exports.RAY_DECIMALS = RAY_DECIMALS;
|
|
20173
20719
|
exports.SECONDS_PER_YEAR = SECONDS_PER_YEAR;
|
|
@@ -20255,9 +20801,11 @@ exports.getTransactionPackets = getTransactionPackets;
|
|
|
20255
20801
|
exports.hexToBigInt = hexToBigInt;
|
|
20256
20802
|
exports.hexToSolanaAddress = hexToSolanaAddress;
|
|
20257
20803
|
exports.hyper = hyper;
|
|
20804
|
+
exports.isAddressString = isAddressString;
|
|
20258
20805
|
exports.isBalnMigrateParams = isBalnMigrateParams;
|
|
20259
20806
|
exports.isConfiguredMoneyMarketConfig = isConfiguredMoneyMarketConfig;
|
|
20260
20807
|
exports.isConfiguredSolverConfig = isConfiguredSolverConfig;
|
|
20808
|
+
exports.isCreateIntentAutoSwapError = isCreateIntentAutoSwapError;
|
|
20261
20809
|
exports.isEvmHubChainConfig = isEvmHubChainConfig;
|
|
20262
20810
|
exports.isEvmInitializedConfig = isEvmInitializedConfig;
|
|
20263
20811
|
exports.isEvmRawSpokeProvider = isEvmRawSpokeProvider;
|
|
@@ -20302,10 +20850,12 @@ exports.isPartnerFeePercentage = isPartnerFeePercentage;
|
|
|
20302
20850
|
exports.isRawSpokeProvider = isRawSpokeProvider;
|
|
20303
20851
|
exports.isResponseAddressType = isResponseAddressType;
|
|
20304
20852
|
exports.isResponseSigningType = isResponseSigningType;
|
|
20853
|
+
exports.isSetSwapPreferenceError = isSetSwapPreferenceError;
|
|
20305
20854
|
exports.isSolanaNativeToken = isSolanaNativeToken;
|
|
20306
20855
|
exports.isSolanaRawSpokeProvider = isSolanaRawSpokeProvider;
|
|
20307
20856
|
exports.isSolanaSpokeProvider = isSolanaSpokeProvider;
|
|
20308
20857
|
exports.isSolanaSpokeProviderType = isSolanaSpokeProviderType;
|
|
20858
|
+
exports.isSolverErrorResponse = isSolverErrorResponse;
|
|
20309
20859
|
exports.isSonicRawSpokeProvider = isSonicRawSpokeProvider;
|
|
20310
20860
|
exports.isSonicSpokeProvider = isSonicSpokeProvider;
|
|
20311
20861
|
exports.isSonicSpokeProviderType = isSonicSpokeProviderType;
|
|
@@ -20316,6 +20866,8 @@ exports.isSuiRawSpokeProvider = isSuiRawSpokeProvider;
|
|
|
20316
20866
|
exports.isSuiSpokeProvider = isSuiSpokeProvider;
|
|
20317
20867
|
exports.isSuiSpokeProviderType = isSuiSpokeProviderType;
|
|
20318
20868
|
exports.isUnifiedBnUSDMigrateParams = isUnifiedBnUSDMigrateParams;
|
|
20869
|
+
exports.isUnknownIntentAutoSwapError = isUnknownIntentAutoSwapError;
|
|
20870
|
+
exports.isWaitIntentAutoSwapError = isWaitIntentAutoSwapError;
|
|
20319
20871
|
exports.isWaitUntilIntentExecutedFailed = isWaitUntilIntentExecutedFailed;
|
|
20320
20872
|
exports.nativeToUSD = nativeToUSD;
|
|
20321
20873
|
exports.newbnUSDSpokeChainIds = newbnUSDSpokeChainIds;
|