@sodax/sdk 0.0.1-rc.2 → 0.0.1-rc.4
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/README.md +2 -0
- package/dist/constants.d.ts +17 -32
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +67 -67
- package/dist/constants.js.map +1 -1
- package/dist/constants.test.js +3 -2
- package/dist/constants.test.js.map +1 -1
- package/dist/entities/Providers.d.ts +3 -10
- package/dist/entities/Providers.d.ts.map +1 -1
- package/dist/entities/Providers.js +2 -2
- package/dist/entities/Providers.js.map +1 -1
- package/dist/entities/Sodax.test.js +120 -104
- package/dist/entities/Sodax.test.js.map +1 -1
- package/dist/entities/cosmos/CWSpokeProvider.d.ts +2 -1
- package/dist/entities/cosmos/CWSpokeProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/CWSpokeProvider.js.map +1 -1
- package/dist/entities/cosmos/CosmosWalletProvider.d.ts +2 -2
- package/dist/entities/cosmos/CosmosWalletProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/CosmosWalletProvider.js +4 -4
- package/dist/entities/cosmos/CosmosWalletProvider.js.map +1 -1
- package/dist/entities/cosmos/InjectiveWalletProvider.d.ts +2 -2
- package/dist/entities/cosmos/InjectiveWalletProvider.d.ts.map +1 -1
- package/dist/entities/cosmos/InjectiveWalletProvider.js +4 -4
- package/dist/entities/cosmos/InjectiveWalletProvider.js.map +1 -1
- package/dist/entities/icon/IconSpokeProvider.d.ts +5 -3
- package/dist/entities/icon/IconSpokeProvider.d.ts.map +1 -1
- package/dist/entities/icon/IconSpokeProvider.js +4 -1
- package/dist/entities/icon/IconSpokeProvider.js.map +1 -1
- package/dist/entities/icon/index.d.ts +0 -1
- package/dist/entities/icon/index.d.ts.map +1 -1
- package/dist/entities/icon/index.js +0 -1
- package/dist/entities/icon/index.js.map +1 -1
- package/dist/entities/index.d.ts +0 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +0 -1
- package/dist/entities/index.js.map +1 -1
- package/dist/entities/solana/SolanaWalletProvider.d.ts +3 -3
- package/dist/entities/solana/SolanaWalletProvider.d.ts.map +1 -1
- package/dist/entities/solana/SolanaWalletProvider.js +3 -3
- package/dist/entities/solana/SolanaWalletProvider.js.map +1 -1
- package/dist/entities/solana/utils/utils.js +2 -1
- package/dist/entities/solana/utils/utils.js.map +1 -1
- package/dist/entities/stellar/StellarSpokeProvider.d.ts +4 -11
- package/dist/entities/stellar/StellarSpokeProvider.d.ts.map +1 -1
- package/dist/entities/stellar/StellarSpokeProvider.js +27 -31
- package/dist/entities/stellar/StellarSpokeProvider.js.map +1 -1
- package/dist/entities/sui/SuiSpokeProvider.d.ts +6 -5
- package/dist/entities/sui/SuiSpokeProvider.d.ts.map +1 -1
- package/dist/entities/sui/SuiSpokeProvider.js +9 -7
- package/dist/entities/sui/SuiSpokeProvider.js.map +1 -1
- package/dist/guards.js +8 -8
- package/dist/guards.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/hub/EvmAssetManagerService.d.ts +2 -1
- package/dist/services/hub/EvmAssetManagerService.d.ts.map +1 -1
- package/dist/services/hub/EvmAssetManagerService.js.map +1 -1
- package/dist/services/hub/EvmVaultTokenService.d.ts.map +1 -1
- package/dist/services/hub/EvmVaultTokenService.js +4 -2
- package/dist/services/hub/EvmVaultTokenService.js.map +1 -1
- package/dist/services/hub/EvmWalletAbstraction.d.ts +2 -1
- package/dist/services/hub/EvmWalletAbstraction.d.ts.map +1 -1
- package/dist/services/hub/EvmWalletAbstraction.js.map +1 -1
- package/dist/services/intentRelay/IntentRelayApiService.d.ts +2 -1
- package/dist/services/intentRelay/IntentRelayApiService.d.ts.map +1 -1
- package/dist/services/intentRelay/IntentRelayApiService.js.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.d.ts +267 -63
- package/dist/services/moneyMarket/MoneyMarketService.d.ts.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.js +283 -73
- package/dist/services/moneyMarket/MoneyMarketService.js.map +1 -1
- package/dist/services/moneyMarket/MoneyMarketService.test.js +36 -19
- package/dist/services/moneyMarket/MoneyMarketService.test.js.map +1 -1
- package/dist/services/shared/Erc20Service.d.ts +6 -5
- package/dist/services/shared/Erc20Service.d.ts.map +1 -1
- package/dist/services/shared/Erc20Service.js +7 -6
- package/dist/services/shared/Erc20Service.js.map +1 -1
- package/dist/services/solver/SolverApiService.test.js +2 -1
- package/dist/services/solver/SolverApiService.test.js.map +1 -1
- package/dist/services/solver/SolverService.d.ts +138 -37
- package/dist/services/solver/SolverService.d.ts.map +1 -1
- package/dist/services/solver/SolverService.js +146 -41
- package/dist/services/solver/SolverService.js.map +1 -1
- package/dist/services/solver/SolverService.test.js +89 -143
- package/dist/services/solver/SolverService.test.js.map +1 -1
- package/dist/services/spoke/CWSpokeService.d.ts +1 -1
- package/dist/services/spoke/CWSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/CWSpokeService.js +2 -2
- package/dist/services/spoke/CWSpokeService.js.map +1 -1
- package/dist/services/spoke/EvmSpokeService.d.ts +3 -2
- package/dist/services/spoke/EvmSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/EvmSpokeService.js +4 -2
- package/dist/services/spoke/EvmSpokeService.js.map +1 -1
- package/dist/services/spoke/IconSpokeService.d.ts +4 -3
- package/dist/services/spoke/IconSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/IconSpokeService.js +28 -15
- package/dist/services/spoke/IconSpokeService.js.map +1 -1
- package/dist/services/spoke/SolanaSpokeService.d.ts +3 -2
- package/dist/services/spoke/SolanaSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SolanaSpokeService.js.map +1 -1
- package/dist/services/spoke/SpokeService.d.ts +2 -1
- package/dist/services/spoke/SpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SpokeService.js.map +1 -1
- package/dist/services/spoke/StellarSpokeService.d.ts +1 -1
- package/dist/services/spoke/StellarSpokeService.d.ts.map +1 -1
- package/dist/services/spoke/SuiSpokeService.d.ts +1 -1
- package/dist/services/spoke/SuiSpokeService.d.ts.map +1 -1
- package/dist/tests/services/hub/EvmAssetManagerService.test.js +45 -30
- package/dist/tests/services/hub/EvmAssetManagerService.test.js.map +1 -1
- package/dist/tests/services/spoke/EvmSpokeService.test.js +7 -6
- package/dist/tests/services/spoke/EvmSpokeService.test.js.map +1 -1
- package/dist/types.d.ts +28 -71
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/evm-utils.d.ts +2 -2
- package/dist/utils/evm-utils.d.ts.map +1 -1
- package/dist/utils/shared-utils.d.ts +2 -1
- package/dist/utils/shared-utils.d.ts.map +1 -1
- package/dist/utils/shared-utils.js +3 -0
- package/dist/utils/shared-utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/entities/icon/IconWalletProvider.d.ts +0 -12
- package/dist/entities/icon/IconWalletProvider.d.ts.map +0 -1
- package/dist/entities/icon/IconWalletProvider.js +0 -34
- package/dist/entities/icon/IconWalletProvider.js.map +0 -1
- package/dist/entities/sui/SuiWalletProvider.d.ts +0 -15
- package/dist/entities/sui/SuiWalletProvider.d.ts.map +0 -1
- package/dist/entities/sui/SuiWalletProvider.js +0 -43
- package/dist/entities/sui/SuiWalletProvider.js.map +0 -1
- package/dist/interfaces.d.ts +0 -8
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/interfaces.js +0 -2
- package/dist/interfaces.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyMarketService.d.ts","sourceRoot":"","sources":["../../../src/services/moneyMarket/MoneyMarketService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAsB,MAAM,MAAM,CAAC;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAA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AAC,CAAC;IASzE;;;;;;OAMG;IACG,mBAAmB,CACvB,WAAW,EAAE,OAAO,EACpB,kBAAkB,EAAE,OAAO,EAC3B,qBAAqB,EAAE,OAAO,GAC7B,OAAO,CAAC,SAAS,CAAC,SAAS,eAAe,EAAE,EAAE,MAAM,CAAC,CAAC;IASzD;;;;;OAKG;WACW,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,WAAW,EAAE,OAAO,GAAG,eAAe;IAYxG;;;;;;;;OAQG;WACW,cAAc,CAAC,MAAM,EAAE,+BAA+B,EAAE,WAAW,EAAE,OAAO,GAAG,eAAe;IAY5G;;;;;OAKG;WACW,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,WAAW,EAAE,OAAO,GAAG,eAAe;IAYxG;;;;;;;;;OASG;WACW,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,WAAW,EAAE,OAAO,GAAG,eAAe;IAYtG;;;;;OAKG;WACW,sBAAsB,CAClC,MAAM,EAAE,uCAAuC,EAC/C,WAAW,EAAE,OAAO,GACnB,eAAe;IAYlB;;;;;;OAMG;WACW,mCAAmC,CAC/C,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,EACxB,WAAW,EAAE,OAAO,GACnB,eAAe;IAYlB;;;;OAIG;IACI,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,KAAK,EAAE;IAIlE;;;;OAIG;IACI,oBAAoB,IAAI,SAAS,OAAO,EAAE;CAGlD"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { encodeFunctionData } from 'viem';
|
|
2
2
|
import { poolAbi } from '../../abis/pool.abi.js';
|
|
3
|
-
import { DEFAULT_RELAYER_API_ENDPOINT, getHubAssetInfo, getMoneyMarketConfig, getSupportedMoneyMarketTokens, isConfiguredMoneyMarketConfig, isValidOriginalAssetAddress, isValidSpokeChainId, moneyMarketReserveAssets, SpokeService, relayTxAndWaitPacket, uiPoolDataAbi,
|
|
3
|
+
import { DEFAULT_RELAYER_API_ENDPOINT, getHubAssetInfo, getMoneyMarketConfig, getSupportedMoneyMarketTokens, isConfiguredMoneyMarketConfig, isValidOriginalAssetAddress, isValidSpokeChainId, moneyMarketReserveAssets, SpokeService, relayTxAndWaitPacket, uiPoolDataAbi, DEFAULT_RELAY_TX_TIMEOUT, EvmSpokeProvider, isMoneyMarketSupportedToken, } from '../../index.js';
|
|
4
4
|
import { calculateFeeAmount, encodeContractCalls } from '../../utils/index.js';
|
|
5
5
|
import { EvmAssetManagerService, EvmVaultTokenService, EvmWalletAbstraction } from '../hub/index.js';
|
|
6
6
|
import { Erc20Service } from '../shared/index.js';
|
|
7
7
|
import invariant from 'tiny-invariant';
|
|
8
|
+
import { SONIC_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
8
9
|
export class MoneyMarketService {
|
|
9
10
|
config;
|
|
10
11
|
hubProvider;
|
|
@@ -33,15 +34,30 @@ export class MoneyMarketService {
|
|
|
33
34
|
this.hubProvider = hubProvider;
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
|
-
* Check
|
|
37
|
-
* @param {MoneyMarketRepayParams | MoneyMarketSupplyParams} params - Money market params
|
|
38
|
-
* @param {SpokeProvider} spokeProvider - The spoke provider
|
|
39
|
-
* @return {Promise<Result<boolean>>} -
|
|
37
|
+
* Check if allowance is sufficient for supply or repay operations (currently required for EVM only)
|
|
38
|
+
* @param {MoneyMarketRepayParams | MoneyMarketSupplyParams} params - Money market params containing token address and amount
|
|
39
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider instance
|
|
40
|
+
* @return {Promise<Result<boolean>>} - Returns true if allowance is sufficient, false otherwise
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const allowanceValid = await isAllowanceValid({
|
|
44
|
+
* token: '0x...', // Address of the token (spoke chain) to supply
|
|
45
|
+
* amount: 1000n, // Amount to supply (in token decimals)
|
|
46
|
+
* }, spokeProvider);
|
|
47
|
+
*
|
|
48
|
+
* if (!allowanceValid.ok) {
|
|
49
|
+
* // Handle error
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* if (!allowanceValid.value) {
|
|
53
|
+
* // Need to approve
|
|
54
|
+
* }
|
|
40
55
|
*/
|
|
41
56
|
async isAllowanceValid(params, spokeProvider) {
|
|
42
57
|
try {
|
|
43
58
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
44
|
-
|
|
59
|
+
const walletAddress = (await spokeProvider.walletProvider.getWalletAddress());
|
|
60
|
+
return Erc20Service.isAllowanceValid(params.token, params.amount, walletAddress, spokeProvider.chainConfig.addresses.assetManager, spokeProvider);
|
|
45
61
|
}
|
|
46
62
|
return {
|
|
47
63
|
ok: true,
|
|
@@ -56,16 +72,31 @@ export class MoneyMarketService {
|
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
/**
|
|
59
|
-
* Approve
|
|
75
|
+
* Approve amount spending (currently required for EVM only)
|
|
60
76
|
* @param token - ERC20 token address
|
|
61
77
|
* @param amount - Amount to approve
|
|
62
|
-
* @param
|
|
78
|
+
* @param spender - Spender address
|
|
63
79
|
* @param spokeProvider - Spoke provider
|
|
80
|
+
* @returns {Promise<Result<EvmRawTransactionReceipt>>} - Returns the transaction receipt
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const approveResult = await approve(
|
|
84
|
+
* '0x...', // ERC20 token address
|
|
85
|
+
* 1000n, // Amount to approve (in token decimals)
|
|
86
|
+
* '0x...', // Spender address (usually the asset manager contract: spokeProvider.chainConfig.addresses.assetManager)
|
|
87
|
+
* spokeProvider
|
|
88
|
+
* );
|
|
89
|
+
*
|
|
90
|
+
* if (!approveResult.ok) {
|
|
91
|
+
* // Handle error
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* const txReceipt = approveResult.value;
|
|
64
95
|
*/
|
|
65
|
-
async approve(token, amount,
|
|
96
|
+
async approve(token, amount, spender, spokeProvider) {
|
|
66
97
|
try {
|
|
67
98
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
68
|
-
return Erc20Service.approve(token, amount,
|
|
99
|
+
return Erc20Service.approve(token, amount, spender, spokeProvider);
|
|
69
100
|
}
|
|
70
101
|
return {
|
|
71
102
|
ok: false,
|
|
@@ -80,11 +111,31 @@ export class MoneyMarketService {
|
|
|
80
111
|
}
|
|
81
112
|
}
|
|
82
113
|
/**
|
|
83
|
-
* Supply tokens to the money market pool and submit the intent to the Solver API
|
|
114
|
+
* Supply tokens to the money market pool, relay the transaction to the hub and submit the intent to the Solver API
|
|
84
115
|
* @param params - The parameters for the supply transaction.
|
|
85
116
|
* @param spokeProvider - The spoke provider.
|
|
86
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is
|
|
87
|
-
* @returns [
|
|
117
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
118
|
+
* @returns {Promise<Result<[Hex, Hex], MoneyMarketError>>} - Returns the transaction result and the hub transaction hash or error
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const result = await moneyMarketService.supplyAndSubmit(
|
|
122
|
+
* {
|
|
123
|
+
* token: '0x...', // Address of the token (spoke chain address) to supply
|
|
124
|
+
* amount: 1000n, // Amount to supply (in token decimals)
|
|
125
|
+
* },
|
|
126
|
+
* spokeProvider,
|
|
127
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
128
|
+
* );
|
|
129
|
+
*
|
|
130
|
+
* if (!result.ok) {
|
|
131
|
+
* // Handle error
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* const [
|
|
135
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
136
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
137
|
+
* ] = result.value;
|
|
138
|
+
* console.log('Supply transaction hashes:', { spokeTxHash, hubTxHash });
|
|
88
139
|
*/
|
|
89
140
|
async supplyAndSubmit(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
90
141
|
try {
|
|
@@ -115,22 +166,48 @@ export class MoneyMarketService {
|
|
|
115
166
|
}
|
|
116
167
|
}
|
|
117
168
|
/**
|
|
118
|
-
* Supply tokens to the money market pool
|
|
119
|
-
* NOTE: This method does not submit the intent to the Solver API
|
|
169
|
+
* Supply tokens to the money market pool without submitting the intent to the Solver API
|
|
170
|
+
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
171
|
+
* In order to successfully supply tokens, you need to:
|
|
172
|
+
* 1. Check if the allowance is sufficient
|
|
173
|
+
* 2. Approve the asset manager contract to spend the tokens
|
|
174
|
+
* 3. Supply the tokens
|
|
175
|
+
* 4. Submit the intent to the Solver API and await it using relayTxAndWaitPacket method
|
|
176
|
+
*
|
|
120
177
|
* @param params - The parameters for the supply transaction.
|
|
121
178
|
* @param spokeProvider - The spoke provider.
|
|
122
179
|
* @param raw - Whether to return the raw transaction data.
|
|
123
|
-
* @returns
|
|
180
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MoneyMarketErrorCode>>} - Returns the transaction result.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const moneyMarketService = new MoneyMarketService(config);
|
|
184
|
+
* const result = await moneyMarketService.supply(
|
|
185
|
+
* {
|
|
186
|
+
* token: "0x123...", // token address
|
|
187
|
+
* amount: 1000000000000000000n // 1 token in wei
|
|
188
|
+
* },
|
|
189
|
+
* spokeProvider,
|
|
190
|
+
* raw // Optional: true = return the raw transaction data, false = exeute and return the transaction hash (default: false)
|
|
191
|
+
* );
|
|
192
|
+
*
|
|
193
|
+
* if (result.ok) {
|
|
194
|
+
* const txHash = result.value;
|
|
195
|
+
* console.log('Supply transaction hash:', txHash);
|
|
196
|
+
* } else {
|
|
197
|
+
* console.error('Supply failed:', result.error);
|
|
198
|
+
* }
|
|
124
199
|
*/
|
|
125
200
|
async supply(params, spokeProvider, raw) {
|
|
126
201
|
try {
|
|
127
202
|
invariant(params.token.length > 0, 'Token is required');
|
|
128
203
|
invariant(params.amount > 0n, 'Amount must be greater than 0');
|
|
129
204
|
invariant(isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token), `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`);
|
|
130
|
-
const
|
|
205
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
206
|
+
const hubWallet = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id, walletAddressBytes, this.hubProvider);
|
|
131
207
|
const data = this.supplyData(params.token, hubWallet, params.amount, spokeProvider.chainConfig.chain.id);
|
|
208
|
+
const walletAddress = (await spokeProvider.walletProvider.getWalletAddress());
|
|
132
209
|
const txResult = await SpokeService.deposit({
|
|
133
|
-
from:
|
|
210
|
+
from: walletAddress,
|
|
134
211
|
to: hubWallet,
|
|
135
212
|
token: params.token,
|
|
136
213
|
amount: params.amount,
|
|
@@ -152,11 +229,31 @@ export class MoneyMarketService {
|
|
|
152
229
|
}
|
|
153
230
|
}
|
|
154
231
|
/**
|
|
155
|
-
* Borrow tokens from the money market pool and submit the intent to the Solver API
|
|
232
|
+
* Borrow tokens from the money market pool, relay the transaction to the hub and submit the intent to the Solver API
|
|
156
233
|
* @param params - The parameters for the borrow transaction.
|
|
157
234
|
* @param spokeProvider - The spoke provider.
|
|
158
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is
|
|
159
|
-
* @returns [
|
|
235
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
236
|
+
* @returns {Promise<Result<[Hex, Hex], MoneyMarketError>>} - Returns the transaction result and the hub transaction hash or error
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* const result = await moneyMarketService.borrowAndSubmit(
|
|
240
|
+
* {
|
|
241
|
+
* token: '0x...', // Address of the token (spoke chain address) to borrow
|
|
242
|
+
* amount: 1000n, // Amount to borrow (in token decimals)
|
|
243
|
+
* },
|
|
244
|
+
* spokeProvider,
|
|
245
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
246
|
+
* );
|
|
247
|
+
*
|
|
248
|
+
* if (!result.ok) {
|
|
249
|
+
* // Handle error
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* const [
|
|
253
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
254
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
255
|
+
* ] = result.value;
|
|
256
|
+
* console.log('Borrow transaction hashes:', { spokeTxHash, hubTxHash });
|
|
160
257
|
*/
|
|
161
258
|
async borrowAndSubmit(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
162
259
|
try {
|
|
@@ -187,28 +284,72 @@ export class MoneyMarketService {
|
|
|
187
284
|
}
|
|
188
285
|
}
|
|
189
286
|
/**
|
|
190
|
-
* Borrow tokens from the money market pool
|
|
191
|
-
* NOTE: This method does not submit the intent to the Solver API
|
|
287
|
+
* Borrow tokens from the money market pool without submitting the intent to the Solver API
|
|
288
|
+
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
289
|
+
* In order to successfully borrow tokens, you need to:
|
|
290
|
+
* 1. Execute the borrow transaction on the spoke chain
|
|
291
|
+
* 2. Submit the intent to the Solver API and await it using relayTxAndWaitPacket method
|
|
292
|
+
*
|
|
192
293
|
* @param params - The parameters for the borrow transaction.
|
|
193
294
|
* @param spokeProvider - The spoke provider.
|
|
194
295
|
* @param raw - Whether to return the raw transaction data.
|
|
195
|
-
* @returns
|
|
296
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MoneyMarketErrorCode>>} - Returns the transaction result (raw transaction data or transaction hash).
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* const moneyMarketService = new MoneyMarketService(config);
|
|
300
|
+
* const result = await moneyMarketService.borrow(
|
|
301
|
+
* {
|
|
302
|
+
* token: "0x123...", // token address
|
|
303
|
+
* amount: 1000000000000000000n // 1 token in wei
|
|
304
|
+
* },
|
|
305
|
+
* spokeProvider,
|
|
306
|
+
* raw // Optional: true = return the raw transaction data, false = exeute and return the transaction hash (default: false)
|
|
307
|
+
* );
|
|
308
|
+
*
|
|
309
|
+
* if (result.ok) {
|
|
310
|
+
* const txHash = result.value;
|
|
311
|
+
* console.log('Borrow transaction hash:', txHash);
|
|
312
|
+
* } else {
|
|
313
|
+
* console.error('Borrow failed:', result.error);
|
|
314
|
+
* }
|
|
196
315
|
*/
|
|
197
316
|
async borrow(params, spokeProvider, raw) {
|
|
198
317
|
invariant(params.token.length > 0, 'Token is required');
|
|
199
318
|
invariant(params.amount > 0n, 'Amount must be greater than 0');
|
|
200
319
|
invariant(isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token), `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`);
|
|
201
|
-
const
|
|
202
|
-
const
|
|
320
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
321
|
+
const hubWallet = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id, walletAddressBytes, this.hubProvider);
|
|
322
|
+
const data = this.borrowData(hubWallet, walletAddressBytes, params.token, params.amount, spokeProvider.chainConfig.chain.id);
|
|
203
323
|
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
204
324
|
return { ok: true, value: txResult };
|
|
205
325
|
}
|
|
206
326
|
/**
|
|
207
|
-
* Withdraw tokens from the money market pool and submit the intent to the Solver API
|
|
327
|
+
* Withdraw tokens from the money market pool, relay the transaction to the hub and submit the intent to the Solver API
|
|
328
|
+
*
|
|
208
329
|
* @param params - The parameters for the withdraw transaction.
|
|
209
330
|
* @param spokeProvider - The spoke provider.
|
|
210
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is
|
|
211
|
-
* @returns [
|
|
331
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
332
|
+
* @returns {Promise<Result<[Hex, Hex], MoneyMarketError>>} - Returns the transaction result and the hub transaction hash or error
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* const result = await moneyMarketService.withdrawAndSubmit(
|
|
336
|
+
* {
|
|
337
|
+
* token: '0x...', // Address of the token (spoke chain address) to withdraw
|
|
338
|
+
* amount: 1000n, // Amount to withdraw (in token decimals)
|
|
339
|
+
* },
|
|
340
|
+
* spokeProvider,
|
|
341
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
342
|
+
* );
|
|
343
|
+
*
|
|
344
|
+
* if (!result.ok) {
|
|
345
|
+
* // Handle error
|
|
346
|
+
* }
|
|
347
|
+
*
|
|
348
|
+
* const [
|
|
349
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
350
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
351
|
+
* ] = result.value;
|
|
352
|
+
* console.log('Withdraw transaction hashes:', { spokeTxHash, hubTxHash });
|
|
212
353
|
*/
|
|
213
354
|
async withdrawAndSubmit(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
214
355
|
try {
|
|
@@ -239,28 +380,72 @@ export class MoneyMarketService {
|
|
|
239
380
|
}
|
|
240
381
|
}
|
|
241
382
|
/**
|
|
242
|
-
* Withdraw tokens from the money market pool
|
|
243
|
-
* NOTE: This method does not submit the intent to the Solver API
|
|
383
|
+
* Withdraw tokens from the money market pool without submitting the intent to the Solver API
|
|
384
|
+
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
385
|
+
* In order to successfully withdraw tokens, you need to:
|
|
386
|
+
* 1. Execute the withdraw transaction on the spoke chain
|
|
387
|
+
* 2. Submit the intent to the Solver API and await it using relayTxAndWaitPacket method
|
|
388
|
+
*
|
|
244
389
|
* @param params - The parameters for the withdraw transaction.
|
|
245
390
|
* @param spokeProvider - The spoke provider.
|
|
246
391
|
* @param raw - Whether to return the raw transaction data.
|
|
247
|
-
* @returns
|
|
392
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MoneyMarketErrorCode>>} - Returns the transaction result (raw transaction data or transaction hash).
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* const moneyMarketService = new MoneyMarketService(config);
|
|
396
|
+
* const result = await moneyMarketService.withdraw(
|
|
397
|
+
* {
|
|
398
|
+
* token: "0x123...", // token address
|
|
399
|
+
* amount: 1000000000000000000n // 1 token in wei
|
|
400
|
+
* },
|
|
401
|
+
* spokeProvider,
|
|
402
|
+
* raw // Optional: true = return the raw transaction data, false = exeute and return the transaction hash (default: false)
|
|
403
|
+
* );
|
|
404
|
+
*
|
|
405
|
+
* if (result.ok) {
|
|
406
|
+
* const txHash = result.value;
|
|
407
|
+
* console.log('Withdraw transaction hash:', txHash);
|
|
408
|
+
* } else {
|
|
409
|
+
* console.error('Withdraw failed:', result.error);
|
|
410
|
+
* }
|
|
248
411
|
*/
|
|
249
412
|
async withdraw(params, spokeProvider, raw) {
|
|
250
413
|
invariant(params.token.length > 0, 'Token is required');
|
|
251
414
|
invariant(params.amount > 0n, 'Amount must be greater than 0');
|
|
252
415
|
invariant(isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token), `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`);
|
|
253
|
-
const
|
|
254
|
-
const
|
|
416
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
417
|
+
const hubWallet = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id, walletAddressBytes, this.hubProvider);
|
|
418
|
+
const data = this.withdrawData(hubWallet, walletAddressBytes, params.token, params.amount, spokeProvider.chainConfig.chain.id);
|
|
255
419
|
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
256
420
|
return { ok: true, value: txResult };
|
|
257
421
|
}
|
|
258
422
|
/**
|
|
259
|
-
* Repay tokens to the money market pool and submit the intent to the Solver API
|
|
423
|
+
* Repay tokens to the money market pool, relay the transaction to the hub and submit the intent to the Solver API
|
|
424
|
+
*
|
|
260
425
|
* @param params - The parameters for the repay transaction.
|
|
261
426
|
* @param spokeProvider - The spoke provider.
|
|
262
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is
|
|
263
|
-
* @returns [
|
|
427
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
428
|
+
* @returns {Promise<Result<[Hex, Hex], MoneyMarketError>>} - Returns the transaction result and the hub transaction hash or error
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* const result = await moneyMarketService.repayAndSubmit(
|
|
432
|
+
* {
|
|
433
|
+
* token: '0x...', // Address of the token (spoke chain address) to repay
|
|
434
|
+
* amount: 1000n, // Amount to repay (in token decimals)
|
|
435
|
+
* },
|
|
436
|
+
* spokeProvider,
|
|
437
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
438
|
+
* );
|
|
439
|
+
*
|
|
440
|
+
* if (!result.ok) {
|
|
441
|
+
* // Handle error
|
|
442
|
+
* }
|
|
443
|
+
*
|
|
444
|
+
* const [
|
|
445
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
446
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
447
|
+
* ] = result.value;
|
|
448
|
+
* console.log('Repay transaction hashes:', { spokeTxHash, hubTxHash });
|
|
264
449
|
*/
|
|
265
450
|
async repayAndSubmit(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
266
451
|
try {
|
|
@@ -291,21 +476,47 @@ export class MoneyMarketService {
|
|
|
291
476
|
}
|
|
292
477
|
}
|
|
293
478
|
/**
|
|
294
|
-
* Repay tokens to the money market pool
|
|
295
|
-
* NOTE: This method does not submit the intent to the Solver API
|
|
479
|
+
* Repay tokens to the money market pool without submitting the intent to the Solver API
|
|
480
|
+
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
481
|
+
* In order to successfully repay tokens, you need to:
|
|
482
|
+
* 1. Check if the allowance is sufficient
|
|
483
|
+
* 2. Approve the asset manager contract to spend the tokens
|
|
484
|
+
* 3. Execute the repay transaction on the spoke chain
|
|
485
|
+
* 4. Submit the intent to the Solver API and await it using relayTxAndWaitPacket method
|
|
486
|
+
*
|
|
296
487
|
* @param params - The parameters for the repay transaction.
|
|
297
488
|
* @param spokeProvider - The spoke provider.
|
|
298
489
|
* @param raw - Whether to return the raw transaction data.
|
|
299
|
-
* @returns The transaction result (raw transaction data or transaction hash).
|
|
490
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MoneyMarketErrorCode>>} The transaction result (raw transaction data or transaction hash) or error.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* const moneyMarketService = new MoneyMarketService(config);
|
|
494
|
+
* const result = await moneyMarketService.repay(
|
|
495
|
+
* {
|
|
496
|
+
* token: "0x123...", // token address
|
|
497
|
+
* amount: 1000000000000000000n // 1 token in wei
|
|
498
|
+
* },
|
|
499
|
+
* spokeProvider,
|
|
500
|
+
* raw // Optional: true = return the raw transaction data, false = exeute and return the transaction hash (default: false)
|
|
501
|
+
* );
|
|
502
|
+
*
|
|
503
|
+
* if (result.ok) {
|
|
504
|
+
* const txHash = result.value;
|
|
505
|
+
* console.log('Repay transaction hash:', txHash);
|
|
506
|
+
* } else {
|
|
507
|
+
* console.error('Repay failed:', result.error);
|
|
508
|
+
* }
|
|
300
509
|
*/
|
|
301
510
|
async repay(params, spokeProvider, raw) {
|
|
302
511
|
invariant(params.token.length > 0, 'Token is required');
|
|
303
512
|
invariant(params.amount > 0n, 'Amount must be greater than 0');
|
|
304
513
|
invariant(isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token), `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`);
|
|
305
|
-
const
|
|
514
|
+
const walletAddressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
515
|
+
const hubWallet = await EvmWalletAbstraction.getUserHubWalletAddress(spokeProvider.chainConfig.chain.id, walletAddressBytes, this.hubProvider);
|
|
306
516
|
const data = this.repayData(params.token, hubWallet, params.amount, spokeProvider.chainConfig.chain.id);
|
|
517
|
+
const walletAddress = (await spokeProvider.walletProvider.getWalletAddress());
|
|
307
518
|
const txResult = await SpokeService.deposit({
|
|
308
|
-
from:
|
|
519
|
+
from: walletAddress,
|
|
309
520
|
to: hubWallet,
|
|
310
521
|
token: params.token,
|
|
311
522
|
amount: params.amount,
|
|
@@ -314,12 +525,12 @@ export class MoneyMarketService {
|
|
|
314
525
|
return { ok: true, value: txResult };
|
|
315
526
|
}
|
|
316
527
|
/**
|
|
317
|
-
*
|
|
528
|
+
* Build transaction data for supplying to the money market pool
|
|
318
529
|
* @param token - The address of the token on spoke chain
|
|
319
|
-
* @param to The user wallet address on the hub chain
|
|
320
|
-
* @param amount The amount to deposit
|
|
321
|
-
* @param spokeChainId The chain ID of the spoke chain
|
|
322
|
-
* @returns The transaction
|
|
530
|
+
* @param to - The user wallet address on the hub chain
|
|
531
|
+
* @param amount - The amount to deposit
|
|
532
|
+
* @param spokeChainId - The chain ID of the spoke chain
|
|
533
|
+
* @returns {Hex} The transaction data.
|
|
323
534
|
*/
|
|
324
535
|
supplyData(token, to, amount, spokeChainId) {
|
|
325
536
|
const calls = [];
|
|
@@ -336,13 +547,13 @@ export class MoneyMarketService {
|
|
|
336
547
|
return encodeContractCalls(calls);
|
|
337
548
|
}
|
|
338
549
|
/**
|
|
339
|
-
*
|
|
340
|
-
* @param from The user wallet address on the hub chain
|
|
341
|
-
* @param to The user wallet address on the spoke chain
|
|
342
|
-
* @param token The address of the token to borrow
|
|
343
|
-
* @param amount The amount to borrow in hub chain decimals
|
|
344
|
-
* @param spokeChainId The chain ID of the spoke chain
|
|
345
|
-
* @returns
|
|
550
|
+
* Build transaction data for borrowing from the money market pool
|
|
551
|
+
* @param from - The user wallet address on the hub chain
|
|
552
|
+
* @param to - The user wallet address on the spoke chain
|
|
553
|
+
* @param token - The address of the token to borrow
|
|
554
|
+
* @param amount - The amount to borrow in hub chain decimals
|
|
555
|
+
* @param spokeChainId - The chain ID of the spoke chain
|
|
556
|
+
* @returns {Hex} The transaction data.
|
|
346
557
|
*/
|
|
347
558
|
borrowData(from, to, token, amount, spokeChainId) {
|
|
348
559
|
invariant(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
|
|
@@ -375,13 +586,13 @@ export class MoneyMarketService {
|
|
|
375
586
|
return encodeContractCalls(calls);
|
|
376
587
|
}
|
|
377
588
|
/**
|
|
378
|
-
*
|
|
379
|
-
* @param from The user wallet address on the hub chain
|
|
380
|
-
* @param to The user wallet address on the spoke chain
|
|
381
|
-
* @param token The address of the token to borrow
|
|
382
|
-
* @param amount The amount to borrow in hub chain decimals
|
|
383
|
-
* @param spokeChainId The chain ID of the spoke chain
|
|
384
|
-
* @returns
|
|
589
|
+
* Build transaction data for withdrawing from the money market pool
|
|
590
|
+
* @param from - The user wallet address on the hub chain
|
|
591
|
+
* @param to - The user wallet address on the spoke chain
|
|
592
|
+
* @param token - The address of the token to borrow
|
|
593
|
+
* @param amount - The amount to borrow in hub chain decimals
|
|
594
|
+
* @param spokeChainId - The chain ID of the spoke chain
|
|
595
|
+
* @returns {Hex} The transaction data.
|
|
385
596
|
*/
|
|
386
597
|
withdrawData(from, to, token, amount, spokeChainId) {
|
|
387
598
|
const calls = [];
|
|
@@ -401,13 +612,12 @@ export class MoneyMarketService {
|
|
|
401
612
|
return encodeContractCalls(calls);
|
|
402
613
|
}
|
|
403
614
|
/**
|
|
404
|
-
*
|
|
405
|
-
* @param token The address of the token to repay
|
|
406
|
-
* @param to The user wallet address on the hub chain
|
|
407
|
-
* @param amount The amount to repay
|
|
408
|
-
* @param spokeChainId The chain ID of the spoke chain
|
|
409
|
-
* @
|
|
410
|
-
* @returns Transaction object
|
|
615
|
+
* Build transaction data for repaying to the money market pool
|
|
616
|
+
* @param token - The address of the token to repay
|
|
617
|
+
* @param to - The user wallet address on the hub chain
|
|
618
|
+
* @param amount - The amount to repay
|
|
619
|
+
* @param spokeChainId - The chain ID of the spoke chain
|
|
620
|
+
* @returns {Hex} The transaction data.
|
|
411
621
|
*/
|
|
412
622
|
repayData(token, to, amount, spokeChainId) {
|
|
413
623
|
const calls = [];
|
|
@@ -435,7 +645,7 @@ export class MoneyMarketService {
|
|
|
435
645
|
* Get the list of all reserves in the pool
|
|
436
646
|
* @param uiPoolDataProvider - The address of the UI Pool Data Provider
|
|
437
647
|
* @param poolAddressesProvider - The address of the Pool Addresses Provider
|
|
438
|
-
* @returns Array of reserve addresses
|
|
648
|
+
* @returns {Promise<readonly Address[]>} - Array of reserve addresses
|
|
439
649
|
*/
|
|
440
650
|
async getReservesList(uiPoolDataProvider, poolAddressesProvider) {
|
|
441
651
|
return this.hubProvider.publicClient.readContract({
|
|
@@ -449,7 +659,7 @@ export class MoneyMarketService {
|
|
|
449
659
|
* Get detailed data for all reserves in the pool
|
|
450
660
|
* @param uiPoolDataProvider - The address of the UI Pool Data Provider
|
|
451
661
|
* @param poolAddressesProvider - The address of the Pool Addresses Provider
|
|
452
|
-
* @returns Tuple containing array of reserve data and base currency info
|
|
662
|
+
* @returns {Promise<readonly [readonly AggregatedReserveData[], BaseCurrencyInfo]>} - Tuple containing array of reserve data and base currency info
|
|
453
663
|
*/
|
|
454
664
|
async getReservesData(uiPoolDataProvider, poolAddressesProvider) {
|
|
455
665
|
return this.hubProvider.publicClient.readContract({
|
|
@@ -464,7 +674,7 @@ export class MoneyMarketService {
|
|
|
464
674
|
* @param userAddress Address of the user
|
|
465
675
|
* @param uiPoolDataProvider - The address of the UI Pool Data Provider
|
|
466
676
|
* @param poolAddressesProvider - The address of the Pool Addresses Provider
|
|
467
|
-
* @returns Tuple containing array of user reserve data and eMode category ID
|
|
677
|
+
* @returns {Promise<readonly [readonly UserReserveData[], number]>} - Tuple containing array of user reserve data and eMode category ID
|
|
468
678
|
*/
|
|
469
679
|
async getUserReservesData(userAddress, uiPoolDataProvider, poolAddressesProvider) {
|
|
470
680
|
return this.hubProvider.publicClient.readContract({
|
|
@@ -587,7 +797,7 @@ export class MoneyMarketService {
|
|
|
587
797
|
/**
|
|
588
798
|
* Get the list of all supported money market tokens (supply / borrow tokens) for a given spoke chain ID
|
|
589
799
|
* @param chainId The chain ID
|
|
590
|
-
* @returns Array of supported tokens
|
|
800
|
+
* @returns {readonly Token[]} - Array of supported tokens
|
|
591
801
|
*/
|
|
592
802
|
getSupportedTokens(chainId) {
|
|
593
803
|
return getSupportedMoneyMarketTokens(chainId);
|
|
@@ -595,7 +805,7 @@ export class MoneyMarketService {
|
|
|
595
805
|
/**
|
|
596
806
|
* Get the list of all supported money market reserves (supply / borrow reserves)
|
|
597
807
|
* NOTE: reserve addresses are on the hub chain and can be of type vault, erc20, etc.
|
|
598
|
-
* @returns Array of supported reserves
|
|
808
|
+
* @returns {readonly Address[]} - Array of supported reserves
|
|
599
809
|
*/
|
|
600
810
|
getSupportedReserves() {
|
|
601
811
|
return [...moneyMarketReserveAssets];
|