1.0.1 • Published 6 months ago

@didhubdev/sdk v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

didhub-sdk

DIDhub SDK

Installation

Install with npm

npm install @didhubdev/sdk

Install with yarn

yarn add @didhubdev/sdk

Deployed Smart Contracts

contract namechainaddressfee
Batch RegisterBSC0x35580f058022d7BA612D1ba31CedFaCC019091a910%
Batch RegisterARBITRUM0x2ce430A5e124308e3D6CAEcA392ed3AB03c74DE110%
Batch RegisterFANTOM0x2ce430A5e124308e3D6CAEcA392ed3AB03c74DE110%
Batch RegisterETHEREUM0xD7356f1FC4acc3557cA5E213D3f467FdAeC0140f10%
Batch TransferBSC0x62D09c810F0AD579E4fbcD8f60d6cD6a487e56460%
Batch TransferARBITRUM0x5950286105FEe78216EB51eBEFb8c188A42A5B1b0%
Batch TransferFANTOM0xB6A819c02EAddbdAe4C7e9912029B77bE03A20680%
Batch TransferETHEREUM0xefb0Cf219C4FCF22132d2C3330970A1Ff29AC0B70%
Batch TransferPOLYGON0x9610fDdF5721e9d727d82bE318b864eC7d4967c70%
Batch TransferAVALANCHE0x700d05ae51Da2C00E6FeeC912AbaF208B24De0aA0%
Batch ENS ManagerETHEREUM0x373e91FbF9Ac403BcBAb680A1349e767FB87E57B0%

Usage

This SDK primarily exposes a clean interface to the DIDhub smart contracts that enable batch operation on domain registration, renewal and management for public use. These functions are already integrated into the DIDhub official website. Detail examples are provided in the example/script folder for testing.

The SDK also contains logic that involves batch list, offer and purchase of domains on Opensea. However such functions are currently limited for use only on the DIDhub official website.

Initalise SDK

const sdk = new DIDhubSDK(signer, secret);

signer, e.g. metamask signer \

secret is any 32 bytes hash. It creates uncertainly in the commit process. It is recommended to generate one for each user. This variable is optional

Inputs for Domain Name Registration

const domains = [
    {
        collectionInfo: "BNB:0xe3b1d32e43ce8d658368e2cbff95d57ef39be8a6",
        nameKey: "SpaceId:bnb.xxxyyyzzz",
        duration: 31536000 // 1 year
    }
];
const margin = 3; // 3%
const paymentToken = ZERO_ADDRESS;

domains is a list of domain information that contains the collectionInfo (${chain}:${contractAddress}), nameKey, and duration. \ margin is the slipage of the swap. Put 0 if you are certain that no token swap will take place \ paymentToken is the token to pay for the domain. Supported tokens are listed below: | chain | token symbol | address | | --- | --- | --- | | BSC | Native | 0x0000000000000000000000000000000000000000 | | BSC | WBNB | 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c | | BSC | USDC | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d | | ARBITRUM | Native | 0x0000000000000000000000000000000000000000 | | ARBITRUM | WBNB | 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 | | ARBITRUM | USDC | 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8 |

Functions to interact with the DIDHUB batch registration contract

Please follow the following steps to purchase domains in bulk with the DIDHUB contract. See ./test/index.ts for a comphrensive flow of domain purchase.

Check Domain Availability

const availabilityStatus = await sdk.register.batchCheckAvailability(domains);

Check Commit Status

There are 5 different commit status types:

  • 0: not exist, requires commit
  • 1: available but before minCommitmentAge
  • 2: available and after minCommitmentAge and before maxCommitmentAge, or does not require commitment
  • 3: available and after maxCommitmentAge, requires commit
  • 4: commit not required
const commitmentStatus = await sdk.register.batchCheckCommitment(domains);

Get Individual Price for the domain names

const individualPrices = await sdk.register.getIndividualPrice(domains);

Get Commit Data

Obtain the data that will be used as input to the commit function

const commitmentInfos = await sdk.register.batchMakeCommitments(domains);

Commit the domain names on chain

A on-chain transaction to commit the domain names. Wait 10 seconds at least of the commit transaction as required by Space Id

const commitTx = await sdk.register.batchCommit(commitmentInfos);
await commitTx.wait();

Get Domain Purchase Data

Below is the function to obtain the data input for the batchRegister function.

const registrationData = await sdk.register.getPriceWithMargin(domains, paymentToken, margin)

Get Supported token list

cont tokenList = await sdk.register.getSupportedTokens()

Check ERC20 token balance

const balance = await sdk.register.getERC20balance(tokenAddress)

Approve ERC20 tokens if necessary

If you want to purchase the domains with tokens that are different from the type specified by the domain name project, you need to approve the DIDhub contract to take custody of your tokens, perform swapping and purchase the domain on your behalf

const approveTx = await sdk.register.approveERC20Tokens(paymentToken, amount);
await approveTx.wait()

Final Check before Register

This function does a final check on all conditions, such as availability, commit statuses, token balance, token approval. It is recommended to use the function before Batch Register

const finalCheck = await sdk.register.checkPurchaseConditions(domains, registrationData.paymentToken, registrationData.paymentMax);

The return variable contains the followings

success //whether the transaction will suceed
availabilityStatus //A list containing the availability status of the domains to the input domain list
commitmentStatus //A list containing the commitment status of the domains from the input domain list
errors //A list of error message if something is not right

Batch Register

Use the registration data as input for the purchase. The SDK will handle cases of both native tokens and ERC20 tokens.

const registerTx = await sdk.register.batchRegister(registrationData.requests, registrationData.paymentToken, registrationData.paymentMax);

Batch Transfer NFT Functions

Check Fixed Fees

Check the amount of fixed fees charged by DIDHUB to use the smart contracts (zero at the moment)

const fixedFee = await sdk.transfer.getFixedFee();

Check Approval

Batch Check whether the didhub contract is given the approval

const isApprovedForTransfer: boolean[] = await sdk.transfer.batchCheckApproval(domainInfos);

Batch Make Approval

Batch make approval

await sdk.transfer.approveAllDomains(domainInfos);

Batch Transfer

Batch transfer the domains to a newOwner

const transferTx = await sdk.transfer.batchTransfer(domainInfos, newOwner);

Batch ENS Domain Management

Batch Manage the ENS Domain name

Check Fixed Fees

Check the amount of fixed fees charged by DIDHUB to use the smart contracts (zero at the moment)

const fixedFee = await sdk.ens.getFixedFee();

Batch Check Wraped Status

Check the wrap status: true is wrapped, and false is unwrapped

const wrapStatus = await sdk.ens.batchCheckWrapStatus(nameKeys);

Batch Check Owner Status

Check the owner status of the unwrapped domain by calling ownerOf functions of the Base Imeplementation contract

const ownerStatus = await sdk.ens.batchCheckUnwrappedETH2LDOwnerStatus(nameKeys);

Batch Check Name Wrapper Owner Status

Check the owner status of the wrapped domain by calling ownerOf functions of the Name Wrapper contract

const ownerStatus = await sdk.ens.batchCheckWrappedETH2LDOwnerStatus(nameKeys);

Batch Check Approval

Check whether the user has given approve to the DIDHUB contract for unwrapped domains

const isApprovedForWrap = await sdk.ens.batchCheckUnwrappedETH2LDApproval(nameKeys);

Batch Check Name Wrapper Approval

Check whether the user has given approve to the DIDHUB contract for wrapped domains

const isApprovedForWrap = await sdk.ens.batchCheckWrappedETH2LDApproval(nameKeys);

Batch Approve unwrapped domain

Approve the DIDHUB contract to operate on the unwrapped domains

const approvalTx = await sdk.ens.approveUnwrappedETH2LDDomains(nameKeys);

Batch Approve wrapped domain

Approve the DIDHUB contract to operate on the wrapped domains

const approvalTx = await sdk.ens.approveWrappedETH2LDDomains();

Batch Wrap

Batch wrap the domain. Fee is paid internally

const wrapTx = await sdk.ens.batchWrap(nameKeys);

Batch Unwrap

Batch unwrap the domain. Fee is paid internally

const wrapTx = await sdk.ens.batchUnwrap(nameKeys);

Functions to interact with Opensea (Not for public use)

Supported Chains: BNB, ARBITRUM, POLYGON

Make Offer

Note that it is not possible to offer native token. \ Approval process is automatically handled.

const data = await sdk.opensea.offerDomain(domainInfo, paymentToken, amount, days);

Batch Make Offers

Batch offer an array of domains

const data = await sdk.opensea.bulkOfferDomain(offerDataArray);

where offerDataArray is given as follows

const offerDataArray = {
    domainInfo: domainInfo,
    paymentToken: paymentToken,
    amount: amount, 
    days: days
}

List Domain

Approval is automatically handled.

const data = await sdk.opensea.listDomain(domainInfo, paymentToken, amount, days);

Batch List Domain

Batch list an array of domains

const data = await sdk.opensea.bulkListDomain(listingDataArray);

where listingDataArray is given as follows

const listingDataArray = {
    domainInfo: domainInfo,
    paymentToken: paymentToken,
    amount: amount, 
    days: days
}

Accept Offer

const tx = await sdk.opensea.fulfillOffer(orderId);

Fulfill Listing

const tx = await sdk.opensea.fulfillListing(orderId);

Cancel Order

This can take in an array of both offer or listing orders

const tx = await sdk.opensea.cancelOrders(orderIds);

Fulfill Multiple Listings

Fulfill multiple listings in one transaction, using a single token type as input. If the orders require payment of different token types, the input tokens will be swapped to the targe token type. There are 3 steps to complete this operation:

  1. Obtain the advanced order information using orderId. It is recommended to do this at the time when users add items to cart, instead of doing it in one go during checkout.
const advancedOrders = await sdk.opensea.getAdvancedOrders(orderIds);
  1. Before transaction, the user will choose a token type to complete the purchase, and select the slippage that he/she will toleration in case the target price cannot be met.
const swapInfo = await sdk.opensea.getSwapInfo(advancedOrders, paymentToken, margin);
  1. Approve the DIDHub for the amount of token that will be used in the purchase if needded
const approveTx = await sdk.opensea.approveERC20Tokens(paymentToken, swapInfo.paymentMax);
  1. Finally, complete the transaction with the obtained in the previous functions
const purchaseTx = await sdk.opensea.fulfillListings(advancedOrders, swapInfo);
0.2.27

8 months ago

0.2.26

8 months ago

0.2.25

8 months ago

0.2.24

8 months ago

0.2.23

8 months ago

0.2.22

9 months ago

0.2.21

9 months ago

0.2.20

9 months ago

0.2.19

9 months ago

0.2.18

9 months ago

0.2.17

9 months ago

0.2.16

9 months ago

0.2.15

9 months ago

0.2.14

9 months ago

0.2.13

9 months ago

0.2.12

9 months ago

0.2.11

9 months ago

0.2.10

9 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.1.90

9 months ago

0.1.85

9 months ago

0.1.86

9 months ago

0.1.87

9 months ago

0.1.88

9 months ago

0.1.89

9 months ago

0.1.81

9 months ago

0.1.83

9 months ago

0.1.84

9 months ago

0.1.74

9 months ago

0.1.75

9 months ago

0.1.76

9 months ago

0.1.77

9 months ago

0.1.78

9 months ago

0.1.79

9 months ago

0.1.70

11 months ago

0.1.71

9 months ago

0.1.72

9 months ago

0.1.73

9 months ago

0.2.30

7 months ago

0.1.69

11 months ago

0.2.38

6 months ago

0.2.37

6 months ago

0.2.36

6 months ago

0.2.35

6 months ago

0.2.34

6 months ago

0.2.33

7 months ago

0.2.32

7 months ago

0.2.31

7 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.2.29

7 months ago

0.2.28

7 months ago

0.2.7

9 months ago

0.2.6

9 months ago

0.2.9

9 months ago

0.2.8

9 months ago

0.2.3

9 months ago

0.2.2

9 months ago

0.2.5

9 months ago

0.2.4

9 months ago

0.1.68

11 months ago

0.1.66

11 months ago

0.1.67

11 months ago

0.1.65

11 months ago

0.1.64

11 months ago

0.1.63

11 months ago

0.1.62

11 months ago

0.1.61

11 months ago

0.1.60

11 months ago

0.1.59

11 months ago

0.1.58

11 months ago

0.1.57

11 months ago

0.1.56

11 months ago

0.1.55

11 months ago

0.1.54

11 months ago

0.1.53

11 months ago

0.1.51

11 months ago

0.1.50

11 months ago

0.1.49

11 months ago

0.1.48

11 months ago

0.1.47

11 months ago

0.1.46

11 months ago

0.1.45

11 months ago

0.1.44

11 months ago

0.1.43

11 months ago

0.1.42

11 months ago

0.1.41

11 months ago

0.1.40

11 months ago

0.1.39

11 months ago

0.1.38

11 months ago

0.1.37

12 months ago

0.1.36

12 months ago

0.1.35

12 months ago

0.1.34

12 months ago

0.1.33

12 months ago

0.1.32

12 months ago

0.1.31

12 months ago

0.1.30

12 months ago

0.1.29

12 months ago

0.1.28

12 months ago

0.1.27

12 months ago

0.1.26

12 months ago

0.1.25

12 months ago

0.1.24

12 months ago

0.1.23

12 months ago

0.1.22

12 months ago

0.1.21

12 months ago

0.1.20

12 months ago

0.1.19

12 months ago

0.1.18

12 months ago

0.1.17

12 months ago

0.1.16

12 months ago

0.1.15

12 months ago

0.1.14

12 months ago

0.1.13

12 months ago

0.1.12

12 months ago

0.1.11

12 months ago

0.1.10

12 months ago

0.1.9

12 months ago

0.1.8

12 months ago

0.1.7

12 months ago

0.1.6

12 months ago

0.1.5

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago

0.0.53

12 months ago

0.0.52

12 months ago

0.0.51

12 months ago

0.0.50

12 months ago

0.0.49

12 months ago

0.0.47

12 months ago

0.0.46

12 months ago

0.0.45

12 months ago

0.0.44

12 months ago

0.0.43

12 months ago

0.0.42

12 months ago

0.0.41

12 months ago

0.0.40

12 months ago

0.0.39

12 months ago

0.0.38

12 months ago

0.0.37

12 months ago

0.0.36

12 months ago

0.0.35

12 months ago

0.0.34

12 months ago

0.0.33

12 months ago

0.0.32

12 months ago

0.0.31

12 months ago

0.0.30

12 months ago

0.0.29

12 months ago

0.0.28

12 months ago

0.0.27

12 months ago

0.0.26

12 months ago

0.0.25

12 months ago

0.0.24

12 months ago

0.0.23

12 months ago

0.0.22

12 months ago

0.0.21

12 months ago

0.0.20

12 months ago

0.0.19

12 months ago

0.0.18

12 months ago

0.0.16

12 months ago

0.0.13

12 months ago

0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

1 year ago