@usdctofiat/offramp 1.1.2 → 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-2XJXFOPJ.js → chunk-OJY6DE3I.js} +214 -149
- package/dist/chunk-OJY6DE3I.js.map +1 -0
- package/dist/index.cjs +119 -57
- 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 +46 -53
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-2XJXFOPJ.js.map +0 -1
package/dist/react.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,14 +15,6 @@ 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/react.ts
|
|
@@ -39,8 +29,8 @@ var import_react = require("react");
|
|
|
39
29
|
|
|
40
30
|
// src/deposit.ts
|
|
41
31
|
var import_viem3 = require("viem");
|
|
42
|
-
var
|
|
43
|
-
var
|
|
32
|
+
var import_chains3 = require("viem/chains");
|
|
33
|
+
var import_sdk5 = require("@zkp2p/sdk");
|
|
44
34
|
|
|
45
35
|
// src/config.ts
|
|
46
36
|
var import_sdk = require("@zkp2p/sdk");
|
|
@@ -382,6 +372,7 @@ function isUserCancellation(error) {
|
|
|
382
372
|
|
|
383
373
|
// src/otc.ts
|
|
384
374
|
var import_viem = require("viem");
|
|
375
|
+
var import_chains = require("viem/chains");
|
|
385
376
|
|
|
386
377
|
// ../../node_modules/@zkp2p/contracts-v2/abis/base/WhitelistPreIntentHook.json
|
|
387
378
|
var WhitelistPreIntentHook_default = [
|
|
@@ -663,14 +654,21 @@ var WhitelistPreIntentHook_default = [
|
|
|
663
654
|
type: "uint256"
|
|
664
655
|
},
|
|
665
656
|
{
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
657
|
+
components: [
|
|
658
|
+
{
|
|
659
|
+
internalType: "address",
|
|
660
|
+
name: "recipient",
|
|
661
|
+
type: "address"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
internalType: "uint256",
|
|
665
|
+
name: "fee",
|
|
666
|
+
type: "uint256"
|
|
667
|
+
}
|
|
668
|
+
],
|
|
669
|
+
internalType: "struct IReferralFee.ReferralFee[]",
|
|
670
|
+
name: "referralFees",
|
|
671
|
+
type: "tuple[]"
|
|
674
672
|
},
|
|
675
673
|
{
|
|
676
674
|
internalType: "bytes",
|
|
@@ -719,6 +717,18 @@ var WhitelistPreIntentHook_default = [
|
|
|
719
717
|
}
|
|
720
718
|
];
|
|
721
719
|
|
|
720
|
+
// src/sdk-client.ts
|
|
721
|
+
var import_sdk3 = require("@zkp2p/sdk");
|
|
722
|
+
function createSdkClient(walletClient) {
|
|
723
|
+
return new import_sdk3.OfframpClient({
|
|
724
|
+
walletClient,
|
|
725
|
+
chainId: BASE_CHAIN_ID,
|
|
726
|
+
runtimeEnv: RUNTIME_ENV,
|
|
727
|
+
rpcUrl: BASE_RPC_URL,
|
|
728
|
+
baseApiUrl: API_BASE_URL
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
|
|
722
732
|
// src/otc.ts
|
|
723
733
|
var WHITELIST_HOOK_ADDRESS = "0xda023Ea0d789A41BcF5866F7B6BBd2CaDF9b79B8";
|
|
724
734
|
var OTC_BASE_URL = "https://usdctofiat.xyz";
|
|
@@ -736,12 +746,7 @@ async function enableOtc(walletClient, depositId, takerAddress, escrowAddress) {
|
|
|
736
746
|
escrowAddress: escrow
|
|
737
747
|
});
|
|
738
748
|
if (currentHook !== import_viem.zeroAddress) {
|
|
739
|
-
const isAlready = await readIsWhitelisted(
|
|
740
|
-
walletClient,
|
|
741
|
-
escrow,
|
|
742
|
-
depositIdBig,
|
|
743
|
-
taker
|
|
744
|
-
);
|
|
749
|
+
const isAlready = await readIsWhitelisted(escrow, depositIdBig, taker);
|
|
745
750
|
if (isAlready) {
|
|
746
751
|
return {
|
|
747
752
|
depositId,
|
|
@@ -791,13 +796,8 @@ async function writeContract(walletClient, functionName, args) {
|
|
|
791
796
|
args
|
|
792
797
|
});
|
|
793
798
|
}
|
|
794
|
-
async function readIsWhitelisted(
|
|
795
|
-
const {
|
|
796
|
-
const { base: base2 } = await import("viem/chains");
|
|
797
|
-
const publicClient = createPublicClient2({
|
|
798
|
-
chain: base2,
|
|
799
|
-
transport: http2("https://mainnet.base.org")
|
|
800
|
-
});
|
|
799
|
+
async function readIsWhitelisted(escrow, depositId, taker) {
|
|
800
|
+
const publicClient = (0, import_viem.createPublicClient)({ chain: import_chains.base, transport: (0, import_viem.http)(BASE_RPC_URL) });
|
|
801
801
|
return publicClient.readContract({
|
|
802
802
|
address: WHITELIST_HOOK_ADDRESS,
|
|
803
803
|
abi: WhitelistPreIntentHook_default,
|
|
@@ -808,13 +808,14 @@ async function readIsWhitelisted(walletClient, escrow, depositId, taker) {
|
|
|
808
808
|
|
|
809
809
|
// src/queries.ts
|
|
810
810
|
var import_viem2 = require("viem");
|
|
811
|
-
var
|
|
811
|
+
var import_chains2 = require("viem/chains");
|
|
812
|
+
var import_sdk4 = require("@zkp2p/sdk");
|
|
812
813
|
var indexerService = null;
|
|
813
814
|
function getIndexerService() {
|
|
814
815
|
if (!indexerService) {
|
|
815
|
-
const endpoint = (0,
|
|
816
|
-
const client = new
|
|
817
|
-
indexerService = new
|
|
816
|
+
const endpoint = (0, import_sdk4.defaultIndexerEndpoint)("PRODUCTION");
|
|
817
|
+
const client = new import_sdk4.IndexerClient(endpoint);
|
|
818
|
+
indexerService = new import_sdk4.IndexerDepositService(client);
|
|
818
819
|
}
|
|
819
820
|
return indexerService;
|
|
820
821
|
}
|
|
@@ -848,7 +849,7 @@ function resolveMethodNames(hashes) {
|
|
|
848
849
|
return Array.from(names);
|
|
849
850
|
}
|
|
850
851
|
function mapDeposit(d) {
|
|
851
|
-
const delegationState = (0,
|
|
852
|
+
const delegationState = (0, import_sdk4.classifyDelegationState)(
|
|
852
853
|
d.rateManagerId ?? void 0,
|
|
853
854
|
d.rateManagerAddress ?? void 0,
|
|
854
855
|
DELEGATE_RATE_MANAGER_ID,
|
|
@@ -865,7 +866,7 @@ function mapDeposit(d) {
|
|
|
865
866
|
fulfilledIntents: d.fulfilledIntents ?? 0,
|
|
866
867
|
paymentMethods: resolveMethodNames(d.paymentMethods),
|
|
867
868
|
currencies: d.currencies.map((c) => {
|
|
868
|
-
const info = (0,
|
|
869
|
+
const info = (0, import_sdk4.getCurrencyInfoFromHash)(c.currencyCode);
|
|
869
870
|
return info?.currencyCode ?? c.currencyCode;
|
|
870
871
|
}),
|
|
871
872
|
rateSource: d.currencies[0]?.rateSource || "unknown",
|
|
@@ -977,7 +978,7 @@ function attachOracleConfig(entries, conversionRates) {
|
|
|
977
978
|
(group, gi) => group.map((entry, ci) => {
|
|
978
979
|
const currency = conversionRates[gi]?.[ci]?.currency;
|
|
979
980
|
if (!currency) return entry;
|
|
980
|
-
const oracleConfig = (0,
|
|
981
|
+
const oracleConfig = (0, import_sdk5.getSpreadOracleConfig)(currency);
|
|
981
982
|
if (!oracleConfig) return entry;
|
|
982
983
|
return {
|
|
983
984
|
...entry,
|
|
@@ -999,15 +1000,6 @@ function extractTxHash2(result) {
|
|
|
999
1000
|
return result.transactionHash;
|
|
1000
1001
|
throw new Error("Unexpected transaction result format");
|
|
1001
1002
|
}
|
|
1002
|
-
function createSdkClient(walletClient) {
|
|
1003
|
-
return new import_sdk4.OfframpClient({
|
|
1004
|
-
walletClient,
|
|
1005
|
-
chainId: BASE_CHAIN_ID,
|
|
1006
|
-
runtimeEnv: RUNTIME_ENV,
|
|
1007
|
-
rpcUrl: BASE_RPC_URL,
|
|
1008
|
-
baseApiUrl: API_BASE_URL
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
1003
|
async function findUndelegatedDeposit(walletAddress) {
|
|
1012
1004
|
try {
|
|
1013
1005
|
const service = getIndexerService();
|
|
@@ -1016,6 +1008,7 @@ async function findUndelegatedDeposit(walletAddress) {
|
|
|
1016
1008
|
{ limit: 50 }
|
|
1017
1009
|
);
|
|
1018
1010
|
const escrowLower = ESCROW_ADDRESS.toLowerCase();
|
|
1011
|
+
const delegateIdLower = DELEGATE_RATE_MANAGER_ID.toLowerCase();
|
|
1019
1012
|
const undelegated = (raw || []).filter((d) => {
|
|
1020
1013
|
if (d.status === "CLOSED") return false;
|
|
1021
1014
|
if (d.escrowAddress.toLowerCase() !== escrowLower) return false;
|
|
@@ -1027,7 +1020,7 @@ async function findUndelegatedDeposit(walletAddress) {
|
|
|
1027
1020
|
}
|
|
1028
1021
|
})();
|
|
1029
1022
|
if (remaining === 0n) return false;
|
|
1030
|
-
return d.rateManagerId !==
|
|
1023
|
+
return (d.rateManagerId ?? "").toLowerCase() !== delegateIdLower;
|
|
1031
1024
|
});
|
|
1032
1025
|
undelegated.sort((a, b) => Number(BigInt(b.depositId) - BigInt(a.depositId)));
|
|
1033
1026
|
return undelegated[0] ?? null;
|
|
@@ -1092,7 +1085,7 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1092
1085
|
const minUnits = usdcToUnits(String(MIN_ORDER_USDC));
|
|
1093
1086
|
const maxUnits = usdcToUnits(String(Math.min(amt, 2500)));
|
|
1094
1087
|
try {
|
|
1095
|
-
const publicClient = (0, import_viem3.createPublicClient)({ chain:
|
|
1088
|
+
const publicClient = (0, import_viem3.createPublicClient)({ chain: import_chains3.base, transport: (0, import_viem3.http)(BASE_RPC_URL) });
|
|
1096
1089
|
const balance = await publicClient.readContract({
|
|
1097
1090
|
address: USDC_ADDRESS,
|
|
1098
1091
|
abi: [
|
|
@@ -1147,7 +1140,7 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1147
1140
|
const conversionRates = [
|
|
1148
1141
|
[{ currency: currencyCode, conversionRate: "1" }]
|
|
1149
1142
|
];
|
|
1150
|
-
const baseCurrenciesOverride = (0,
|
|
1143
|
+
const baseCurrenciesOverride = (0, import_sdk5.mapConversionRatesToOnchainMinRate)(conversionRates, 1);
|
|
1151
1144
|
const currenciesOverride = attachOracleConfig(baseCurrenciesOverride, conversionRates);
|
|
1152
1145
|
let hash;
|
|
1153
1146
|
try {
|
|
@@ -1157,8 +1150,8 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
1157
1150
|
retainOnEmpty: false,
|
|
1158
1151
|
intentAmountRange: { min: minUnits, max: maxUnits },
|
|
1159
1152
|
processorNames: [platformId],
|
|
1160
|
-
depositData: [buildDepositData(platformId, normalizedIdentifier)],
|
|
1161
1153
|
conversionRates,
|
|
1154
|
+
payeeDetailsHashes: [hashedOnchainId],
|
|
1162
1155
|
paymentMethodsOverride: [methodHash],
|
|
1163
1156
|
paymentMethodDataOverride: [
|
|
1164
1157
|
{
|