Skip to content

Commit 55d1cae

Browse files
committed
update claimToken
1 parent 20f7448 commit 55d1cae

File tree

5 files changed

+182
-44
lines changed

5 files changed

+182
-44
lines changed

src/localServer/testMinerV2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ const connectToGossipNode = async ( wallet: ethers.Wallet ) => {
305305

306306
const start = (privateKeyArmor: string) => new Promise(async resolve => {
307307
const wallet = new ethers.Wallet(privateKeyArmor)
308-
connectToGossipNode(wallet)
308+
await connectToGossipNode(wallet)
309+
resolve (true)
309310
})
310311

311312

src/localServer/workers/encrypt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ const processCmd = async (cmd: worker_command) => {
722722
return recoverAccount(cmd)
723723
}
724724

725+
case 'claimToken': {
726+
return claimToken (cmd)
727+
}
728+
725729
case 'getAllProfiles': {
726730
const profiles = CoNET_Data?.profiles
727731
if (!profiles) {

src/localServer/workers/utilities/miningV2.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,74 @@ const CONETianPlan_purchase = async (referrer: string, profile: profile, amount:
458458
return resolve(false)
459459
}
460460
return resolve(true)
461-
})
461+
})
462+
463+
const claimAdmin = '0xD7fa7D7316C0de4538c7033c503Bee8Ad2AA338d'
464+
465+
const approveClaimToken = async (profile: profile, token: CryptoAsset) => {
466+
const getContract = getClaimableAddress(token.name)
467+
if (!getContract) {
468+
return false
469+
}
470+
const wallet = new ethers.Wallet(profile.privateKeyArmor, provideCONET)
471+
const amount = ethers.parseEther (token.balance)
472+
const approveContract = new ethers.Contract (getContract, cCNTP_ABI, wallet)
473+
try {
474+
const tx = await approveContract.approve(claimAdmin, amount)
475+
return tx
476+
} catch (ex) {
477+
return false
478+
}
479+
}
480+
481+
const getTokenByName = (tokens: conet_tokens, tokenName: string) => {
482+
const tokensKeys = Object.keys(tokens)
483+
const tokensIndex = tokensKeys.findIndex(n => tokens[n].name === tokenName)
484+
if (tokensIndex < 0) {
485+
return null
486+
}
487+
return tokens[tokensKeys[tokensIndex]]
488+
}
489+
490+
const claimToken = async (cmd: worker_command) => {
491+
if (!cmd?.data?.length) {
492+
cmd.err = 'INVALID_DATA'
493+
return returnUUIDChannel(cmd)
494+
}
495+
496+
const _profile: profile = cmd.data[0]
497+
const tokenName = cmd.data[1]
498+
499+
if (!_profile?.keyID || !tokenName ) {
500+
cmd.err = 'INVALID_DATA'
501+
return returnUUIDChannel(cmd)
502+
}
503+
504+
const profile = getProfileFromKeyID (_profile.keyID)
505+
506+
if (!profile) {
507+
cmd.err = 'INVALID_DATA'
508+
return returnUUIDChannel(cmd)
509+
}
510+
511+
const tokens = profile.tokens
512+
if (!tokens) {
513+
cmd.err = 'INVALID_DATA'
514+
return returnUUIDChannel(cmd)
515+
}
516+
517+
const conetBalance = parseFloat(tokens.conet?.balance || '0')
518+
const token = getTokenByName (tokens, tokenName)
519+
if (conetBalance< 0.0001 || !token) {
520+
await getFaucet(profile)
521+
cmd.err = 'INVALID_DATA'
522+
return returnUUIDChannel(cmd)
523+
}
524+
525+
const tx = await approveClaimToken (profile, token)
526+
if (!tx) {
527+
cmd.err = 'INVALID_DATA'
528+
return returnUUIDChannel(cmd)
529+
}
530+
531+
}

src/localServer/workers/utilities/smartContractABI.ts

Lines changed: 103 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,25 @@ const cCNTP_ABI = [
29322932
"name": "Transfer",
29332933
"type": "event"
29342934
},
2935+
{
2936+
"inputs": [
2937+
{
2938+
"internalType": "address",
2939+
"name": "",
2940+
"type": "address"
2941+
}
2942+
],
2943+
"name": "adminList",
2944+
"outputs": [
2945+
{
2946+
"internalType": "bool",
2947+
"name": "",
2948+
"type": "bool"
2949+
}
2950+
],
2951+
"stateMutability": "view",
2952+
"type": "function"
2953+
},
29352954
{
29362955
"inputs": [
29372956
{
@@ -2999,6 +3018,19 @@ const cCNTP_ABI = [
29993018
"stateMutability": "view",
30003019
"type": "function"
30013020
},
3021+
{
3022+
"inputs": [
3023+
{
3024+
"internalType": "uint256",
3025+
"name": "value",
3026+
"type": "uint256"
3027+
}
3028+
],
3029+
"name": "bronCNTP",
3030+
"outputs": [],
3031+
"stateMutability": "nonpayable",
3032+
"type": "function"
3033+
},
30023034
{
30033035
"inputs": [
30043036
{
@@ -3043,32 +3075,94 @@ const cCNTP_ABI = [
30433075
"type": "bool"
30443076
}
30453077
],
3046-
"name": "changeAddressInWhitelist",
3078+
"name": "changeAddressInAdminlist",
30473079
"outputs": [],
30483080
"stateMutability": "nonpayable",
30493081
"type": "function"
30503082
},
3083+
{
3084+
"inputs": [],
3085+
"name": "decimals",
3086+
"outputs": [
3087+
{
3088+
"internalType": "uint8",
3089+
"name": "",
3090+
"type": "uint8"
3091+
}
3092+
],
3093+
"stateMutability": "view",
3094+
"type": "function"
3095+
},
30513096
{
30523097
"inputs": [
30533098
{
3054-
"internalType": "bool",
3055-
"name": "_rule",
3056-
"type": "bool"
3099+
"internalType": "address",
3100+
"name": "to",
3101+
"type": "address"
3102+
},
3103+
{
3104+
"internalType": "uint256",
3105+
"name": "value",
3106+
"type": "uint256"
30573107
}
30583108
],
3059-
"name": "changeWhitelistRule",
3109+
"name": "initAccount",
30603110
"outputs": [],
30613111
"stateMutability": "nonpayable",
30623112
"type": "function"
30633113
},
30643114
{
3065-
"inputs": [],
3066-
"name": "decimals",
3115+
"inputs": [
3116+
{
3117+
"internalType": "address",
3118+
"name": "",
3119+
"type": "address"
3120+
}
3121+
],
3122+
"name": "initV2",
30673123
"outputs": [
30683124
{
3069-
"internalType": "uint8",
3125+
"internalType": "bool",
30703126
"name": "",
3071-
"type": "uint8"
3127+
"type": "bool"
3128+
}
3129+
],
3130+
"stateMutability": "view",
3131+
"type": "function"
3132+
},
3133+
{
3134+
"inputs": [
3135+
{
3136+
"internalType": "address",
3137+
"name": "",
3138+
"type": "address"
3139+
}
3140+
],
3141+
"name": "latestBronBlockNumber",
3142+
"outputs": [
3143+
{
3144+
"internalType": "uint256",
3145+
"name": "",
3146+
"type": "uint256"
3147+
}
3148+
],
3149+
"stateMutability": "view",
3150+
"type": "function"
3151+
},
3152+
{
3153+
"inputs": [
3154+
{
3155+
"internalType": "address",
3156+
"name": "",
3157+
"type": "address"
3158+
}
3159+
],
3160+
"name": "latestBronValue",
3161+
"outputs": [
3162+
{
3163+
"internalType": "uint256",
3164+
"name": "",
3165+
"type": "uint256"
30723166
}
30733167
],
30743168
"stateMutability": "view",
@@ -3183,38 +3277,6 @@ const cCNTP_ABI = [
31833277
],
31843278
"stateMutability": "nonpayable",
31853279
"type": "function"
3186-
},
3187-
{
3188-
"inputs": [
3189-
{
3190-
"internalType": "address",
3191-
"name": "",
3192-
"type": "address"
3193-
}
3194-
],
3195-
"name": "whiteList",
3196-
"outputs": [
3197-
{
3198-
"internalType": "bool",
3199-
"name": "",
3200-
"type": "bool"
3201-
}
3202-
],
3203-
"stateMutability": "view",
3204-
"type": "function"
3205-
},
3206-
{
3207-
"inputs": [],
3208-
"name": "whitelistRule",
3209-
"outputs": [
3210-
{
3211-
"internalType": "bool",
3212-
"name": "",
3213-
"type": "bool"
3214-
}
3215-
],
3216-
"stateMutability": "view",
3217-
"type": "function"
32183280
}
32193281
]
32203282

src/localServer/workers/utilities/utilV2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ const prePurchase = async (cmd) => {
404404

405405
const nodePrice = 1250
406406

407-
const claimAdmin = '0x418833b70F882C833EF0F0Fcee3FB9d89C79d47C'
407+
408+
408409
const getClaimableAddress = (CONET_claimableName) => {
409410
switch (CONET_claimableName) {
410411

0 commit comments

Comments
 (0)