[SDK] Fix handling of old allowlist proof format (#368)

This commit is contained in:
Joaquim Verges
2022-11-02 14:11:13 -07:00
committed by GitHub
parent c9c0e4ff39
commit 4e7b293c54
6 changed files with 32 additions and 68 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---
Fix handling of old allowlist proof format
+2 -1
View File
@@ -16,4 +16,5 @@ public/dist
.yalc/
yalc.lock
build/
playwright-report/
playwright-report/
.vscode/
@@ -92,14 +92,16 @@ export async function prepareClaim(
tokenDecimals,
);
priceInProof =
snapshotEntry.price === undefined ||
snapshotEntry.price === "unlimited"
? ethers.constants.MaxUint256
: await normalizePriceValue(
contractWrapper.getProvider(),
snapshotEntry.price,
snapshotEntry.currencyAddress,
snapshotEntry.currencyAddress || ethers.constants.AddressZero,
);
currencyAddressInProof = snapshotEntry.currencyAddress;
currencyAddressInProof =
snapshotEntry.currencyAddress || ethers.constants.AddressZero;
} else {
// if no snapshot entry, and it's a v1 format (exclusive allowlist) then address can't claim
if (snapshotFormatVersion === SnapshotFormatVersion.V1) {
@@ -323,9 +325,13 @@ export async function getClaimerProofs(
return undefined;
}
const price =
claim.price === "unlimited"
claim.price === "unlimited" || claim.price === undefined
? ethers.constants.MaxUint256
: await normalizePriceValue(provider, claim.price, claim.currencyAddress);
: await normalizePriceValue(
provider,
claim.price,
claim.currencyAddress || ethers.constants.AddressZero,
);
const maxClaimable =
claim.maxClaimable === "unlimited"
? ethers.constants.MaxUint256
@@ -334,7 +340,7 @@ export async function getClaimerProofs(
proof: claim.proof,
maxClaimable,
price,
currencyAddress: claim.currencyAddress,
currencyAddress: claim.currencyAddress || ethers.constants.AddressZero,
};
}
@@ -101,8 +101,11 @@ export class ShardedMerkleTree {
[
entry.address,
convertQuantityToBigNumber(entry.maxClaimable, tokenDecimals),
convertQuantityToBigNumber(entry.price, currencyDecimals),
entry.currencyAddress,
convertQuantityToBigNumber(
entry.price || "unlimited",
currencyDecimals,
),
entry.currencyAddress || ethers.constants.AddressZero,
],
);
}
@@ -111,11 +114,14 @@ export class ShardedMerkleTree {
static async fetchAndCacheDecimals(
cache: Record<string, number>,
provider: ethers.providers.Provider,
currencyAddress: string,
currencyAddress?: string,
): Promise<number> {
if (!currencyAddress) {
return 18;
}
// cache decimals for each currency to avoid refetching for every address
let currencyDecimals = cache[currencyAddress];
if (!currencyDecimals) {
if (currencyDecimals === undefined) {
const currencyMetadata = await fetchCurrencyMetadata(
provider,
currencyAddress,
@@ -13,8 +13,10 @@ export const MerkleSchema = z.object({
export const SnapshotEntryInput = z.object({
address: AddressSchema,
maxClaimable: QuantitySchema.default(0), // defaults to 0
price: QuantitySchema, // defaults to unlimited
currencyAddress: AddressSchema.default(ethers.constants.AddressZero),
price: QuantitySchema.optional(), // defaults to unlimited, but can be undefined in old snapshots
currencyAddress: AddressSchema.default(
ethers.constants.AddressZero,
).optional(), // defaults to AddressZero, but can be undefined for old snapshots
});
export type SnapshotEntry = z.output<typeof SnapshotEntryInput>;
-56
View File
@@ -1475,36 +1475,6 @@
near-api-js "^0.44.2"
near-seed-phrase "^0.2.0"
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-darwin-arm64/-/cbor-extract-darwin-arm64-2.0.0.tgz#cf0667e4c22111c9d45e16c29964892b12460a76"
integrity sha512-jebtLrruvsBbGMsUn0QxZW/8Z7caS9OkszVKZ64WTWajUkyohmolUdKL2nbfaTyyi3ABJrxVNM4YO1pvMsNI1g==
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-darwin-x64/-/cbor-extract-darwin-x64-2.0.0.tgz#7bc01e7911b97eee4c78ae074bd3108f2ff208c3"
integrity sha512-LGYjdlyqANBqCDzBujCqXpPcK70rvaQgw98/aquzBuEmK0KXS7i579CoVG1yS/eb3bMqiVPevBri45jbR6Tlsg==
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-linux-arm64/-/cbor-extract-linux-arm64-2.0.0.tgz#e40608afed5f373091560fa9dcd19c7f52f510b0"
integrity sha512-c1rbQcSF01yVgbG60zEfHNsUkXiEEQRNdYqm5qpqEAkLx4gA6DDU91IQbalkqXfwDuQzcMovOc1TC3uJJIi2OQ==
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-linux-arm/-/cbor-extract-linux-arm-2.0.0.tgz#f52a7580fb23e305370e66ae9ff136de3729c4b8"
integrity sha512-cOGHEIif5rPbpix6qhpuatrZzm6HeC5rT0nXt8ynLTc7PzfXmovswD9x6d9h5NcHswkV5y3PbkNbpel/tLADYg==
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-linux-x64/-/cbor-extract-linux-x64-2.0.0.tgz#8c936b8a93f915bf3c2459d5b4b78d244bda0f26"
integrity sha512-WYeE1b5WGf9pbbQH3qeNBXq710gGsuVFUiP148RY8In+2pCp/fxjBpe701ngam9/fF5D+gJs8B1i5wv/PN7JZA==
"@cbor-extract/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@cbor-extract/cbor-extract-win32-x64/-/cbor-extract-win32-x64-2.0.0.tgz#4d4ad91527a8313c3db1e2167a8821dfae9d6211"
integrity sha512-XqVuJEnE0jpl/RkuSp04FF2UE73gY52Y4nZaIE6j9GAeSH2cHYU5CCd4TaVMDi2M18ZpZv7XhL/k+nneQzyJpQ==
"@changesets/apply-release-plan@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@changesets/apply-release-plan/-/apply-release-plan-6.1.0.tgz#97d755a7725bdcc1152aa54d8c7fbc85a5bf1e40"
@@ -7128,27 +7098,6 @@ catering@^2.1.0, catering@^2.1.1:
resolved "https://registry.yarnpkg.com/catering/-/catering-2.1.1.tgz#66acba06ed5ee28d5286133982a927de9a04b510"
integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==
cbor-extract@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/cbor-extract/-/cbor-extract-2.0.2.tgz#8e45339627fb8b47071e8e71138c630019125939"
integrity sha512-QoLGEgPff03ad/L66P91ci5Zmf7Woq8bh4H5XT3+D5annlrPH5ObHf2Yvo53eDQaDkQtF9tJwMKSWANGXDmwUA==
dependencies:
node-gyp-build-optional-packages "5.0.3"
optionalDependencies:
"@cbor-extract/cbor-extract-darwin-arm64" "2.0.0"
"@cbor-extract/cbor-extract-darwin-x64" "2.0.0"
"@cbor-extract/cbor-extract-linux-arm" "2.0.0"
"@cbor-extract/cbor-extract-linux-arm64" "2.0.0"
"@cbor-extract/cbor-extract-linux-x64" "2.0.0"
"@cbor-extract/cbor-extract-win32-x64" "2.0.0"
cbor-x@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/cbor-x/-/cbor-x-1.4.1.tgz#1cada332cf5b7d1f940b494c0e88f2f1439bbcf3"
integrity sha512-qp6nM61RaamDJWsDGHzMIQ4+XBtg7/QIoBi5Lra4IDU65eP8lHcgkkJ9t2yIU8EvRThBfFCh6+S1Qkrmq93J3Q==
optionalDependencies:
cbor-extract "^2.0.2"
chai@^4.3.6:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
@@ -13955,11 +13904,6 @@ node-forge@^1:
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==
[email protected]:
version "5.0.3"
resolved "https://registry.yarnpkg.com/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.0.3.tgz#92a89d400352c44ad3975010368072b41ad66c17"
integrity sha512-k75jcVzk5wnnc/FMxsf4udAoTEUv2jY3ycfdSd3yWu6Cnd1oee6/CfZJApyscA4FJOmdoixWwiwOyf16RzD5JA==
node-gyp-build@^4.2.0, node-gyp-build@^4.3.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.5.0.tgz#7a64eefa0b21112f89f58379da128ac177f20e40"