-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into manifold
- Loading branch information
Showing
13 changed files
with
261 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ALCHEMY_API_KEY= | ||
SIMULATE_DURING_TESTS=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Alchemy, BigNumber, Network, Utils } from "alchemy-sdk"; | ||
import { EVMMintInstructions } from "../types"; | ||
export const SIGNER1_WALLET = '0x965EF172b303B0BcdC38669DF1De3c26BAD2dB8a'; | ||
export const TEST_RECIPIENT = '0x0cc9601298361e844451a7e35e1d7fcd72750e47'; | ||
|
||
export const NETWORKS: Record<number, Network> = { | ||
1: Network.ETH_MAINNET, | ||
5: Network.ETH_GOERLI, | ||
137: Network.MATIC_MAINNET, | ||
42161: Network.ARB_MAINNET, | ||
80001: Network.MATIC_MUMBAI, | ||
8453: Network.BASE_MAINNET, | ||
84531: Network.BASE_GOERLI, | ||
11155111: Network.ETH_SEPOLIA | ||
}; | ||
|
||
export const simulateEVMTransactionWithAlchemy = async (mintInstructions: EVMMintInstructions, blockNumber?: string): Promise<{ message: string, success: boolean, rawSimulationResult: any }> => { | ||
const alchemy = new Alchemy({ | ||
apiKey: process.env.ALCHEMY_API_KEY, | ||
network: NETWORKS[mintInstructions.chainId], | ||
}); | ||
|
||
const abi = mintInstructions.abi; | ||
const iface = new Utils.Interface(abi); | ||
|
||
const paramsArray = prepareContractParams(mintInstructions.contractParams); | ||
|
||
const data = iface.encodeFunctionData(mintInstructions.contractMethod, paramsArray); | ||
|
||
const tx = { | ||
to: mintInstructions.contractAddress, | ||
from: SIGNER1_WALLET, | ||
data: data, | ||
value: BigNumber.from(mintInstructions.priceWei || '0').toHexString().replace('0x0', '0x'), | ||
}; | ||
|
||
const simResult = await alchemy.transact.simulateExecution(tx, blockNumber ? blockNumber : undefined); | ||
|
||
const failedCalls: any = simResult.calls.find((call) => call.error) || []; | ||
|
||
const message = failedCalls?.revertReason; | ||
const success = failedCalls.length === 0; | ||
|
||
if (!success) { | ||
console.log(`Error Simulating: ${message}, ${JSON.stringify(simResult)}`); | ||
} | ||
|
||
return { message, success, rawSimulationResult: simResult }; | ||
} | ||
|
||
export const prepareContractParams = (template: string): any[] => { | ||
const regex = /{{(\w+)}}|tokenId|address|encodedAddress/g; | ||
|
||
const replacedTemplate = template.replace(regex, (match) => { | ||
switch (match) { | ||
case 'address': | ||
return `"${TEST_RECIPIENT}"`; | ||
case 'encodedAddress': | ||
return `"${encodeAddress(TEST_RECIPIENT)}"`; | ||
default: | ||
return '""'; | ||
} | ||
}); | ||
|
||
return JSON.parse(replacedTemplate); | ||
}; | ||
|
||
export const encodeAddress = (address: string) => { | ||
const rawAddress = address.replace('0x', ''); | ||
|
||
return '0x' + rawAddress.padStart(64, '0'); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clones/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then | ||
echo "Usage: $0 <git-url> [branch-name]" | ||
exit 1 | ||
fi | ||
|
||
# if the URL is of the format https://github.com/pbkompasz/mobile-minting/tree/ingestor-highlight then pull both the branch name and the repo name | ||
if [[ $1 == *"tree"* ]]; then | ||
BRANCH_NAME=$(echo $1 | cut -d'/' -f7) | ||
REPO_NAME=$(echo $1 | cut -d'/' -f5) | ||
|
||
# remove the tree part from the URL | ||
GIT_URL=$(echo $1 | cut -d'/' -f1-5) | ||
GIT_URL="$GIT_URL" | ||
else | ||
GIT_URL=$1 | ||
BRANCH_NAME=${2:-main} | ||
fi | ||
|
||
echo "GIT_URL: $GIT_URL" | ||
echo "BRANCH_NAME: $BRANCH_NAME" | ||
|
||
ORG_NAME=$(basename $(dirname $GIT_URL) .git) | ||
|
||
echo "ORG_NAME: $ORG_NAME" | ||
|
||
cd clones | ||
|
||
# if the folder name exists, delete it | ||
if [ -d $ORG_NAME ]; then | ||
rm -rf $ORG_NAME | ||
fi | ||
|
||
# Clone the fork into a directory with the name of the organization the fork is in | ||
git clone $GIT_URL $ORG_NAME | ||
cd $ORG_NAME | ||
|
||
# Move to the specified branch | ||
git checkout $BRANCH_NAME | ||
|
||
# Install dependencies | ||
yarn install | ||
|
||
# Add the floornfts/mobile-minting repo as a remote "floor" | ||
git remote add floor https://github.com/floornfts/mobile-minting.git | ||
|
||
# Fetch the remote "floor" | ||
git fetch floor | ||
|
||
# Merge main from "floor" into the current branch | ||
git merge floor/main --no-edit | ||
|
||
# copy the .env.example file to .env | ||
cp ../../../../.env .env | ||
|
||
# Run tests | ||
yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.