-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from walt-id/feat/soulboundNFT
Feat/soulbound nft
- Loading branch information
Showing
13 changed files
with
726 additions
and
9 deletions.
There are no files selected for viewing
459 changes: 459 additions & 0 deletions
459
src/main/java/smart_contract_wrapper/SoulBoundTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/id/walt/nftkit/chains/evm/erc721/ISoulBoundTokenStandard.kt
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,29 @@ | ||
package id.walt.nftkit.chains.evm.erc721 | ||
import id.walt.nftkit.services.Chain | ||
import id.walt.nftkit.services.EVMChain | ||
import org.web3j.abi.datatypes.Address | ||
import org.web3j.abi.datatypes.Bool | ||
import org.web3j.abi.datatypes.DynamicBytes | ||
import org.web3j.abi.datatypes.Utf8String | ||
import org.web3j.abi.datatypes.generated.Uint256 | ||
import org.web3j.protocol.core.RemoteFunctionCall | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt | ||
import java.math.BigInteger | ||
interface ISoulBoundTokenStandard { | ||
|
||
fun safeMint(chain: EVMChain, contractAddress: String,to: String, uri: String): TransactionReceipt? | ||
fun ownerOf(chain: EVMChain, contractAddress: String, tokenId: Uint256):String? | ||
|
||
fun name(chain: EVMChain, contractAddress: String): String? | ||
|
||
fun symbol(chain: EVMChain, contractAddress: String): String? | ||
|
||
fun tokenURI(chain: EVMChain, contractAddress: String, tokenId: Uint256): String? | ||
|
||
fun balanceOf(chain: EVMChain, contractAddress: String, owner: Address): BigInteger? | ||
|
||
fun safeTransferFrom(chain: EVMChain, contractAddress: String, from: Address, to: Address, tokenId: Uint256, signedAccount: String?): TransactionReceipt | ||
|
||
fun supportsInterface(chain: EVMChain, contractAddress: String): Boolean | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
src/main/kotlin/id/walt/nftkit/chains/evm/erc721/SoulBoundTokenStandard.kt
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,133 @@ | ||
package id.walt.nftkit.chains.evm.erc721 | ||
|
||
import id.walt.nftkit.Values | ||
import id.walt.nftkit.WaltIdGasProvider | ||
import id.walt.nftkit.services.* | ||
import id.walt.nftkit.utilis.providers.ProviderFactory | ||
import org.web3j.abi.datatypes.Address | ||
import org.web3j.abi.datatypes.generated.Bytes4 | ||
import org.web3j.abi.datatypes.generated.Uint256 | ||
import org.web3j.crypto.Credentials | ||
import org.web3j.protocol.core.RemoteCall | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt | ||
import org.web3j.tx.RawTransactionManager | ||
import org.web3j.tx.TransactionManager | ||
import org.web3j.tx.gas.ContractGasProvider | ||
import org.web3j.utils.Numeric | ||
import smart_contract_wrapper.SoulBoundTest | ||
import java.math.BigInteger | ||
|
||
object SoulBoundTokenStandard : ISoulBoundTokenStandard { | ||
|
||
|
||
|
||
|
||
|
||
|
||
private fun loadContract(chain: EVMChain, address: String, signedAccount: String? ="") : SoulBoundTest { | ||
val web3j = ProviderFactory.getProvider(chain)?.getWeb3j() | ||
|
||
val privateKey: String = if(signedAccount == null || "" == (signedAccount)){ | ||
WaltIdServices.loadChainConfig().privateKey | ||
}else{ | ||
val lowercaseAddress= WaltIdServices.loadAccountKeysConfig().keys.mapKeys { it.key.lowercase() } | ||
lowercaseAddress[signedAccount.lowercase()]!! | ||
} | ||
|
||
val credentials: Credentials = Credentials.create(privateKey) | ||
|
||
val gasProvider: ContractGasProvider = WaltIdGasProvider | ||
val chainId= when(chain){ | ||
EVMChain.ETHEREUM -> Values.ETHEREUM_MAINNET_CHAIN_ID | ||
EVMChain.GOERLI -> Values.ETHEREUM_TESTNET_GOERLI_CHAIN_ID | ||
EVMChain.SEPOLIA -> Values.ETHEREUM_TESTNET_SEPOLIA_CHAIN_ID | ||
EVMChain.POLYGON -> Values.POLYGON_MAINNET_CHAIN_ID | ||
EVMChain.MUMBAI -> Values.POLYGON_TESTNET_MUMBAI_CHAIN_ID | ||
EVMChain.ASTAR -> Values.ASTAR_MAINNET_CHAIN_ID | ||
EVMChain.MOONBEAM -> Values.MOONBEAM_MAINNET_CHAIN_ID | ||
EVMChain.SHIMMEREVM -> Values.SHIMMEREVM_TESTNET_CHAIN_ID | ||
} | ||
val transactionManager: TransactionManager = RawTransactionManager( | ||
web3j, credentials, chainId | ||
) | ||
return SoulBoundTest.load(address, web3j,transactionManager,gasProvider) | ||
|
||
} | ||
|
||
|
||
override fun ownerOf(chain: EVMChain, contractAddress: String, tokenId: Uint256): String? { | ||
return loadContract(chain, contractAddress).ownerOf(tokenId).send().value | ||
} | ||
|
||
override fun name(chain: EVMChain, contractAddress: String): String? { | ||
val contract = loadContract(chain, contractAddress) | ||
return contract.name().send().value | ||
} | ||
|
||
override fun symbol(chain: EVMChain, contractAddress: String): String? { | ||
return loadContract(chain, contractAddress).symbol().send().value | ||
} | ||
|
||
override fun tokenURI(chain: EVMChain, contractAddress: String, tokenId: Uint256): String? { | ||
return loadContract(chain, contractAddress).tokenURI(tokenId).send().value | ||
} | ||
|
||
override fun balanceOf(chain: EVMChain, contractAddress: String, owner: Address): BigInteger? { | ||
return loadContract(chain, contractAddress).balanceOf(owner).send().value | ||
} | ||
|
||
override fun safeTransferFrom( | ||
chain: EVMChain, | ||
contractAddress: String, | ||
from: Address, | ||
to: Address, | ||
tokenId: Uint256, | ||
signedAccount: String? | ||
): TransactionReceipt { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun safeMint(chain: EVMChain, contractAddress: String, to: String, uri: String): TransactionReceipt? { | ||
return loadContract(chain, contractAddress).safeMint(to, uri).send() | ||
} | ||
|
||
|
||
fun deployContract(chain: EVMChain) : DeploymentResponse { | ||
val chainId= when(chain){ | ||
EVMChain.ETHEREUM -> Values.ETHEREUM_MAINNET_CHAIN_ID | ||
EVMChain.GOERLI -> Values.ETHEREUM_TESTNET_GOERLI_CHAIN_ID | ||
EVMChain.SEPOLIA -> Values.ETHEREUM_TESTNET_SEPOLIA_CHAIN_ID | ||
EVMChain.POLYGON -> Values.POLYGON_MAINNET_CHAIN_ID | ||
EVMChain.MUMBAI -> Values.POLYGON_TESTNET_MUMBAI_CHAIN_ID | ||
EVMChain.ASTAR -> Values.ASTAR_MAINNET_CHAIN_ID | ||
EVMChain.MOONBEAM -> Values.MOONBEAM_MAINNET_CHAIN_ID | ||
EVMChain.SHIMMEREVM -> Values.SHIMMEREVM_TESTNET_CHAIN_ID | ||
} | ||
|
||
val web3j = ProviderFactory.getProvider(chain)?.getWeb3j() | ||
val credentials: Credentials = Credentials.create(WaltIdServices.loadChainConfig().privateKey) | ||
val gasProvider: ContractGasProvider = WaltIdGasProvider | ||
val remotCall: RemoteCall<SoulBoundTest> | ||
val transactionManager: TransactionManager = RawTransactionManager( | ||
web3j, credentials, chainId | ||
) | ||
remotCall = SoulBoundTest.deploy(web3j, transactionManager, gasProvider) | ||
|
||
val contract = remotCall.send() | ||
|
||
val url = WaltIdServices.getBlockExplorerUrl(chain) | ||
val ts = TransactionResponse( | ||
contract.transactionReceipt.get().transactionHash, | ||
"$url/tx/${contract.transactionReceipt.get().transactionHash}" | ||
) | ||
return DeploymentResponse(ts, contract.contractAddress, "$url/address/${contract.contractAddress}") | ||
} | ||
|
||
|
||
override fun supportsInterface(chain: EVMChain, contractAddress: String) : Boolean { | ||
val erc721URIStorageWrapper = loadContract(chain, contractAddress) | ||
val data = Numeric.hexStringToByteArray("0x5b5e139f") // ERC721 interface id | ||
val interfaceId = Bytes4(data) | ||
return erc721URIStorageWrapper.supportsInterface(interfaceId).send().value | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/id/walt/nftkit/utilis/providers/IotaWeb3.kt
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,11 @@ | ||
package id.walt.nftkit.utilis.providers | ||
|
||
import id.walt.nftkit.services.WaltIdServices | ||
import org.web3j.protocol.Web3j | ||
import org.web3j.protocol.http.HttpService | ||
|
||
class IotaWeb3 : Web3jInstance { | ||
override fun getWeb3j(): Web3j { | ||
return Web3j.build(HttpService(WaltIdServices.loadChainConfig().providers.shimmerevm)) | ||
} | ||
} |
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.