@ember-finance/sdk 1.2.2 → 1.2.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Signer } from "ethers";
|
|
1
|
+
import { Provider, Signer } from "ethers";
|
|
2
2
|
import { IPermitSignature } from "../interfaces";
|
|
3
3
|
import { NumStr } from "../../common/types";
|
|
4
4
|
/**
|
|
@@ -79,6 +79,28 @@ export declare function getPermitVersion(tokenAddress: string, provider: import(
|
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
81
|
export declare function supportsEIP5267(tokenAddress: string, provider: import("ethers").Provider): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Helper function to check if a token supports EIP-2612
|
|
84
|
+
*
|
|
85
|
+
* EIP-2612 defines a standard way to retrieve EIP-712 domain information
|
|
86
|
+
* via the DOMAIN_SEPARATOR() method. This is useful for tokens that want to
|
|
87
|
+
* expose their domain separator parameters in a standardized way.
|
|
88
|
+
*
|
|
89
|
+
* @param tokenAddress The address of the ERC20 token
|
|
90
|
+
* @param provider An ethers.js provider
|
|
91
|
+
* @returns True if the token supports EIP-2612, false otherwise
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { supportsERC2612 } from "@ember-finance/sdk";
|
|
96
|
+
*
|
|
97
|
+
* const supports = await supportsERC2612(tokenAddress, provider);
|
|
98
|
+
* if (supports) {
|
|
99
|
+
* console.log("Token supports EIP-2612");
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function supportsERC2612(tokenAddress: string, provider: Provider): Promise<boolean>;
|
|
82
104
|
/**
|
|
83
105
|
* Helper function to get the current nonce for a user from an EIP-2612 token
|
|
84
106
|
*
|
|
@@ -36,8 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.signPermit = signPermit;
|
|
37
37
|
exports.getPermitVersion = getPermitVersion;
|
|
38
38
|
exports.supportsEIP5267 = supportsEIP5267;
|
|
39
|
+
exports.supportsERC2612 = supportsERC2612;
|
|
39
40
|
exports.getPermitNonce = getPermitNonce;
|
|
40
41
|
exports.signPermitSimple = signPermitSimple;
|
|
42
|
+
const ethers_1 = require("ethers");
|
|
41
43
|
/**
|
|
42
44
|
* Signs an EIP-2612 permit message
|
|
43
45
|
*
|
|
@@ -190,6 +192,42 @@ async function supportsEIP5267(tokenAddress, provider) {
|
|
|
190
192
|
return false;
|
|
191
193
|
}
|
|
192
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Helper function to check if a token supports EIP-2612
|
|
197
|
+
*
|
|
198
|
+
* EIP-2612 defines a standard way to retrieve EIP-712 domain information
|
|
199
|
+
* via the DOMAIN_SEPARATOR() method. This is useful for tokens that want to
|
|
200
|
+
* expose their domain separator parameters in a standardized way.
|
|
201
|
+
*
|
|
202
|
+
* @param tokenAddress The address of the ERC20 token
|
|
203
|
+
* @param provider An ethers.js provider
|
|
204
|
+
* @returns True if the token supports EIP-2612, false otherwise
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* import { supportsERC2612 } from "@ember-finance/sdk";
|
|
209
|
+
*
|
|
210
|
+
* const supports = await supportsERC2612(tokenAddress, provider);
|
|
211
|
+
* if (supports) {
|
|
212
|
+
* console.log("Token supports EIP-2612");
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
async function supportsERC2612(tokenAddress, provider) {
|
|
217
|
+
const abi = [
|
|
218
|
+
"function nonces(address) view returns (uint256)",
|
|
219
|
+
"function DOMAIN_SEPARATOR() view returns (bytes32)"
|
|
220
|
+
];
|
|
221
|
+
try {
|
|
222
|
+
const token = new ethers_1.Contract(tokenAddress, abi, provider);
|
|
223
|
+
await token.nonces(ethers_1.ZeroAddress);
|
|
224
|
+
await token.DOMAIN_SEPARATOR();
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
193
231
|
/**
|
|
194
232
|
* Helper function to get the current nonce for a user from an EIP-2612 token
|
|
195
233
|
*
|