Skip to content

Commit

Permalink
feat: new test
Browse files Browse the repository at this point in the history
  • Loading branch information
wellitongervickas committed Nov 30, 2023
1 parent 44b3f7b commit 64eadfb
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 14 deletions.
5 changes: 2 additions & 3 deletions config/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const polygonMumbai: Chain = {
nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
rpcUrls: {
protocol: {
http: [process.env.PUBLIC_NETWORK_80001_HTTP_RPC!]
http: ['https://rpc.ankr.com/polygon_mumbai']
},
infura: {
http: ['https://polygon-mumbai.infura.io/v3']
Expand Down Expand Up @@ -76,8 +76,7 @@ export const polygonMumbai: Chain = {
blockCreated: 0
}
},
testnet: true,
gasPrice: 210000
testnet: true
}

export const optimismGoerli: Chain = {
Expand Down
2 changes: 2 additions & 0 deletions contracts-left.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ pnpm hardhat setup-bridge-adapter --network 80001 --bridge-address 0x96D103BCb67
=========================

pnpm hardhat deploy-test-nft-contract --network 80001 --token-name "hello" --token-symbol "world" --bridge-address 0x96D103BCb675945DE9C51D9dCa57a14593a54558 --adapter-address 0xBd770416a3345F91E4B34576cb804a576fa48EB1 --target-network 43113

pnpm hardhat deploy-test-nft-contract --network 80001 --token-name "hello" --token-symbol "world" --bridge-address 0x96D103BCb675945DE9C51D9dCa57a14593a54558 --adapter-address 0xBd770416a3345F91E4B34576cb804a576fa48EB1 --target-network 43113 --nft-address 0x7634f8DF9d00C1A445062D908aB129BE65DF7AB9 --token-id 1
24 changes: 13 additions & 11 deletions tasks/deploy-test-nft-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,25 @@ task('deploy-test-nft-contract', 'deploy nft contract')
`ℹ️ Deploying new NFT ${tokenName} with symbol ${tokenSymbol} to ${chainConfig.id}`
)

const tokenId = 1
try {
const tokenId = 1

const nft = await hre.ethers.deployContract('MockNFT', [
tokenName,
tokenSymbol
])
const nft = await hre.ethers.deployContract('MockNFT', [
tokenName,
tokenSymbol
])

const [deployer] = await hre.ethers.getSigners()
const [deployer] = await hre.ethers.getSigners()

await nft.waitForDeployment()
const tx = await nft.mint(tokenId)
await nft.waitForDeployment()
const tx = await nft.mint(tokenId)

await tx.wait()
await tx.wait()

const nftAddress = await nft.getAddress()
const nftAddress = await nft.getAddress()

console.log('ℹ️ NFT deployed', nftAddress)

try {
const bridge = await hre.ethers.getContractAt('Bridge', bridgeAddress)

const adapter = await hre.ethers.getContractAt(
Expand Down
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import './deploy-adapter-contract'
import './set-chain-settings'
import './setup-bridge-adapter'
import './deploy-test-nft-contract'
import './test-nft-contracts'
113 changes: 113 additions & 0 deletions tasks/test-nft-contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { task } from 'hardhat/config'
import { Spinner } from '../scripts/spinner'
import cliSpinner from 'cli-spinners'
import { allowedChainsConfig } from '@/config/config'
import { RampType } from './set-chain-settings'

const spinner: Spinner = new Spinner(cliSpinner.triangle)

export type DeployTestNFTContractTask = {
tokenName: string
tokenSymbol: string
bridgeAddress: string
adapterAddress: string
targetNetwork: number
nftAddress: string
tokenId: number
}

task('test-nft-contract', 'deploy nft contract')
.addParam('tokenName', 'token name')
.addParam('tokenSymbol', 'token symbol')
.addParam('bridgeAddress', 'bridge address')
.addParam('adapterAddress', 'adapter address')
.addParam('targetNetwork', 'target network')
.addParam('nftAddress', 'nft address')
.addParam('tokenId', 'token id')
.setAction(
async (
{
nftAddress,
tokenName,
tokenSymbol,
bridgeAddress,
targetNetwork,
adapterAddress,
tokenId
}: DeployTestNFTContractTask,
hre
) => {
spinner.start()
const chainConfig = allowedChainsConfig[+hre.network.name]
if (!chainConfig) throw new Error('Chain config not found')

console.log(
`ℹ️ Deploying new NFT ${tokenName} with symbol ${tokenSymbol} to ${chainConfig.id}`
)

try {
const nft = await hre.ethers.getContractAt('MockNFT', nftAddress)
const [deployer] = await hre.ethers.getSigners()
const bridge = await hre.ethers.getContractAt('Bridge', bridgeAddress)

const adapter = await hre.ethers.getContractAt(
'CCIPAdapter',
adapterAddress
)

const abiCoder = hre.ethers.AbiCoder.defaultAbiCoder()

const targetChainSettings = await bridge.getChainSettings(
targetNetwork,
RampType.OnRamp
)

const payload = {
toChain: targetChainSettings.nonEvmChainId,
receiver: targetChainSettings.adapter,
gasLimit: targetChainSettings.gasLimit,
data: abiCoder.encode(
['address', 'bytes', 'bytes'],
[
deployer.address,
abiCoder.encode(
['uint256', 'address', 'uint256'],
[chainConfig.id, nftAddress, tokenId]
),
abiCoder.encode(
['string', 'string', 'string'],
[tokenName, tokenSymbol, await nft.tokenURI(tokenId)]
)
]
)
}

console.log('ℹ️ Getting required fee')
const fee = await adapter.getFee(payload)
console.log('ℹ️ Feee', fee)

console.log('ℹ️ Approving')
const tx2 = await nft.approve(bridgeAddress, tokenId)
await tx2.wait()
console.log('ℹ️ Approved')

await bridge.sendERC721(
targetChainSettings.evmChainId,
nftAddress,
tokenId,
{
value: fee + 2560000n
}
)

const nftOwner = await nft.ownerOf(tokenId)

spinner.stop()
console.log(`✅ NFT deployed and transfered to ${nftOwner}`)
} catch (error) {
spinner.stop()
console.log(`❌ NFT deploy failed`)
console.log(error)
}
}
)

0 comments on commit 64eadfb

Please sign in to comment.