Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix(increase undernames): fix undername increase cost util
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Aug 18, 2023
1 parent 2231caf commit f184fb1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/actions/write/increaseUndernames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const increaseUndernames = async (

// Check if the user has enough tokens to increase the undername count
if (!walletHasSufficientBalance(balances, caller, undernameCost)) {
throw new ContractError(INSUFFICIENT_FUNDS_MESSAGE);
throw new ContractError(`${INSUFFICIENT_FUNDS_MESSAGE}: caller has ${balances[caller].toLocaleString()} but needs to have ${undernameCost.toLocaleString()} to pay for this undername increase of ${qty} for ${name}.`);
}

// check if record exists
Expand Down
13 changes: 5 additions & 8 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,9 @@ export function calculateProRatedUndernameCost(
type: 'lease' | 'permabuy',
endTimestamp?: number,
) {
if (type === 'lease' && endTimestamp) {
const costPerSecond = UNDERNAME_REGISTRATION_IO_FEE / SECONDS_IN_A_YEAR;
const timeDifferenceInSeconds = endTimestamp - currentTimestamp;
const proratedLeaseCost = costPerSecond * timeDifferenceInSeconds;
return qty * proratedLeaseCost;
} else if (type === 'permabuy') {
return qty * PERMABUY_LEASE_FEE_LENGTH;
}
const fullCost = type === 'lease' ? UNDERNAME_REGISTRATION_IO_FEE * qty : PERMABUY_LEASE_FEE_LENGTH * qty;
const proRatedCost = type === 'lease' ? (fullCost / SECONDS_IN_A_YEAR) * (endTimestamp - currentTimestamp) : fullCost;
return proRatedCost;

}

1 change: 1 addition & 0 deletions tests/contract/arns_contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"initialContractState":{"ticker":"ARNS-TEST","name":"Arweave Name System Test","version":"0.0.18","owner":"ox5kYPTBbEno-dtqBl4PrRRIEO76ItEbFwFsnhCthjw","evolve":null,"records":{"name1":{"tier":"a27dbfe4-6992-4276-91fb-5b97ae8c3ffa","contractTxID":"MSFTfeBVyaJ8s9n7GxIyJNNc62jEVCKD7lbL3fV8kzU","endTimestamp":1735711200,"startTimestamp":1660852761.798},"name2":{"tier":"a27dbfe4-6992-4276-91fb-5b97ae8c3ffa","contractTxID":"MSFTfeBVyaJ8s9n7GxIyJNNc62jEVCKD7lbL3fV8kzU","endTimestamp":1735711200,"startTimestamp":1660852761.798},"name3":{"tier":"a27dbfe4-6992-4276-91fb-5b97ae8c3ffa","contractTxID":"MSFTfeBVyaJ8s9n7GxIyJNNc62jEVCKD7lbL3fV8kzU","endTimestamp":1735711200,"startTimestamp":1660852761.798}},"balances":{"ox5kYPTBbEno-dtqBl4PrRRIEO76ItEbFwFsnhCthjw":1000000000000000,"VJFpaj-BSv1sPeFS-zylHnlbIsgGR0SnMe5eDthDRLo":1000000000000000,"-3_3BlHpHS9-iE_4LJaBywqDjoyFuQ1T4FC3bzJz1-A":1000000000000000,"Mw-TeyNGN27OHrTvPpogctMwxhEg-sI5hysUMWreXV0":1000000000000000,"Hcal8LRCzDlb_aadCz2HM2dCdLR0m0T9mJNbqDusuoE":1000000000000000,"8e9HMlZN3WKPonG0u9aoVbVaGE27IAL-wSOF5VZUOiU":1000000000000000,"F0_0ZOAhavGg2lQXWiaT8j7oqtNqLHvhjKXk9lAp9Do":1000000000000000,"vo5UZT8ufKJN-w4FF1jXKowxxH_WVR-qOrzJXYVrFxQ":1000000000000000,"l7q5lymbxwQmplZsZ7BcVVM0Q3EIXrrkmv0V98YzGAo":1000000000000000,"12qVlo7Xm87KmvrI7NoZucmeoTyYDDeSIAfezbdgMm4":1000000000000000,"q2adC2LPIOJmC4QbQ-rIUoYSmn_yFvwQdP57Q-jNFS4":1000000000000000,"VSw49z31p8G-fghiahBZ50BZP5KkfeaRHTlhfygPCxE":1000000000000000,"1NMTAg7QinPUlAtQzdGZCQIjw3bUKrnEEN-PMdS4jmc":1000000000000000},"gateways":{"ox5kYPTBbEno-dtqBl4PrRRIEO76ItEbFwFsnhCthjw":{"operatorStake":50000,"delegatedStake":301000,"start":1,"end":0,"status":"joined","vaults":[{"balance":40000,"start":1,"end":0},{"balance":10000,"start":1,"end":0}],"delegates":{"Hcal8LRCzDlb_aadCz2HM2dCdLR0m0T9mJNbqDusuoE":[{"balance":300000,"end":5000,"start":0}],"8e9HMlZN3WKPonG0u9aoVbVaGE27IAL-wSOF5VZUOiU":[{"balance":1000,"end":2500,"start":0}]},"settings":{"label":"Arweave Community Gateway","fqdn":"arweave.net","port":443,"protocol":"https","openDelegation":false,"delegateAllowList":["Hcal8LRCzDlb_aadCz2HM2dCdLR0m0T9mJNbqDusuoE","8e9HMlZN3WKPonG0u9aoVbVaGE27IAL-wSOF5VZUOiU"],"note":"The friendliest gateway to the whole permaweb"}},"VJFpaj-BSv1sPeFS-zylHnlbIsgGR0SnMe5eDthDRLo":{"operatorStake":5000,"delegatedStake":3100,"status":"joined","start":1,"end":0,"vaults":[{"balance":5000,"start":1,"end":0}],"delegates":{"8e9HMlZN3WKPonG0u9aoVbVaGE27IAL-wSOF5VZUOiU":[{"balance":1000,"start":1,"end":0},{"balance":100,"start":1,"end":0}],"F0_0ZOAhavGg2lQXWiaT8j7oqtNqLHvhjKXk9lAp9Do":[{"balance":2000,"start":1,"end":0}]},"settings":{"label":"Slashme","fqdn":"slash-this-gateway.io","port":443,"protocol":"https","openDelegation":true,"delegateAllowList":[],"note":"i do bad things"}},"-3_3BlHpHS9-iE_4LJaBywqDjoyFuQ1T4FC3bzJz1-A":{"operatorStake":500000,"delegatedStake":0,"status":"joined","start":1,"end":0,"vaults":[{"balance":250000,"start":1,"end":0},{"balance":50000,"start":1,"end":0},{"balance":100000,"start":1,"end":0},{"balance":100000,"start":1,"end":0}],"delegates":{},"settings":{"label":"Delegateme","fqdn":"delegate.org","port":80,"protocol":"http","openDelegation":true,"delegateAllowList":[],"note":""}},"Mw-TeyNGN27OHrTvPpogctMwxhEg-sI5hysUMWreXV0":{"operatorStake":5000,"delegatedStake":0,"status":"hidden","start":1,"end":0,"vaults":[{"balance":5000,"start":1,"end":0}],"delegates":{},"settings":{"label":"Wack-gateway","fqdn":"brokeninfra.net","port":12345,"protocol":"https","openDelegation":false,"delegateAllowList":[],"note":""}},"Hcal8LRCzDlb_aadCz2HM2dCdLR0m0T9mJNbqDusuoE":{"operatorStake":10000,"delegatedStake":0,"status":"leaving","start":1,"end":4,"vaults":[{"balance":10000,"start":1,"end":0}],"delegates":{},"settings":{"label":"See Ya Later","fqdn":"goodbye.com","port":443,"protocol":"https","openDelegation":true,"delegateAllowList":["ox5kYPTBbEno-dtqBl4PrRRIEO76ItEbFwFsnhCthjw"],"note":"Leaving the network"}}},"tiers":{"current":["a27dbfe4-6992-4276-91fb-5b97ae8c3ffa","93685bbb-8246-4e7e-bef8-d2e7e6c5d44a","b6c8ee18-2481-4c1b-886c-dbe6b606486a"],"history":[{"id":"a27dbfe4-6992-4276-91fb-5b97ae8c3ffa","fee":100,"settings":{"maxUndernames":100}},{"id":"93685bbb-8246-4e7e-bef8-d2e7e6c5d44a","fee":1000,"settings":{"maxUndernames":1000}},{"id":"b6c8ee18-2481-4c1b-886c-dbe6b606486a","fee":10000,"settings":{"maxUndernames":10000}}]},"fees":{"1":310000000000,"2":300000000000,"3":290000000000,"4":280000000000,"5":270000000000,"6":260000000000,"7":250000000000,"8":240000000000,"9":230000000000,"10":220000000000,"11":210000000000,"12":200000000000,"13":190000000000,"14":180000000000,"15":170000000000,"16":160000000000,"17":150000000000,"18":140000000000,"19":130000000000,"20":120000000000,"21":110000000000,"22":100000000000,"23":90000000000,"24":80000000000,"25":70000000000,"26":60000000000,"27":50000000000,"28":40000000000,"29":30000000000,"30":20000000000,"31":10000000000,"32":0},"settings":{"registry":{"minLockLength":5,"maxLockLength":788400,"minNetworkJoinStakeAmount":5000,"minDelegatedStakeAmount":100,"minGatewayJoinLength":2,"gatewayLeaveLength":2,"delegatedStakeWithdrawLength":5,"operatorStakeWithdrawLength":5},"auctions":{"current":"3IkWJ-0HdwuATDhBXuJRm0bWspXOOkRjxTm-5R2xRbw","history":[{"id":"3IkWJ-0HdwuATDhBXuJRm0bWspXOOkRjxTm-5R2xRbw","floorPriceMultiplier":2,"startPriceMultiplier":200,"decayInterval":60,"decayRate":0.05,"auctionDuration":5040}]},"permabuy":{"multiplier":100}},"reserved":{"www":{},"google":{"endTimestamp":1708286361},"twitter":{"target":"VJFpaj-BSv1sPeFS-zylHnlbIsgGR0SnMe5eDthDRLo","endTimestamp":1708286361},"ario":{"endTimestamp":1708286361}},"foundation":{"actionPeriod":1,"minSignatures":1,"addresses":["vo5UZT8ufKJN-w4FF1jXKowxxH_WVR-qOrzJXYVrFxQ"],"actions":[]},"vaults":{},"auctions":{}},"id":"bcFPxd2FwO9O9DDpx9yM0Ob4hWLUJESUMrJHUipq300"}
4 changes: 1 addition & 3 deletions tests/undernames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ describe('undernames', () => {

expect(writeInteraction?.originalTxId).not.toBe(undefined);
const { cachedValue } = await contract.readState();
if (cachedValue.errorMessages) {
console.log(cachedValue.errorMessages);
}

expect(Object.keys(cachedValue.errorMessages)).not.toContain(
writeInteraction!.originalTxId,
);
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
NETWORK_HIDDEN_STATUS,
NETWORK_JOIN_STATUS,
NETWORK_LEAVING_STATUS,
SECONDS_IN_A_YEAR,
TIERS,
WALLET_FUND_AMOUNT,
} from './constants';
Expand Down Expand Up @@ -78,7 +79,7 @@ function createRecords(tiers: string[], count = 3) {
tier: tiers[0],
contractTxID: ANT_CONTRACT_IDS[0],
endTimestamp: new Date('01/01/2025').getTime() / 1000,
startTimestamp: Date.now(),
startTimestamp: (Date.now() / 1000) - SECONDS_IN_A_YEAR,
};
records[name] = obj;
}
Expand Down

0 comments on commit f184fb1

Please sign in to comment.