From eeb69a5f0a66318052d073069419bb16fada9c7a Mon Sep 17 00:00:00 2001 From: sideffect0 Date: Fri, 10 May 2024 20:29:36 +0530 Subject: [PATCH 1/2] remove airdrop functions --- src/token/main.mo | 220 ---------------------------------------------- 1 file changed, 220 deletions(-) diff --git a/src/token/main.mo b/src/token/main.mo index b81284c..5f87d3c 100644 --- a/src/token/main.mo +++ b/src/token/main.mo @@ -587,22 +587,6 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this { Principal.equal, Principal.hash ); - - // helper functions - private func createEligibleTokenList() { - // reset before creating new list - eligible_tokens := []; - eligibleTokens := Map.fromIter([].vals(), 1, Text.equal, Text.hash); - for (x in raw_snapshot.vals()) { - let _tokens = switch(eligibleTokens.get(x.1)){ - case(?c) {c}; - case(_) {0}; - }; - eligibleTokens.put(x.1, _tokens + 1); - }; - return; - }; - // Hail the Vikings public composite query func get_transactions(page : Nat32) : async Root.GetTransactionsResponseBorrowed { let c : Root.Self = actor(capRootBucketId); @@ -643,208 +627,4 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this { snapshot_time = raw_snapshot_time }; }; - - public query func getEligibleTokensSnap() : async [(MotokoNft.AccountIdentifier, Nat)] { - return Iter.toArray(eligibleTokens.entries()); - }; - - private func findEligibleTokens(user: Principal) : Nat { - var totalTokens : Nat = 0; - let accountIdx : [Nat] = Iter.toArray(Iter.range(0, 50)); - for (i in accountIdx.vals()) { - let subaccount_array : [Nat8] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Nat8.fromNat(i)]; - let address = EAID.fromPrincipal(user, ?subaccount_array); - totalTokens += Option.get(eligibleTokens.get(address), 0); - }; - return totalTokens; - }; - - private func _getEligibleTokenOfUser(user: Principal) : TokenClaimStatus { - switch(airdropedTokens.get(user)) { - case(?tokens) { - return #Airdroped { tx = ""; tokens }; - }; - case(_){}; - }; - switch(claimedTokens.get(user)){ - case(?tokens){ - - return #Claimed { tx = ""; tokens }; - }; - case(_){}; - }; - return #Unclaimed(findEligibleTokens(user)); - }; - - public shared query(msg) func getEligibleTokenOfUser(user : Principal) : async TokenClaimStatus { - _getEligibleTokenOfUser(user) - }; - - // updates - public shared(msg) func createSnap() : async () { - assert(Principal.isController(msg.caller)); - // Tuesday, January 30, 2024 3:00:00 PM UTC with 1 minute gap - if(raw_snapshot_time > 0) { - if(Time.now() < (1706626800000000000) or Time.now() > (1706626860000000000)) { - throw Error.reject("not allowed in this time"); - }; - }; - raw_snapshot := await motoko_nft.getRegistry(); - raw_snapshot_time := Time.now(); - createEligibleTokenList(); - }; - - public shared(msg) func claimTokens() : async TokenClaimStatus { - assert(Principal.isController(msg.caller)); - if(airdropedTokens.size() < 2301 or claimedTokens.size() < 53){ - throw Error.reject("please connect to the developer"); - }; - switch(_getEligibleTokenOfUser(msg.caller)) { - case(#Unclaimed(tokens)){ - if(tokens > 0){ - let user = AID.principalToAccountBlob(msg.caller, null); - let tokenAmount = tokens * 100000000; - let res = _transferFrom(msg.caller, owner_, user, tokenAmount - fee_, null, null); - switch(res) { - case(#ok(tx)){ - claimedTokens.put(msg.caller, tokens); - claimedTxs.put(msg.caller, tx); - ignore addRecord( - msg.caller, "claimTokens", - [ - ("to", #Principal(msg.caller)), - ("value", #U64(u64(tokenAmount))), - ("fee", #U64(u64(fee_))) - ] - ); - - return #Claimed { tx; tokens }; - }; - case(_){ - throw Error.reject("unexpected error"); - }; - }; - }; - return #Unclaimed(0); - }; - - case(status){ - return status; - }; - - }; - }; - - public shared(msg) func airdropTokens(user : Principal) : async TokenClaimStatus { - - assert(Principal.isController(msg.caller)); - - switch(_getEligibleTokenOfUser(user)){ - case(#Unclaimed(tokens)) { - if(tokens > 0){ - let _user = AID.principalToAccountBlob(user, null); - let tokenAmount = tokens * 100000000; - let res = _transferFrom(msg.caller, owner_, _user, tokenAmount - fee_, null, null); - switch(res) { - case(#ok(tx)){ - airdropedTokens.put(user, tokens); - airdropTxs.put(user, tx); - ignore addRecord( - msg.caller, "airdropTokens", - [ - ("to", #Principal(user)), - ("value", #U64(u64(tokenAmount))), - ("fee", #U64(u64(fee_))) - ] - ); - return #Airdroped { tx; tokens }; - }; - case(_){ - throw Error.reject("unexpected error"); - }; - }; - }; - return #Unclaimed(0); - }; - case(status){ - return status; - }; - }; - }; - - public shared(msg) func g_balanceOf(hex : Text) : async (Nat) { - let account = Option.unwrap(AID.accountHexToAccountBlob(hex)); - let balance = _getBalance(account); - return balance; - }; - - // public shared(msg) func checkData(start : Nat, end : Nat) : async (Nat, Nat, Nat, Nat) { - // assert(Principal.isController(msg.caller)); - // let affected_pages :[Nat] = Iter.toArray(Iter.range(start, end)); - // let c : Root.Self = actor(capRootBucketId); - // for (page in affected_pages.vals()){ - // let transactions = await c.get_transactions({page = ?Nat32.fromNat(page); witness = false}); - // for(event in transactions.data.vals()){ - // if(event.operation == "claimTokens"){ - // var p : Principal = Principal.fromText("aaaaa-aa"); - // var v : Nat64 = 0; - // for(details in event.details.vals()) { - // if(details.0 == "to") { - // switch(details.1){ - // case(#Principal(user)){ - // p := user; - // }; - // case(_){}; - // }; - // }; - // if(details.0 == "value"){ - // switch(details.1){ - // case(#U64(value)){ - // v := value; - // }; - // case(_){}; - // }; - // }; - // }; - // if (p != Principal.fromText("aaaaa-aa") and v != 0){ - // claimedTokens.put(p, Nat64.toNat(v / 100000000)); - // }; - // }; - // if(event.operation == "airdropTokens"){ - // var p : Principal = Principal.fromText("aaaaa-aa"); - // var v : Nat64 = 0; - // for(details in event.details.vals()) { - // if(details.0 == "to") { - // switch(details.1){ - // case(#Principal(user)){ - // p := user; - // }; - // case(_){}; - // }; - // }; - // if(details.0 == "value"){ - // switch(details.1){ - // case(#U64(value)){ - // v := value; - // }; - // case(_){}; - // }; - // }; - // }; - // if (p != Principal.fromText("aaaaa-aa") and v != 0){ - // airdropedTokens.put(p, Nat64.toNat(v / 100000000)); - // }; - // }; - // }; - // }; - // var aTokens = 0; - // var cTokens = 0; - // for(x in Iter.toArray(airdropedTokens.entries()).vals()){ - // aTokens += x.1; - // }; - // for(x in Iter.toArray(claimedTokens.entries()).vals()){ - // cTokens += x.1; - // }; - // return (airdropedTokens.size(), claimedTokens.size(), aTokens, cTokens); - // }; }; From 3b73b1c6332d79892c7ccb8cc28a2641381406bd Mon Sep 17 00:00:00 2001 From: sideffect0 Date: Fri, 10 May 2024 20:33:15 +0530 Subject: [PATCH 2/2] fix burn for minter account --- src/token/main.mo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/token/main.mo b/src/token/main.mo index 5f87d3c..00904da 100644 --- a/src/token/main.mo +++ b/src/token/main.mo @@ -266,7 +266,12 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this { (result: TxnResult) { let from = _from; let to = _to; - let operation: Operation = #transfer({ action = #send; }); + // destination is minter or not + let operation: Operation = if(_to == owner_){ + #transfer({ action = #burn; }); + } else { + #transfer({ action = #send; }); + }; // check fee if(not(_checkFee(from, _value))){ return #err({ code=#InsufficientBalance; message="Insufficient Balance"; });