Skip to content

Commit

Permalink
feat: auto add name, decimals and symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Apr 3, 2024
1 parent 0135f6e commit 72d8b31
Show file tree
Hide file tree
Showing 150 changed files with 496 additions and 756 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Token-registry is a platform where you can submit the token. Token-registry will
## Requirements
1. Make sure the contract address is correct (main/test)
2. Token image is required
3. Folder name must be the same as the contract address
4. Clear and simple description
3. Folder name must be the same as the contract address in lowercase
4. Clear and simple description
5. Comply with directory & contents rules

## Getting Ready for Submission
Expand All @@ -33,9 +33,6 @@ Forking a repository allows you to create your token details and send a pull req

```
{
"name": "VeThor",
"symbol": "VTHO",
"decimals":18,
"desc": "Represents the underlying cost of using VeChainThor"
}
```
Expand Down
71 changes: 54 additions & 17 deletions contract.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
const abis = require("./abis");
const { abi } = require("thor-devkit");
const { abi, address } = require("thor-devkit");
const axios = require("axios");

const contractCalls = [
new abi.Function(abis.totalSupply).encode(),
new abi.Function(abis.balanceOf).encode(
"0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa",
),
new abi.Function(abis.allowance).encode(
const totalSupplyAbi = new abi.Function(abis.totalSupply);
const balanceOfAbi = new abi.Function(abis.balanceOf);
const allowanceAbi = new abi.Function(abis.allowance);
const decimalsAbi = new abi.Function(abis.decimals);
const nameAbi = new abi.Function(abis.name);
const symbolAbi = new abi.Function(abis.symbol);

const verifyCalls = [
balanceOfAbi.encode("0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa"),
allowanceAbi.encode(
"0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa",
"0x435933c8064b4Ae76bE665428e0307eF2cCFBD68",
),
new abi.Function(abis.decimals).encode(),
new abi.Function(abis.name).encode(),
new abi.Function(abis.symbol).encode(),
];

/**
*
* @param {string} address The contract address
* @param {string} url The node url
*/

const verifyContract = async (address, url) => {
try {
const clauses = contractCalls.map((data) => ({
const clauses = verifyCalls.map((data) => ({
to: address,
data,
value: "0x0",
Expand All @@ -37,7 +34,7 @@ const verifyContract = async (address, url) => {
throw new Error("Some contract calls reverted");
}

if (resp.data.length !== contractCalls.length) {
if (resp.data.length !== verifyCalls.length) {
throw new Error("Invalid contract response");
}
} catch (error) {
Expand All @@ -46,6 +43,46 @@ const verifyContract = async (address, url) => {
}
};

const contractDetailsClauses = [
totalSupplyAbi.encode(),
decimalsAbi.encode(),
nameAbi.encode(),
symbolAbi.encode(),
];

const getContractDetails = async (address, url) => {
const clauses = contractDetailsClauses.map((data) => ({
to: address,
data,
value: "0x0",
}));

const resp = await axios.post(`${url}/accounts/*`, {
clauses,
});

if (resp.data.some((r) => r.reverted)) {
throw new Error("Some contract calls reverted");
}

if (resp.data.length !== contractDetailsClauses.length) {
throw new Error("Invalid contract response");
}

const totalSupply = totalSupplyAbi.decode(resp.data[0].data);
const decimals = decimalsAbi.decode(resp.data[1].data);
const name = nameAbi.decode(resp.data[2].data);
const symbol = symbolAbi.decode(resp.data[3].data);

return {
totalSupply: totalSupply["0"],
decimals: parseInt(decimals["0"]),
name: name["0"],
symbol: symbol["0"],
};
};

module.exports = {
verifyContract,
getContractDetails,
};
42 changes: 20 additions & 22 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { getTokens, redFont, greenFont, yellowFont } = require('./utils')

const { NETS: NET_FOLDERS, NODES } = require('./const')
const abis = require('./abis')
const { verifyContract } = require('./contract')
const { verifyContract, getContractDetails } = require('./contract')

const DIST = path.join(__dirname, './dist')
const ASSETS = path.join(DIST, 'assets')
Expand Down Expand Up @@ -54,18 +54,32 @@ async function packToken(net) {

file.mkdirSync(ASSETS)

for (const item of listJson) {
for (let i = 0; i < listJson.length; i++) {

const item = listJson[i]

const {
name,
symbol,
decimals,
totalSupply
} = await getContractDetails(item.address, NODES[net])

listJson[i].decimals = decimals
listJson[i].name = name
listJson[i].symbol = symbol

await verifyContract(item.address, NODES[net])

file.copyFileSync(item.img, path.join(ASSETS, `${item.imgName}`))
result.push({
name: item.name,
symbol: item.symbol,
decimals: item.decimals,
name,
symbol,
decimals,
address: item.address,
desc: item.desc,
icon: item.imgName,
totalSupply: item.symbol === 'VTHO' ? 'Infinite' : await getTotalSupply(NODES[net], item.address),
totalSupply: item.symbol === 'VTHO' ? 'Infinite' : totalSupply,
...item.extra
})
}
Expand Down Expand Up @@ -177,22 +191,6 @@ async function getCreateTimeFromGit(dirPath) {
})
}

async function getTotalSupply(url, address) {
const resp = await axios.post(`${url}/accounts/*`, {
clauses: [
{
to: address,
value: '0',
data: '0x18160ddd'
}
]
})
let tsf = new abi.Function(abis.totalSupply)
const decoded = tsf.decode(resp.data[0]['data'])

return decoded[0]
}

module.exports = {
clean: clear,
build: packToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"website":"https://www.vechain.org/",
"links":{
"twitter":"https://twitter.com/vechaindev",
"medium":"https://medium.com/@vechainofficial",
"github":"https://github.com/vechain"
},
"whitePaper":"https://www.vechain.org/whitepaper/"
}
"website": "https://www.vechain.org/",
"links": {
"twitter": "https://twitter.com/vechaindev",
"medium": "https://medium.com/@vechainofficial",
"github": "https://github.com/vechain"
},
"whitePaper": "https://www.vechain.org/whitepaper/"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "VeThor",
"symbol": "VTHO",
"decimals": 18,
"desc": "Represents the underlying cost of using VeChainThor"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"website":"https://www.myvechain.com/",
"links":{
"twitter":"https://twitter.com/myvechain"
}
"website": "https://www.myvechain.com/",
"links": {
"twitter": "https://twitter.com/myvechain"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "MyVeChain",
"symbol": "MVC",
"decimals":18,
"desc": "Utility token for the myvechain.com community website"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"website":"https://www.odee.com/ ",
"links":{
"twitter":"https://twitter.com/VyvoSmartChain"
}
}
"website": "https://www.odee.com/ ",
"links": {
"twitter": "https://twitter.com/VyvoSmartChain"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "Vyvo US Dollar",
"symbol": "USDV",
"decimals": 6,
"desc": "A fiat-backed stablecoin redeemable 1-to-1 for U.S Dollar held in trust accounts."
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"website":"https://vexchange.io/",
"links":{
"twitter":"https://twitter.com/VexchangeIO",
"telegram":"https://t.me/vexchange",
"medium":"https://medium.com/@vexchange",
"github":"https://github.com/vexchange/"
"website": "https://vexchange.io/",
"links": {
"twitter": "https://twitter.com/VexchangeIO",
"telegram": "https://t.me/vexchange",
"medium": "https://medium.com/@vexchange",
"github": "https://github.com/vexchange/"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "Vexchange",
"symbol": "VEX",
"decimals": 18,
"desc": "Governance Token for the Vexchange Ecosystem"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "OceanEx",
"symbol": "OCE",
"decimals": 18,
"desc": "OceanEx Token (OCE) is OceanEx's platform token"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"website": "https://www.DragonsofSingapura.com/",
"links": {
"twitter": "https://twitter.com/Dragonsingapura",
"github": "https://github.com/Murtagh300"
}
}
{
"website": "https://www.DragonsofSingapura.com/",
"links": {
"twitter": "https://twitter.com/Dragonsingapura",
"github": "https://github.com/Murtagh300"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "Dragon Coin",
"symbol": "DRAGON",
"decimals": 18,
"desc": "The main currency used For Staking and evolving your Dragon egg. Dragons of Singapura. Will also be used for future nft drops within Singapura"
}
{
"desc": "The main currency used For Staking and evolving your Dragon egg. Dragons of Singapura. Will also be used for future nft drops within Singapura"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"website":"https://www.worldofv.art/",
"links":{
"twitter":"https://twitter.com/WorldOfV2",
"telegram":"https://t.me/worldofvofficial",
"medium":"https://medium.com/@WorldofV",
"github":""
},
"whitePaper":"https://medium.com/@WorldofV/world-of-v-tokenomics-the-beginning-of-our-journey-together-d428907c22af"
}

"website": "https://www.worldofv.art/",
"links": {
"twitter": "https://twitter.com/WorldOfV2",
"telegram": "https://t.me/worldofvofficial",
"medium": "https://medium.com/@WorldofV",
"github": ""
},
"whitePaper": "https://medium.com/@WorldofV/world-of-v-tokenomics-the-beginning-of-our-journey-together-d428907c22af"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "WorldOfV",
"symbol": "WoV",
"decimals": 18,
"desc": "WoV is the ecosystem utility and governance token of WorldOfV."
}
"desc": "WoV is the ecosystem utility and governance token of WorldOfV."
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"website":"https://www.madiniafricainvest.com/",
"links":{
"github":"https://github.com/Bluegate-BS"
},
"whitePaper":"https://www.madiniafricainvest.com/whitepaper/MadiniWhitepaper112020.pdf"
"website": "https://www.madiniafricainvest.com/",
"links": {
"github": "https://github.com/Bluegate-BS"
},
"whitePaper": "https://www.madiniafricainvest.com/whitepaper/MadiniWhitepaper112020.pdf"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "Madini",
"symbol": "MDN",
"decimals":18,
"desc": "MDN is the Madini VeChain Vip180 token that is used to carry value or 'smart money' from Madini smart contracts. In other words, transactions on decentralized applications occurring on Madini VeChain's blockchain will use MDN. It is available for investing by the general public. MDN token is the Madini utility token in our Ecosystem since it is linked to the Madini Minerals Marketplace, to the Madini VeChain Wallet - Android APP - and other Madini VeChain dApps."
}
{
"desc": "MDN is the Madini VeChain Vip180 token that is used to carry value or 'smart money' from Madini smart contracts. In other words, transactions on decentralized applications occurring on Madini VeChain's blockchain will use MDN. It is available for investing by the general public. MDN token is the Madini utility token in our Ecosystem since it is linked to the Madini Minerals Marketplace, to the Madini VeChain Wallet - Android APP - and other Madini VeChain dApps."
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "Decent.bet",
"symbol": "DBET",
"decimals": 18,
"desc": "DECENT.bet is an open-source p2p gaming platform built on the VeChain blockchain"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"name": "VeSea Token",
"symbol": "VSEA",
"decimals":18,
"desc": "The fuel powering VeSea's NFT Utility Ecosystem, designed to be destroyed by VeSea-deployed smartcontracts providing usage to various VIP-181 tokens"
"desc": "The fuel powering VeSea's NFT Utility Ecosystem, designed to be destroyed by VeSea-deployed smartcontracts providing usage to various VIP-181 tokens"
}
Loading

0 comments on commit 72d8b31

Please sign in to comment.