@bosonprotocol/core-sdk 1.20.1 → 1.21.0-alpha.0
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/cjs/core-sdk.d.ts +60 -102
- package/dist/cjs/core-sdk.d.ts.map +1 -1
- package/dist/cjs/core-sdk.js +93 -19
- package/dist/cjs/core-sdk.js.map +1 -1
- package/dist/cjs/erc20/handler.d.ts +7 -0
- package/dist/cjs/erc20/handler.d.ts.map +1 -1
- package/dist/cjs/erc20/handler.js +12 -1
- package/dist/cjs/erc20/handler.js.map +1 -1
- package/dist/cjs/exchanges/handler.d.ts.map +1 -1
- package/dist/cjs/exchanges/handler.js +12 -0
- package/dist/cjs/exchanges/handler.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/meta-tx/biconomy.d.ts +0 -1
- package/dist/cjs/meta-tx/biconomy.d.ts.map +1 -1
- package/dist/cjs/meta-tx/biconomy.js +14 -2
- package/dist/cjs/meta-tx/biconomy.js.map +1 -1
- package/dist/cjs/meta-tx/handler.d.ts +31 -108
- package/dist/cjs/meta-tx/handler.d.ts.map +1 -1
- package/dist/cjs/meta-tx/handler.js +28 -28
- package/dist/cjs/meta-tx/handler.js.map +1 -1
- package/dist/cjs/native-meta-tx/handler.d.ts +43 -0
- package/dist/cjs/native-meta-tx/handler.d.ts.map +1 -0
- package/dist/cjs/native-meta-tx/handler.js +121 -0
- package/dist/cjs/native-meta-tx/handler.js.map +1 -0
- package/dist/cjs/native-meta-tx/index.d.ts +3 -0
- package/dist/cjs/native-meta-tx/index.d.ts.map +1 -0
- package/dist/cjs/native-meta-tx/index.js +29 -0
- package/dist/cjs/native-meta-tx/index.js.map +1 -0
- package/dist/cjs/native-meta-tx/interface.d.ts +3 -0
- package/dist/cjs/native-meta-tx/interface.d.ts.map +1 -0
- package/dist/cjs/native-meta-tx/interface.js +7 -0
- package/dist/cjs/native-meta-tx/interface.js.map +1 -0
- package/dist/cjs/utils/signature.d.ts +1 -0
- package/dist/cjs/utils/signature.d.ts.map +1 -1
- package/dist/cjs/utils/signature.js +1 -6
- package/dist/cjs/utils/signature.js.map +1 -1
- package/dist/esm/core-sdk.d.ts +60 -102
- package/dist/esm/core-sdk.d.ts.map +1 -1
- package/dist/esm/core-sdk.js +86 -12
- package/dist/esm/core-sdk.js.map +1 -1
- package/dist/esm/erc20/handler.d.ts +7 -0
- package/dist/esm/erc20/handler.d.ts.map +1 -1
- package/dist/esm/erc20/handler.js +8 -0
- package/dist/esm/erc20/handler.js.map +1 -1
- package/dist/esm/exchanges/handler.d.ts.map +1 -1
- package/dist/esm/exchanges/handler.js +12 -0
- package/dist/esm/exchanges/handler.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/meta-tx/biconomy.d.ts +0 -1
- package/dist/esm/meta-tx/biconomy.d.ts.map +1 -1
- package/dist/esm/meta-tx/biconomy.js +14 -2
- package/dist/esm/meta-tx/biconomy.js.map +1 -1
- package/dist/esm/meta-tx/handler.d.ts +31 -108
- package/dist/esm/meta-tx/handler.d.ts.map +1 -1
- package/dist/esm/meta-tx/handler.js +28 -27
- package/dist/esm/meta-tx/handler.js.map +1 -1
- package/dist/esm/native-meta-tx/handler.d.ts +43 -0
- package/dist/esm/native-meta-tx/handler.d.ts.map +1 -0
- package/dist/esm/native-meta-tx/handler.js +108 -0
- package/dist/esm/native-meta-tx/handler.js.map +1 -0
- package/dist/esm/native-meta-tx/index.d.ts +3 -0
- package/dist/esm/native-meta-tx/index.d.ts.map +1 -0
- package/dist/esm/native-meta-tx/index.js +3 -0
- package/dist/esm/native-meta-tx/index.js.map +1 -0
- package/dist/esm/native-meta-tx/interface.d.ts +3 -0
- package/dist/esm/native-meta-tx/interface.d.ts.map +1 -0
- package/dist/esm/native-meta-tx/interface.js +4 -0
- package/dist/esm/native-meta-tx/interface.js.map +1 -0
- package/dist/esm/utils/signature.d.ts +1 -0
- package/dist/esm/utils/signature.d.ts.map +1 -1
- package/dist/esm/utils/signature.js +2 -1
- package/dist/esm/utils/signature.js.map +1 -1
- package/package.json +3 -3
- package/src/core-sdk.ts +142 -25
- package/src/erc20/handler.ts +15 -1
- package/src/exchanges/handler.ts +13 -0
- package/src/index.ts +1 -0
- package/src/meta-tx/biconomy.ts +13 -6
- package/src/meta-tx/handler.ts +59 -37
- package/src/native-meta-tx/handler.ts +170 -0
- package/src/native-meta-tx/index.ts +2 -0
- package/src/native-meta-tx/interface.ts +6 -0
- package/src/utils/signature.ts +3 -1
package/src/core-sdk.ts
CHANGED
|
@@ -14,7 +14,6 @@ import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
|
|
|
14
14
|
import { AddressZero } from "@ethersproject/constants";
|
|
15
15
|
import { BytesLike } from "@ethersproject/bytes";
|
|
16
16
|
import { EnvironmentType } from "@bosonprotocol/common/src/types";
|
|
17
|
-
import { ContractTransaction } from "ethers";
|
|
18
17
|
|
|
19
18
|
import * as accounts from "./accounts";
|
|
20
19
|
import * as disputes from "./disputes";
|
|
@@ -25,6 +24,7 @@ import * as erc20 from "./erc20";
|
|
|
25
24
|
import * as erc721 from "./erc721";
|
|
26
25
|
import * as funds from "./funds";
|
|
27
26
|
import * as metaTx from "./meta-tx";
|
|
27
|
+
import * as nativeMetaTx from "./native-meta-tx";
|
|
28
28
|
import * as metadata from "./metadata";
|
|
29
29
|
import * as subgraph from "./subgraph";
|
|
30
30
|
import * as eventLogs from "./event-logs";
|
|
@@ -114,9 +114,23 @@ export class CoreSDK {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
public get isMetaTxConfigSet() {
|
|
117
|
+
return this.checkMetaTxConfigSet();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public checkMetaTxConfigSet(
|
|
121
|
+
args: {
|
|
122
|
+
contractAddress?: string;
|
|
123
|
+
metaTransactionMethod?: string;
|
|
124
|
+
} = {}
|
|
125
|
+
) {
|
|
126
|
+
const contractAddress = args.contractAddress || this._protocolDiamond;
|
|
127
|
+
const metaTransactionMethod =
|
|
128
|
+
args.metaTransactionMethod || "executeMetaTransaction";
|
|
117
129
|
return (
|
|
118
130
|
!!this._metaTxConfig &&
|
|
119
|
-
!!this._metaTxConfig.
|
|
131
|
+
!!this._metaTxConfig.apiIds &&
|
|
132
|
+
!!this._metaTxConfig.apiIds[contractAddress] &&
|
|
133
|
+
!!this._metaTxConfig.apiIds[contractAddress][metaTransactionMethod] &&
|
|
120
134
|
!!this._metaTxConfig.apiKey &&
|
|
121
135
|
!!this._metaTxConfig.relayerUrl
|
|
122
136
|
);
|
|
@@ -940,6 +954,21 @@ export class CoreSDK {
|
|
|
940
954
|
});
|
|
941
955
|
}
|
|
942
956
|
|
|
957
|
+
public async getProtocolAllowance(
|
|
958
|
+
exchangeToken: string,
|
|
959
|
+
overrides: Partial<{
|
|
960
|
+
spender: string;
|
|
961
|
+
owner: string;
|
|
962
|
+
}> = {}
|
|
963
|
+
): Promise<string> {
|
|
964
|
+
return erc20.handler.getAllowance({
|
|
965
|
+
contractAddress: exchangeToken,
|
|
966
|
+
owner: overrides.owner || (await this._web3Lib.getSignerAddress()),
|
|
967
|
+
spender: overrides.spender || this._protocolDiamond,
|
|
968
|
+
web3Lib: this._web3Lib
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
943
972
|
/* -------------------------------------------------------------------------- */
|
|
944
973
|
/* Funds related methods */
|
|
945
974
|
/* -------------------------------------------------------------------------- */
|
|
@@ -1071,8 +1100,9 @@ export class CoreSDK {
|
|
|
1071
1100
|
buyer: string;
|
|
1072
1101
|
}> = {}
|
|
1073
1102
|
): Promise<TransactionResponse> {
|
|
1103
|
+
const buyer = overrides.buyer || (await this._web3Lib.getSignerAddress());
|
|
1074
1104
|
return exchanges.handler.commitToOffer({
|
|
1075
|
-
buyer
|
|
1105
|
+
buyer,
|
|
1076
1106
|
offerId,
|
|
1077
1107
|
web3Lib: this._web3Lib,
|
|
1078
1108
|
subgraphUrl: this._subgraphUrl,
|
|
@@ -1445,12 +1475,13 @@ export class CoreSDK {
|
|
|
1445
1475
|
public async signMetaTxCreateSeller(
|
|
1446
1476
|
args: Omit<
|
|
1447
1477
|
Parameters<typeof metaTx.handler.signMetaTxCreateSeller>[0],
|
|
1448
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1478
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1449
1479
|
>
|
|
1450
1480
|
) {
|
|
1451
1481
|
return metaTx.handler.signMetaTxCreateSeller({
|
|
1452
1482
|
web3Lib: this._web3Lib,
|
|
1453
1483
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1484
|
+
chainId: this._chainId,
|
|
1454
1485
|
...args
|
|
1455
1486
|
});
|
|
1456
1487
|
}
|
|
@@ -1463,12 +1494,13 @@ export class CoreSDK {
|
|
|
1463
1494
|
public async signMetaTxCreateOffer(
|
|
1464
1495
|
args: Omit<
|
|
1465
1496
|
Parameters<typeof metaTx.handler.signMetaTxCreateOffer>[0],
|
|
1466
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1497
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1467
1498
|
>
|
|
1468
1499
|
) {
|
|
1469
1500
|
return metaTx.handler.signMetaTxCreateOffer({
|
|
1470
1501
|
web3Lib: this._web3Lib,
|
|
1471
1502
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1503
|
+
chainId: this._chainId,
|
|
1472
1504
|
...args
|
|
1473
1505
|
});
|
|
1474
1506
|
}
|
|
@@ -1481,12 +1513,13 @@ export class CoreSDK {
|
|
|
1481
1513
|
public async signMetaTxCreateOfferBatch(
|
|
1482
1514
|
args: Omit<
|
|
1483
1515
|
Parameters<typeof metaTx.handler.signMetaTxCreateOfferBatch>[0],
|
|
1484
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1516
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1485
1517
|
>
|
|
1486
1518
|
) {
|
|
1487
1519
|
return metaTx.handler.signMetaTxCreateOfferBatch({
|
|
1488
1520
|
web3Lib: this._web3Lib,
|
|
1489
1521
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1522
|
+
chainId: this._chainId,
|
|
1490
1523
|
...args
|
|
1491
1524
|
});
|
|
1492
1525
|
}
|
|
@@ -1499,12 +1532,13 @@ export class CoreSDK {
|
|
|
1499
1532
|
public async signMetaTxVoidOffer(
|
|
1500
1533
|
args: Omit<
|
|
1501
1534
|
Parameters<typeof metaTx.handler.signMetaTxVoidOffer>[0],
|
|
1502
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1535
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1503
1536
|
>
|
|
1504
1537
|
) {
|
|
1505
1538
|
return metaTx.handler.signMetaTxVoidOffer({
|
|
1506
1539
|
web3Lib: this._web3Lib,
|
|
1507
1540
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1541
|
+
chainId: this._chainId,
|
|
1508
1542
|
...args
|
|
1509
1543
|
});
|
|
1510
1544
|
}
|
|
@@ -1517,12 +1551,13 @@ export class CoreSDK {
|
|
|
1517
1551
|
public async signMetaTxVoidOfferBatch(
|
|
1518
1552
|
args: Omit<
|
|
1519
1553
|
Parameters<typeof metaTx.handler.signMetaTxVoidOfferBatch>[0],
|
|
1520
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1554
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1521
1555
|
>
|
|
1522
1556
|
) {
|
|
1523
1557
|
return metaTx.handler.signMetaTxVoidOfferBatch({
|
|
1524
1558
|
web3Lib: this._web3Lib,
|
|
1525
1559
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1560
|
+
chainId: this._chainId,
|
|
1526
1561
|
...args
|
|
1527
1562
|
});
|
|
1528
1563
|
}
|
|
@@ -1535,12 +1570,13 @@ export class CoreSDK {
|
|
|
1535
1570
|
public async signMetaTxCompleteExchangeBatch(
|
|
1536
1571
|
args: Omit<
|
|
1537
1572
|
Parameters<typeof metaTx.handler.signMetaTxCompleteExchangeBatch>[0],
|
|
1538
|
-
"web3Lib" | "metaTxHandlerAddress"
|
|
1573
|
+
"web3Lib" | "metaTxHandlerAddress" | "chainId"
|
|
1539
1574
|
>
|
|
1540
1575
|
) {
|
|
1541
1576
|
return metaTx.handler.signMetaTxCompleteExchangeBatch({
|
|
1542
1577
|
web3Lib: this._web3Lib,
|
|
1543
1578
|
metaTxHandlerAddress: this._protocolDiamond,
|
|
1579
|
+
chainId: this._chainId,
|
|
1544
1580
|
...args
|
|
1545
1581
|
});
|
|
1546
1582
|
}
|
|
@@ -1734,15 +1770,16 @@ export class CoreSDK {
|
|
|
1734
1770
|
overrides: Partial<{
|
|
1735
1771
|
userAddress: string;
|
|
1736
1772
|
contractAddress: string;
|
|
1737
|
-
metaTxConfig: Partial<MetaTxConfig>;
|
|
1773
|
+
metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
|
|
1774
|
+
metaTransactionMethod: string;
|
|
1738
1775
|
}> = {}
|
|
1739
|
-
): Promise<
|
|
1740
|
-
const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
|
|
1741
|
-
this.assertAndGetMetaTxConfig(overrides
|
|
1776
|
+
): Promise<TransactionResponse> {
|
|
1777
|
+
const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl, contractAddress } =
|
|
1778
|
+
this.assertAndGetMetaTxConfig(overrides);
|
|
1742
1779
|
|
|
1743
1780
|
return metaTx.handler.relayMetaTransaction({
|
|
1744
1781
|
web3LibAdapter: this._web3Lib,
|
|
1745
|
-
contractAddress
|
|
1782
|
+
contractAddress,
|
|
1746
1783
|
chainId: this._chainId,
|
|
1747
1784
|
metaTx: {
|
|
1748
1785
|
config: {
|
|
@@ -1764,6 +1801,76 @@ export class CoreSDK {
|
|
|
1764
1801
|
});
|
|
1765
1802
|
}
|
|
1766
1803
|
|
|
1804
|
+
/**
|
|
1805
|
+
* Encodes and signs a native "token.approve()" meta transaction that can be relayed.
|
|
1806
|
+
* @param exchangeToken - The address of the token contract.
|
|
1807
|
+
* @param value - The value to be approved.
|
|
1808
|
+
* @param overrides - Optionally specify a spender address (default is the protocol contract address).
|
|
1809
|
+
* @returns Signature.
|
|
1810
|
+
*/
|
|
1811
|
+
public async signNativeMetaTxApproveExchangeToken(
|
|
1812
|
+
exchangeToken: string,
|
|
1813
|
+
value: BigNumberish,
|
|
1814
|
+
overrides: Partial<{
|
|
1815
|
+
spender: string;
|
|
1816
|
+
}> = {}
|
|
1817
|
+
) {
|
|
1818
|
+
const user = await this._web3Lib.getSignerAddress();
|
|
1819
|
+
return nativeMetaTx.handler.signNativeMetaTxApproveExchangeToken({
|
|
1820
|
+
web3Lib: this._web3Lib,
|
|
1821
|
+
chainId: this._chainId,
|
|
1822
|
+
user,
|
|
1823
|
+
exchangeToken,
|
|
1824
|
+
spender: overrides.spender || this._protocolDiamond,
|
|
1825
|
+
value
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Relay a native meta transaction,
|
|
1831
|
+
* @param metaTxParams - Required params for meta transaction.
|
|
1832
|
+
* @param overrides - Optional overrides.
|
|
1833
|
+
* @returns Transaction response.
|
|
1834
|
+
*/
|
|
1835
|
+
public async relayNativeMetaTransaction(
|
|
1836
|
+
contractAddress: string,
|
|
1837
|
+
metaTxParams: {
|
|
1838
|
+
functionSignature: BytesLike;
|
|
1839
|
+
sigR: BytesLike;
|
|
1840
|
+
sigS: BytesLike;
|
|
1841
|
+
sigV: BigNumberish;
|
|
1842
|
+
},
|
|
1843
|
+
overrides: Partial<{
|
|
1844
|
+
userAddress: string;
|
|
1845
|
+
metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
|
|
1846
|
+
metaTransactionMethod: string;
|
|
1847
|
+
}> = {}
|
|
1848
|
+
): Promise<TransactionResponse> {
|
|
1849
|
+
const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
|
|
1850
|
+
this.assertAndGetMetaTxConfig({ ...overrides, contractAddress });
|
|
1851
|
+
|
|
1852
|
+
return nativeMetaTx.handler.relayNativeMetaTransaction({
|
|
1853
|
+
web3LibAdapter: this._web3Lib,
|
|
1854
|
+
contractAddress,
|
|
1855
|
+
chainId: this._chainId,
|
|
1856
|
+
metaTx: {
|
|
1857
|
+
config: {
|
|
1858
|
+
relayerUrl: metaTxRelayerUrl,
|
|
1859
|
+
apiId: metaTxApiId,
|
|
1860
|
+
apiKey: metaTxApiKey
|
|
1861
|
+
},
|
|
1862
|
+
params: {
|
|
1863
|
+
userAddress:
|
|
1864
|
+
overrides.userAddress || (await this._web3Lib.getSignerAddress()),
|
|
1865
|
+
functionSignature: metaTxParams.functionSignature,
|
|
1866
|
+
sigR: metaTxParams.sigR,
|
|
1867
|
+
sigS: metaTxParams.sigS,
|
|
1868
|
+
sigV: metaTxParams.sigV
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1767
1874
|
/**
|
|
1768
1875
|
* Returns information of submitted meta transaction.
|
|
1769
1876
|
* See https://docs.biconomy.io/api/native-meta-tx/get-retried-hashes.
|
|
@@ -1774,11 +1881,13 @@ export class CoreSDK {
|
|
|
1774
1881
|
public async getResubmittedMetaTx(
|
|
1775
1882
|
originalMetaTxHash: string,
|
|
1776
1883
|
overrides: Partial<{
|
|
1777
|
-
|
|
1884
|
+
contractAddress: string;
|
|
1885
|
+
metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
|
|
1886
|
+
metaTransactionMethod: string;
|
|
1778
1887
|
}> = {}
|
|
1779
1888
|
): Promise<GetRetriedHashesData> {
|
|
1780
1889
|
const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } =
|
|
1781
|
-
this.assertAndGetMetaTxConfig(overrides
|
|
1890
|
+
this.assertAndGetMetaTxConfig(overrides);
|
|
1782
1891
|
|
|
1783
1892
|
return metaTx.handler.getResubmitted({
|
|
1784
1893
|
chainId: this._chainId,
|
|
@@ -1794,19 +1903,26 @@ export class CoreSDK {
|
|
|
1794
1903
|
}
|
|
1795
1904
|
|
|
1796
1905
|
private assertAndGetMetaTxConfig(
|
|
1797
|
-
|
|
1906
|
+
overrides: Partial<{
|
|
1907
|
+
contractAddress: string;
|
|
1908
|
+
metaTxConfig: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
|
|
1909
|
+
metaTransactionMethod: string;
|
|
1910
|
+
}> = {}
|
|
1798
1911
|
) {
|
|
1912
|
+
const contractAddress = overrides.contractAddress || this._protocolDiamond;
|
|
1913
|
+
const metaTransactionMethod =
|
|
1914
|
+
overrides.metaTransactionMethod || "executeMetaTransaction";
|
|
1799
1915
|
const metaTxRelayerUrl =
|
|
1800
|
-
|
|
1916
|
+
overrides.metaTxConfig?.relayerUrl || this._metaTxConfig?.relayerUrl;
|
|
1801
1917
|
const metaTxApiKey =
|
|
1802
|
-
|
|
1918
|
+
overrides.metaTxConfig?.apiKey || this._metaTxConfig?.apiKey;
|
|
1919
|
+
// metaTxApiId is depending on the contract/method(=executeMetaTransaction) to be called with Biconomy
|
|
1920
|
+
const apiIds = this._metaTxConfig?.apiIds[contractAddress];
|
|
1803
1921
|
const metaTxApiId =
|
|
1804
|
-
|
|
1922
|
+
overrides.metaTxConfig?.apiId ||
|
|
1923
|
+
(apiIds && apiIds[metaTransactionMethod]);
|
|
1805
1924
|
|
|
1806
|
-
if (
|
|
1807
|
-
!this.isMetaTxConfigSet ||
|
|
1808
|
-
!(metaTxRelayerUrl && metaTxApiKey && metaTxApiId)
|
|
1809
|
-
) {
|
|
1925
|
+
if (!(metaTxRelayerUrl && metaTxApiKey && metaTxApiId)) {
|
|
1810
1926
|
throw new Error(
|
|
1811
1927
|
"CoreSDK not configured to relay meta transactions. Either pass in 'relayerUrl', 'apiKey' and 'apiId' during initialization OR as overrides arguments."
|
|
1812
1928
|
);
|
|
@@ -1815,7 +1931,8 @@ export class CoreSDK {
|
|
|
1815
1931
|
return {
|
|
1816
1932
|
metaTxRelayerUrl,
|
|
1817
1933
|
metaTxApiId,
|
|
1818
|
-
metaTxApiKey
|
|
1934
|
+
metaTxApiKey,
|
|
1935
|
+
contractAddress
|
|
1819
1936
|
};
|
|
1820
1937
|
}
|
|
1821
1938
|
|
package/src/erc20/handler.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Web3LibAdapter } from "@bosonprotocol/common";
|
|
2
|
-
import { BigNumberish } from "@ethersproject/bignumber";
|
|
2
|
+
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
|
|
3
3
|
import { erc20Iface } from "./interface";
|
|
4
4
|
|
|
5
5
|
export async function approve(args: {
|
|
@@ -67,3 +67,17 @@ export async function getName(args: {
|
|
|
67
67
|
const [name] = erc20Iface.decodeFunctionResult("name", result);
|
|
68
68
|
return String(name);
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
export async function ensureAllowance(args: {
|
|
72
|
+
owner: string;
|
|
73
|
+
spender: string;
|
|
74
|
+
contractAddress: string;
|
|
75
|
+
value: BigNumberish;
|
|
76
|
+
web3Lib: Web3LibAdapter;
|
|
77
|
+
}) {
|
|
78
|
+
const allowance = await getAllowance(args);
|
|
79
|
+
if (BigNumber.from(allowance).lt(args.value)) {
|
|
80
|
+
const approveTx = await approve(args);
|
|
81
|
+
await approveTx.wait();
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/exchanges/handler.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { getOfferById } from "../offers/subgraph";
|
|
14
14
|
import { getExchangeById, getExchanges } from "../exchanges/subgraph";
|
|
15
15
|
import { ExchangeFieldsFragment, ExchangeState } from "../subgraph";
|
|
16
|
+
import { ensureAllowance } from "../erc20/handler";
|
|
16
17
|
|
|
17
18
|
type BaseExchangeHandlerArgs = {
|
|
18
19
|
contractAddress: string;
|
|
@@ -48,6 +49,18 @@ export async function commitToOffer(
|
|
|
48
49
|
throw new Error(`Offer with id ${args.offerId} is sold out`);
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
if (offer.exchangeToken.address !== AddressZero) {
|
|
53
|
+
const owner = await args.web3Lib.getSignerAddress();
|
|
54
|
+
// check if we need the committer to approve the token first
|
|
55
|
+
await ensureAllowance({
|
|
56
|
+
owner,
|
|
57
|
+
spender: args.contractAddress,
|
|
58
|
+
contractAddress: offer.exchangeToken.address,
|
|
59
|
+
value: offer.price,
|
|
60
|
+
web3Lib: args.web3Lib
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
return args.web3Lib.sendTransaction({
|
|
52
65
|
from: args.buyer,
|
|
53
66
|
to: args.contractAddress,
|
package/src/index.ts
CHANGED
package/src/meta-tx/biconomy.ts
CHANGED
|
@@ -36,7 +36,6 @@ export type GetRetriedHashesResponse = {
|
|
|
36
36
|
code: number;
|
|
37
37
|
message: string;
|
|
38
38
|
data: GetRetriedHashesData;
|
|
39
|
-
events?: unknown[];
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
export type GetRetriedHashesArgs = {
|
|
@@ -72,13 +71,21 @@ export class Biconomy {
|
|
|
72
71
|
});
|
|
73
72
|
|
|
74
73
|
if (!response.ok) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
let message;
|
|
75
|
+
try {
|
|
76
|
+
const jsonResponse = await response.json();
|
|
77
|
+
message = JSON.stringify(jsonResponse);
|
|
78
|
+
} catch {
|
|
79
|
+
message = response.statusText;
|
|
80
|
+
}
|
|
81
|
+
throw new ApiError(response.status, `Failed to relay tx: ${message}`);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
const txResponse = (await response.json()) as RelayTransactionResponse;
|
|
85
|
+
if (!txResponse.txHash) {
|
|
86
|
+
throw new ApiError(txResponse.flag, txResponse.log);
|
|
87
|
+
}
|
|
88
|
+
return txResponse;
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
public async getResubmitted(
|
package/src/meta-tx/handler.ts
CHANGED
|
@@ -2,11 +2,14 @@ import {
|
|
|
2
2
|
CreateOfferArgs,
|
|
3
3
|
CreateSellerArgs,
|
|
4
4
|
MetaTxConfig,
|
|
5
|
-
Web3LibAdapter
|
|
5
|
+
Web3LibAdapter,
|
|
6
|
+
TransactionResponse,
|
|
7
|
+
utils,
|
|
8
|
+
MetadataStorage
|
|
6
9
|
} from "@bosonprotocol/common";
|
|
10
|
+
import { storeMetadataOnTheGraph } from "../offers/storage";
|
|
7
11
|
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
|
|
8
12
|
import { BytesLike } from "@ethersproject/bytes";
|
|
9
|
-
import { ContractTransaction } from "@ethersproject/contracts";
|
|
10
13
|
|
|
11
14
|
import { encodeCreateSeller } from "../accounts/interface";
|
|
12
15
|
import { bosonExchangeHandlerIface } from "../exchanges/interface";
|
|
@@ -18,19 +21,27 @@ import {
|
|
|
18
21
|
import { prepareDataSignatureParameters } from "../utils/signature";
|
|
19
22
|
import { Biconomy, GetRetriedHashesData } from "./biconomy";
|
|
20
23
|
|
|
21
|
-
type BaseMetaTxArgs = {
|
|
24
|
+
export type BaseMetaTxArgs = {
|
|
22
25
|
web3Lib: Web3LibAdapter;
|
|
23
26
|
nonce: BigNumberish;
|
|
24
27
|
metaTxHandlerAddress: string;
|
|
25
28
|
chainId: number;
|
|
26
29
|
};
|
|
27
30
|
|
|
31
|
+
export type SignedMetaTx = {
|
|
32
|
+
functionName: string;
|
|
33
|
+
functionSignature: string;
|
|
34
|
+
r: string;
|
|
35
|
+
s: string;
|
|
36
|
+
v: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
28
39
|
export async function signMetaTx(
|
|
29
40
|
args: BaseMetaTxArgs & {
|
|
30
41
|
functionName: string;
|
|
31
42
|
functionSignature: string;
|
|
32
43
|
}
|
|
33
|
-
) {
|
|
44
|
+
): Promise<SignedMetaTx> {
|
|
34
45
|
const metaTransactionType = [
|
|
35
46
|
{ name: "nonce", type: "uint256" },
|
|
36
47
|
{ name: "from", type: "address" },
|
|
@@ -84,8 +95,20 @@ export async function signMetaTxCreateSeller(
|
|
|
84
95
|
export async function signMetaTxCreateOffer(
|
|
85
96
|
args: BaseMetaTxArgs & {
|
|
86
97
|
createOfferArgs: CreateOfferArgs;
|
|
98
|
+
metadataStorage?: MetadataStorage;
|
|
99
|
+
theGraphStorage?: MetadataStorage;
|
|
87
100
|
}
|
|
88
101
|
) {
|
|
102
|
+
utils.validation.createOfferArgsSchema.validateSync(args.createOfferArgs, {
|
|
103
|
+
abortEarly: false
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await storeMetadataOnTheGraph({
|
|
107
|
+
metadataUriOrHash: args.createOfferArgs.metadataUri,
|
|
108
|
+
metadataStorage: args.metadataStorage,
|
|
109
|
+
theGraphStorage: args.theGraphStorage
|
|
110
|
+
});
|
|
111
|
+
|
|
89
112
|
return signMetaTx({
|
|
90
113
|
...args,
|
|
91
114
|
functionName:
|
|
@@ -97,8 +120,26 @@ export async function signMetaTxCreateOffer(
|
|
|
97
120
|
export async function signMetaTxCreateOfferBatch(
|
|
98
121
|
args: BaseMetaTxArgs & {
|
|
99
122
|
createOffersArgs: CreateOfferArgs[];
|
|
123
|
+
metadataStorage?: MetadataStorage;
|
|
124
|
+
theGraphStorage?: MetadataStorage;
|
|
100
125
|
}
|
|
101
126
|
) {
|
|
127
|
+
for (const offerToCreate of args.createOffersArgs) {
|
|
128
|
+
utils.validation.createOfferArgsSchema.validateSync(offerToCreate, {
|
|
129
|
+
abortEarly: false
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
await Promise.all(
|
|
134
|
+
args.createOffersArgs.map((offerToCreate) =>
|
|
135
|
+
storeMetadataOnTheGraph({
|
|
136
|
+
metadataUriOrHash: offerToCreate.metadataUri,
|
|
137
|
+
metadataStorage: args.metadataStorage,
|
|
138
|
+
theGraphStorage: args.theGraphStorage
|
|
139
|
+
})
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
|
|
102
143
|
return signMetaTx({
|
|
103
144
|
...args,
|
|
104
145
|
functionName:
|
|
@@ -170,7 +211,7 @@ export async function signMetaTxCommitToOffer(
|
|
|
170
211
|
args: BaseMetaTxArgs & {
|
|
171
212
|
offerId: BigNumberish;
|
|
172
213
|
}
|
|
173
|
-
) {
|
|
214
|
+
): Promise<SignedMetaTx> {
|
|
174
215
|
const functionName = "commitToOffer(address,uint256)";
|
|
175
216
|
|
|
176
217
|
const offerType = [
|
|
@@ -364,7 +405,7 @@ export async function signMetaTxWithdrawFunds(
|
|
|
364
405
|
tokenList: string[];
|
|
365
406
|
tokenAmounts: BigNumberish[];
|
|
366
407
|
}
|
|
367
|
-
) {
|
|
408
|
+
): Promise<SignedMetaTx> {
|
|
368
409
|
const functionName = "withdrawFunds(uint256,bytes32,bytes32,uint8)";
|
|
369
410
|
|
|
370
411
|
const fundType = [
|
|
@@ -428,7 +469,7 @@ function makeExchangeMetaTxSigner(
|
|
|
428
469
|
args: BaseMetaTxArgs & {
|
|
429
470
|
exchangeId: BigNumberish;
|
|
430
471
|
}
|
|
431
|
-
) {
|
|
472
|
+
): Promise<SignedMetaTx> {
|
|
432
473
|
const exchangeType = [{ name: "exchangeId", type: "uint256" }];
|
|
433
474
|
|
|
434
475
|
const metaTransactionType = [
|
|
@@ -481,7 +522,7 @@ export async function relayMetaTransaction(args: {
|
|
|
481
522
|
chainId: number;
|
|
482
523
|
contractAddress: string;
|
|
483
524
|
metaTx: {
|
|
484
|
-
config: MetaTxConfig;
|
|
525
|
+
config: Omit<MetaTxConfig, "apiIds"> & { apiId: string };
|
|
485
526
|
params: {
|
|
486
527
|
userAddress: string;
|
|
487
528
|
functionName: string;
|
|
@@ -492,7 +533,7 @@ export async function relayMetaTransaction(args: {
|
|
|
492
533
|
sigV: BigNumberish;
|
|
493
534
|
};
|
|
494
535
|
};
|
|
495
|
-
}): Promise<
|
|
536
|
+
}): Promise<TransactionResponse> {
|
|
496
537
|
const { chainId, contractAddress, metaTx } = args;
|
|
497
538
|
|
|
498
539
|
const biconomy = new Biconomy(
|
|
@@ -522,43 +563,24 @@ export async function relayMetaTransaction(args: {
|
|
|
522
563
|
transactionHash: relayTxResponse.txHash
|
|
523
564
|
});
|
|
524
565
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
// data below.
|
|
566
|
+
const txHash = waitResponse.data.newHash;
|
|
567
|
+
const txReceipt = await args.web3LibAdapter.getTransactionReceipt(txHash);
|
|
528
568
|
return {
|
|
529
|
-
to: contractAddress,
|
|
530
|
-
from: metaTx.params.userAddress,
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
logsBloom: "",
|
|
535
|
-
blockHash: "string",
|
|
536
|
-
transactionHash: waitResponse.data.newHash,
|
|
537
|
-
logs: [],
|
|
538
|
-
blockNumber: 0,
|
|
539
|
-
confirmations: 0,
|
|
540
|
-
cumulativeGasUsed: BigNumber.from(0),
|
|
541
|
-
effectiveGasPrice: BigNumber.from(waitResponse.data.newGasPrice),
|
|
542
|
-
byzantium: true,
|
|
543
|
-
type: 0,
|
|
544
|
-
events: waitResponse.events?.map((event) => JSON.parse(event as string))
|
|
569
|
+
to: txReceipt?.to || contractAddress,
|
|
570
|
+
from: txReceipt?.from || metaTx.params.userAddress,
|
|
571
|
+
transactionHash: txHash,
|
|
572
|
+
logs: txReceipt?.logs || [],
|
|
573
|
+
effectiveGasPrice: BigNumber.from(waitResponse.data.newGasPrice)
|
|
545
574
|
};
|
|
546
575
|
},
|
|
547
|
-
hash: relayTxResponse.txHash
|
|
548
|
-
confirmations: 0,
|
|
549
|
-
from: metaTx.params.userAddress,
|
|
550
|
-
nonce: 0,
|
|
551
|
-
gasLimit: BigNumber.from(0),
|
|
552
|
-
data: "",
|
|
553
|
-
value: BigNumber.from(0),
|
|
554
|
-
chainId: chainId
|
|
576
|
+
hash: relayTxResponse.txHash
|
|
555
577
|
};
|
|
556
578
|
}
|
|
557
579
|
|
|
558
580
|
export async function getResubmitted(args: {
|
|
559
581
|
chainId: number;
|
|
560
582
|
metaTx: {
|
|
561
|
-
config: MetaTxConfig
|
|
583
|
+
config: Partial<Omit<MetaTxConfig, "apiIds"> & { apiId: string }>;
|
|
562
584
|
originalHash: string;
|
|
563
585
|
};
|
|
564
586
|
}): Promise<GetRetriedHashesData> {
|