@riftresearch/sdk 0.1.3 → 0.1.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/dist/index.js +22 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1009,7 +1009,9 @@ function getSupportedModes(from, to) {
|
|
|
1009
1009
|
}
|
|
1010
1010
|
// src/sdk.ts
|
|
1011
1011
|
import { match as match2 } from "ts-pattern";
|
|
1012
|
-
import {
|
|
1012
|
+
import {
|
|
1013
|
+
erc20Abi
|
|
1014
|
+
} from "viem";
|
|
1013
1015
|
|
|
1014
1016
|
// src/cowswap.ts
|
|
1015
1017
|
var import_sdk_common = __toESM(require_dist(), 1);
|
|
@@ -1092,7 +1094,11 @@ function decodeSwapId(encoded) {
|
|
|
1092
1094
|
};
|
|
1093
1095
|
}
|
|
1094
1096
|
if (parts[0] === "c" && parts.length === 3) {
|
|
1095
|
-
return {
|
|
1097
|
+
return {
|
|
1098
|
+
type: "cowswap_rift",
|
|
1099
|
+
cowOrderId: parts[1],
|
|
1100
|
+
riftOrderId: parts[2]
|
|
1101
|
+
};
|
|
1096
1102
|
}
|
|
1097
1103
|
throw new Error(`Invalid swap ID format: ${encoded}`);
|
|
1098
1104
|
}
|
|
@@ -1134,7 +1140,7 @@ class RiftSdk {
|
|
|
1134
1140
|
return {
|
|
1135
1141
|
quote,
|
|
1136
1142
|
executeSwap: async () => {
|
|
1137
|
-
const refundAddress = params.refundAddress ??
|
|
1143
|
+
const refundAddress = params.refundAddress ?? this.getRefundAddress(params);
|
|
1138
1144
|
const swap = await this.riftClient.createOrder({
|
|
1139
1145
|
id: riftQuote.id,
|
|
1140
1146
|
userDestinationAddress: params.destinationAddress,
|
|
@@ -1206,7 +1212,7 @@ class RiftSdk {
|
|
|
1206
1212
|
};
|
|
1207
1213
|
}
|
|
1208
1214
|
async executeCowswapThenRift(params, riftQuote, evmChainId, cbBtcAddress, sellToken) {
|
|
1209
|
-
const refundAddress = params.refundAddress ??
|
|
1215
|
+
const refundAddress = params.refundAddress ?? this.getRefundAddress(params);
|
|
1210
1216
|
const swap = await this.riftClient.createOrder({
|
|
1211
1217
|
id: riftQuote.id,
|
|
1212
1218
|
userDestinationAddress: params.destinationAddress,
|
|
@@ -1215,7 +1221,7 @@ class RiftSdk {
|
|
|
1215
1221
|
const cowSdk = createCowSwapSdk(evmChainId, this.publicClient, this.walletClient);
|
|
1216
1222
|
const sellAmount = params.mode === "exact_input" ? params.amount : riftQuote.from.amount;
|
|
1217
1223
|
if (!isNativeToken(params.from)) {
|
|
1218
|
-
const ownerAddress =
|
|
1224
|
+
const ownerAddress = this.getAddress();
|
|
1219
1225
|
await ensureCowSwapApproval(cowSdk, sellToken, ownerAddress, sellAmount);
|
|
1220
1226
|
}
|
|
1221
1227
|
const { postOrder } = await getCowSwapQuote(cowSdk, {
|
|
@@ -1294,9 +1300,12 @@ class RiftSdk {
|
|
|
1294
1300
|
}
|
|
1295
1301
|
}
|
|
1296
1302
|
async transferErc20(tokenAddress, to, amount) {
|
|
1297
|
-
const
|
|
1303
|
+
const account = this.walletClient.account;
|
|
1304
|
+
if (!account) {
|
|
1305
|
+
throw new Error("No account configured on wallet client");
|
|
1306
|
+
}
|
|
1298
1307
|
const hash = await this.walletClient.writeContract({
|
|
1299
|
-
account
|
|
1308
|
+
account,
|
|
1300
1309
|
address: tokenAddress,
|
|
1301
1310
|
abi: erc20Abi,
|
|
1302
1311
|
functionName: "transfer",
|
|
@@ -1305,15 +1314,14 @@ class RiftSdk {
|
|
|
1305
1314
|
});
|
|
1306
1315
|
return hash;
|
|
1307
1316
|
}
|
|
1308
|
-
|
|
1309
|
-
const
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
throw new Error("No address available in wallet");
|
|
1317
|
+
getAddress() {
|
|
1318
|
+
const account = this.walletClient.account;
|
|
1319
|
+
if (!account) {
|
|
1320
|
+
throw new Error("No account configured on wallet client");
|
|
1313
1321
|
}
|
|
1314
|
-
return address;
|
|
1322
|
+
return account.address;
|
|
1315
1323
|
}
|
|
1316
|
-
|
|
1324
|
+
getRefundAddress(params) {
|
|
1317
1325
|
if (params.from.chain.kind === "BITCOIN") {
|
|
1318
1326
|
throw new Error("refundAddress is required for BTC swaps (Bitcoin refund address)");
|
|
1319
1327
|
}
|