@usdctofiat/offramp 1.1.3 → 1.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/README.md +1 -1
- package/dist/{chunk-QELK2M73.js → chunk-OJY6DE3I.js} +197 -139
- package/dist/chunk-OJY6DE3I.js.map +1 -0
- package/dist/index.cjs +103 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +30 -44
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-QELK2M73.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,35 +15,30 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var index_exports = {};
|
|
32
22
|
__export(index_exports, {
|
|
33
23
|
CURRENCIES: () => CURRENCIES,
|
|
24
|
+
ESCROW_ADDRESS: () => ESCROW_ADDRESS,
|
|
34
25
|
OfframpError: () => OfframpError,
|
|
35
26
|
PLATFORMS: () => PLATFORMS,
|
|
36
27
|
close: () => close,
|
|
28
|
+
delegate: () => delegate,
|
|
37
29
|
deposits: () => deposits,
|
|
38
30
|
disableOtc: () => disableOtc,
|
|
39
31
|
enableOtc: () => enableOtc,
|
|
40
32
|
getOtcLink: () => getOtcLink,
|
|
41
|
-
offramp: () => offramp
|
|
33
|
+
offramp: () => offramp,
|
|
34
|
+
undelegate: () => undelegate
|
|
42
35
|
});
|
|
43
36
|
module.exports = __toCommonJS(index_exports);
|
|
44
37
|
|
|
45
38
|
// src/deposit.ts
|
|
46
39
|
var import_viem3 = require("viem");
|
|
47
|
-
var
|
|
48
|
-
var
|
|
40
|
+
var import_chains3 = require("viem/chains");
|
|
41
|
+
var import_sdk5 = require("@zkp2p/sdk");
|
|
49
42
|
|
|
50
43
|
// src/config.ts
|
|
51
44
|
var import_sdk = require("@zkp2p/sdk");
|
|
@@ -387,6 +380,7 @@ function isUserCancellation(error) {
|
|
|
387
380
|
|
|
388
381
|
// src/otc.ts
|
|
389
382
|
var import_viem = require("viem");
|
|
383
|
+
var import_chains = require("viem/chains");
|
|
390
384
|
|
|
391
385
|
// ../../node_modules/@zkp2p/contracts-v2/abis/base/WhitelistPreIntentHook.json
|
|
392
386
|
var WhitelistPreIntentHook_default = [
|
|
@@ -731,6 +725,18 @@ var WhitelistPreIntentHook_default = [
|
|
|
731
725
|
}
|
|
732
726
|
];
|
|
733
727
|
|
|
728
|
+
// src/sdk-client.ts
|
|
729
|
+
var import_sdk3 = require("@zkp2p/sdk");
|
|
730
|
+
function createSdkClient(walletClient) {
|
|
731
|
+
return new import_sdk3.OfframpClient({
|
|
732
|
+
walletClient,
|
|
733
|
+
chainId: BASE_CHAIN_ID,
|
|
734
|
+
runtimeEnv: RUNTIME_ENV,
|
|
735
|
+
rpcUrl: BASE_RPC_URL,
|
|
736
|
+
baseApiUrl: API_BASE_URL
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
|
|
734
740
|
// src/otc.ts
|
|
735
741
|
var WHITELIST_HOOK_ADDRESS = "0xda023Ea0d789A41BcF5866F7B6BBd2CaDF9b79B8";
|
|
736
742
|
var OTC_BASE_URL = "https://usdctofiat.xyz";
|
|
@@ -748,12 +754,7 @@ async function enableOtc(walletClient, depositId, takerAddress, escrowAddress) {
|
|
|
748
754
|
escrowAddress: escrow
|
|
749
755
|
});
|
|
750
756
|
if (currentHook !== import_viem.zeroAddress) {
|
|
751
|
-
const isAlready = await readIsWhitelisted(
|
|
752
|
-
walletClient,
|
|
753
|
-
escrow,
|
|
754
|
-
depositIdBig,
|
|
755
|
-
taker
|
|
756
|
-
);
|
|
757
|
+
const isAlready = await readIsWhitelisted(escrow, depositIdBig, taker);
|
|
757
758
|
if (isAlready) {
|
|
758
759
|
return {
|
|
759
760
|
depositId,
|
|
@@ -824,13 +825,8 @@ async function writeContract(walletClient, functionName, args) {
|
|
|
824
825
|
args
|
|
825
826
|
});
|
|
826
827
|
}
|
|
827
|
-
async function readIsWhitelisted(
|
|
828
|
-
const {
|
|
829
|
-
const { base: base2 } = await import("viem/chains");
|
|
830
|
-
const publicClient = createPublicClient2({
|
|
831
|
-
chain: base2,
|
|
832
|
-
transport: http2("https://mainnet.base.org")
|
|
833
|
-
});
|
|
828
|
+
async function readIsWhitelisted(escrow, depositId, taker) {
|
|
829
|
+
const publicClient = (0, import_viem.createPublicClient)({ chain: import_chains.base, transport: (0, import_viem.http)(BASE_RPC_URL) });
|
|
834
830
|
return publicClient.readContract({
|
|
835
831
|
address: WHITELIST_HOOK_ADDRESS,
|
|
836
832
|
abi: WhitelistPreIntentHook_default,
|
|
@@ -841,13 +837,14 @@ async function readIsWhitelisted(walletClient, escrow, depositId, taker) {
|
|
|
841
837
|
|
|
842
838
|
// src/queries.ts
|
|
843
839
|
var import_viem2 = require("viem");
|
|
844
|
-
var
|
|
840
|
+
var import_chains2 = require("viem/chains");
|
|
841
|
+
var import_sdk4 = require("@zkp2p/sdk");
|
|
845
842
|
var indexerService = null;
|
|
846
843
|
function getIndexerService() {
|
|
847
844
|
if (!indexerService) {
|
|
848
|
-
const endpoint = (0,
|
|
849
|
-
const client = new
|
|
850
|
-
indexerService = new
|
|
845
|
+
const endpoint = (0, import_sdk4.defaultIndexerEndpoint)("PRODUCTION");
|
|
846
|
+
const client = new import_sdk4.IndexerClient(endpoint);
|
|
847
|
+
indexerService = new import_sdk4.IndexerDepositService(client);
|
|
851
848
|
}
|
|
852
849
|
return indexerService;
|
|
853
850
|
}
|
|
@@ -881,7 +878,7 @@ function resolveMethodNames(hashes) {
|
|
|
881
878
|
return Array.from(names);
|
|
882
879
|
}
|
|
883
880
|
function mapDeposit(d) {
|
|
884
|
-
const delegationState = (0,
|
|
881
|
+
const delegationState = (0, import_sdk4.classifyDelegationState)(
|
|
885
882
|
d.rateManagerId ?? void 0,
|
|
886
883
|
d.rateManagerAddress ?? void 0,
|
|
887
884
|
DELEGATE_RATE_MANAGER_ID,
|
|
@@ -898,7 +895,7 @@ function mapDeposit(d) {
|
|
|
898
895
|
fulfilledIntents: d.fulfilledIntents ?? 0,
|
|
899
896
|
paymentMethods: resolveMethodNames(d.paymentMethods),
|
|
900
897
|
currencies: d.currencies.map((c) => {
|
|
901
|
-
const info = (0,
|
|
898
|
+
const info = (0, import_sdk4.getCurrencyInfoFromHash)(c.currencyCode);
|
|
902
899
|
return info?.currencyCode ?? c.currencyCode;
|
|
903
900
|
}),
|
|
904
901
|
rateSource: d.currencies[0]?.rateSource || "unknown",
|
|
@@ -914,6 +911,18 @@ function extractTxHash(result) {
|
|
|
914
911
|
return result.transactionHash;
|
|
915
912
|
throw new Error("Unexpected transaction result format");
|
|
916
913
|
}
|
|
914
|
+
var ESCROW_V2_ABI = [
|
|
915
|
+
{
|
|
916
|
+
name: "clearRateManager",
|
|
917
|
+
type: "function",
|
|
918
|
+
stateMutability: "nonpayable",
|
|
919
|
+
inputs: [{ name: "depositId", type: "uint256" }],
|
|
920
|
+
outputs: []
|
|
921
|
+
}
|
|
922
|
+
];
|
|
923
|
+
function appendReferrerAttribution(calldata) {
|
|
924
|
+
return (0, import_viem2.concatHex)([calldata, (0, import_sdk4.getAttributionDataSuffix)([REFERRER])]);
|
|
925
|
+
}
|
|
917
926
|
async function deposits(walletAddress) {
|
|
918
927
|
const service = getIndexerService();
|
|
919
928
|
const raw = await service.fetchDepositsWithRelations(
|
|
@@ -936,6 +945,57 @@ async function close(walletClient, depositId, escrowAddress) {
|
|
|
936
945
|
});
|
|
937
946
|
return extractTxHash(result);
|
|
938
947
|
}
|
|
948
|
+
async function delegate(walletClient, depositId, escrowAddress) {
|
|
949
|
+
const client = createSdkClient(walletClient);
|
|
950
|
+
const result = await client.setRateManager({
|
|
951
|
+
depositId: BigInt(depositId),
|
|
952
|
+
rateManagerAddress: RATE_MANAGER_REGISTRY_ADDRESS,
|
|
953
|
+
rateManagerId: DELEGATE_RATE_MANAGER_ID,
|
|
954
|
+
escrowAddress: escrowAddress || ESCROW_ADDRESS,
|
|
955
|
+
txOverrides: { referrer: [REFERRER] }
|
|
956
|
+
});
|
|
957
|
+
return extractTxHash(result);
|
|
958
|
+
}
|
|
959
|
+
async function undelegate(walletClient, depositId, escrowAddress) {
|
|
960
|
+
const account = walletClient.account;
|
|
961
|
+
if (!account) {
|
|
962
|
+
throw new Error("Wallet client has no account. Connect a wallet first.");
|
|
963
|
+
}
|
|
964
|
+
const data = appendReferrerAttribution(
|
|
965
|
+
(0, import_viem2.encodeFunctionData)({
|
|
966
|
+
abi: ESCROW_V2_ABI,
|
|
967
|
+
functionName: "clearRateManager",
|
|
968
|
+
args: [BigInt(depositId)]
|
|
969
|
+
})
|
|
970
|
+
);
|
|
971
|
+
const hash = await walletClient.sendTransaction({
|
|
972
|
+
account,
|
|
973
|
+
chain: import_chains2.base,
|
|
974
|
+
data,
|
|
975
|
+
to: escrowAddress || ESCROW_ADDRESS
|
|
976
|
+
});
|
|
977
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
978
|
+
chain: import_chains2.base,
|
|
979
|
+
transport: (0, import_viem2.http)(BASE_RPC_URL)
|
|
980
|
+
});
|
|
981
|
+
try {
|
|
982
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
983
|
+
hash,
|
|
984
|
+
confirmations: 1,
|
|
985
|
+
timeout: 12e4,
|
|
986
|
+
pollingInterval: 4e3
|
|
987
|
+
});
|
|
988
|
+
if (receipt.status !== "success") {
|
|
989
|
+
throw new Error("Undelegation transaction failed");
|
|
990
|
+
}
|
|
991
|
+
} catch (err) {
|
|
992
|
+
const isTimeout = err instanceof Error && err.message.toLowerCase().includes("timed out");
|
|
993
|
+
if (!isTimeout) {
|
|
994
|
+
throw err;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return hash;
|
|
998
|
+
}
|
|
939
999
|
|
|
940
1000
|
// src/deposit.ts
|
|
941
1001
|
function usdcToUnits(amount) {
|
|
@@ -1010,7 +1070,7 @@ function attachOracleConfig(entries, conversionRates) {
|
|
|
1010
1070
|
(group, gi) => group.map((entry, ci) => {
|
|
1011
1071
|
const currency = conversionRates[gi]?.[ci]?.currency;
|
|
1012
1072
|
if (!currency) return entry;
|
|
1013
|
-
const oracleConfig = (0,
|
|
1073
|
+
const oracleConfig = (0, import_sdk5.getSpreadOracleConfig)(currency);
|
|
1014
1074
|
if (!oracleConfig) return entry;
|
|
1015
1075
|
return {
|
|
1016
1076
|
...entry,
|
|
@@ -1032,15 +1092,6 @@ function extractTxHash2(result) {
|
|
|
1032
1092
|
return result.transactionHash;
|
|
1033
1093
|
throw new Error("Unexpected transaction result format");
|
|
1034
1094
|
}
|
|
1035
|
-
function createSdkClient(walletClient) {
|
|
1036
|
-
return new import_sdk4.OfframpClient({
|
|
1037
|
-
walletClient,
|
|
1038
|
-
chainId: BASE_CHAIN_ID,
|
|
1039
|
-
runtimeEnv: RUNTIME_ENV,
|
|
1040
|
-
rpcUrl: BASE_RPC_URL,
|
|
1041
|
-
baseApiUrl: API_BASE_URL
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
1095
|
async function findUndelegatedDeposit(walletAddress) {
|
|
1045
1096
|
try {
|
|
1046
1097
|
const service = getIndexerService();
|
|
@@ -1049,6 +1100,7 @@ async function findUndelegatedDeposit(walletAddress) {
|
|
|
1049
1100
|
{ limit: 50 }
|
|
1050
1101
|
);
|
|
1051
1102
|
const escrowLower = ESCROW_ADDRESS.toLowerCase();
|
|
1103
|
+
const delegateIdLower = DELEGATE_RATE_MANAGER_ID.toLowerCase();
|
|
1052
1104
|
const undelegated = (raw || []).filter((d) => {
|
|
1053
1105
|
if (d.status === "CLOSED") return false;
|
|
1054
1106
|
if (d.escrowAddress.toLowerCase() !== escrowLower) return false;
|
|
@@ -1060,7 +1112,7 @@ async function findUndelegatedDeposit(walletAddress) {
|
|
|
1060
1112
|
}
|
|
1061
1113
|
})();
|
|
1062
1114
|
if (remaining === 0n) return false;
|
|
1063
|
-
return d.rateManagerId !==
|
|
1115
|
+
return (d.rateManagerId ?? "").toLowerCase() !== delegateIdLower;
|
|
1064
1116
|
});
|
|
1065
1117
|
undelegated.sort((a, b) => Number(BigInt(b.depositId) - BigInt(a.depositId)));
|
|
1066
1118
|
return undelegated[0] ?? null;
|
|
@@ -1125,7 +1177,7 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1125
1177
|
const minUnits = usdcToUnits(String(MIN_ORDER_USDC));
|
|
1126
1178
|
const maxUnits = usdcToUnits(String(Math.min(amt, 2500)));
|
|
1127
1179
|
try {
|
|
1128
|
-
const publicClient = (0, import_viem3.createPublicClient)({ chain:
|
|
1180
|
+
const publicClient = (0, import_viem3.createPublicClient)({ chain: import_chains3.base, transport: (0, import_viem3.http)(BASE_RPC_URL) });
|
|
1129
1181
|
const balance = await publicClient.readContract({
|
|
1130
1182
|
address: USDC_ADDRESS,
|
|
1131
1183
|
abi: [
|
|
@@ -1180,7 +1232,7 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1180
1232
|
const conversionRates = [
|
|
1181
1233
|
[{ currency: currencyCode, conversionRate: "1" }]
|
|
1182
1234
|
];
|
|
1183
|
-
const baseCurrenciesOverride = (0,
|
|
1235
|
+
const baseCurrenciesOverride = (0, import_sdk5.mapConversionRatesToOnchainMinRate)(conversionRates, 1);
|
|
1184
1236
|
const currenciesOverride = attachOracleConfig(baseCurrenciesOverride, conversionRates);
|
|
1185
1237
|
let hash;
|
|
1186
1238
|
try {
|
|
@@ -1315,11 +1367,11 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1315
1367
|
}
|
|
1316
1368
|
|
|
1317
1369
|
// src/currencies.ts
|
|
1318
|
-
var
|
|
1370
|
+
var import_sdk6 = require("@zkp2p/sdk");
|
|
1319
1371
|
function buildCurrencies() {
|
|
1320
1372
|
const entries = {};
|
|
1321
1373
|
for (const [code, info] of Object.entries(
|
|
1322
|
-
|
|
1374
|
+
import_sdk6.currencyInfo
|
|
1323
1375
|
)) {
|
|
1324
1376
|
entries[code] = {
|
|
1325
1377
|
code: info.currencyCode ?? code,
|
|
@@ -1334,13 +1386,16 @@ var CURRENCIES = buildCurrencies();
|
|
|
1334
1386
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1335
1387
|
0 && (module.exports = {
|
|
1336
1388
|
CURRENCIES,
|
|
1389
|
+
ESCROW_ADDRESS,
|
|
1337
1390
|
OfframpError,
|
|
1338
1391
|
PLATFORMS,
|
|
1339
1392
|
close,
|
|
1393
|
+
delegate,
|
|
1340
1394
|
deposits,
|
|
1341
1395
|
disableOtc,
|
|
1342
1396
|
enableOtc,
|
|
1343
1397
|
getOtcLink,
|
|
1344
|
-
offramp
|
|
1398
|
+
offramp,
|
|
1399
|
+
undelegate
|
|
1345
1400
|
});
|
|
1346
1401
|
//# sourceMappingURL=index.cjs.map
|