Skip to content

Commit

Permalink
fix(arns): use buy-name when fetching token bost by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Feb 12, 2025
1 parent 0e59521 commit 5585b4d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1355,12 +1355,12 @@ const { id: txId } = await ario.extendLease(

#### `getTokenCost({ intent, ...args })`

Calculates the price in mARIO to perform the interaction in question, eg a 'Buy-record' interaction, where args are the specific params for that interaction.
Calculates the price in mARIO to perform the interaction in question, eg a 'Buy-Name' interaction, where args are the specific params for that interaction.

```typescript
const price = await ario
.getTokenCost({
intent: 'Buy-Record',
intent: 'Buy-Name',
name: 'ar-io',
type: 'permabuy',
})
Expand All @@ -1378,11 +1378,11 @@ const price = await ario

#### `getCostDetails({ intent, fromAddress, fundFrom, ...args})`

Calculates the expanded cost details for the interaction in question, e.g a 'Buy-Record' interaction, where args are the specific params for that interaction. The fromAddress is the address that would be charged for the interaction, and fundFrom is where the funds would be taken from, either `balance`, `stakes`, or `any`.
Calculates the expanded cost details for the interaction in question, e.g a 'Buy-Name' interaction, where args are the specific params for that interaction. The fromAddress is the address that would be charged for the interaction, and fundFrom is where the funds would be taken from, either `balance`, `stakes`, or `any`.

```typescript
const costDetails = await ario.getCostDetails({
intent: 'Buy-Record',
intent: 'Buy-Name',
fromAddress: 't4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3',
fundFrom: 'stakes',
name: 'ar-io',
Expand Down
2 changes: 1 addition & 1 deletion examples/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
const observations = await arIO.getObservations({ epochIndex: 0 });
const distributions = await arIO.getDistributions({ epochIndex: 0 });
const buyRecordCost = await arIO.getTokenCost({
intent: 'Buy-Record',
intent: 'Buy-Name',
type: 'lease',
name: 'ar-io-dapp-record',
years: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/arnsPurchaseCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function buyRecordCLICommand(
ario,
address: signerAddress,
costDetailsParams: {
intent: 'Buy-Record',
intent: 'Buy-Name',
type,
name,
years,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ export function getANTStateFromOptions(
}

export function getTokenCostParamsFromOptions(o: GetTokenCostCLIOptions) {
o.intent ??= 'Buy-Record';
o.intent ??= 'Buy-Name';
o.type ??= 'lease';
o.years ??= '1';

Expand Down
6 changes: 4 additions & 2 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class ARIOReadable implements AoARIORead {
}

async getTokenCost(params: {
intent: 'Buy-Record';
intent: 'Buy-Record' | 'Buy-Name';
type: 'permabuy' | 'lease';
years: number;
name: string;
Expand Down Expand Up @@ -514,11 +514,13 @@ export class ARIOReadable implements AoARIORead {
quantity,
fromAddress,
}: AoTokenCostParams): Promise<number> {
const replacedBuyRecordWithBuyName =
intent === 'Buy-Record' ? 'Buy-Name' : intent;
const allTags = [
{ name: 'Action', value: 'Token-Cost' },
{
name: 'Intent',
value: intent,
value: replacedBuyRecordWithBuyName,
},
{
name: 'Name',
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/esm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ describe('e2e esm tests', async () => {
assert.ok(tokenCost);
});

it('should be able to get token cost for buying a name using `Buy-Name` intent', async () => {
it('should be able to get token cost for buying a name using `Buy-Record` intent', async () => {
const tokenCost = await ario.getTokenCost({
intent: 'Buy-Record',
name: 'new-name',
Expand All @@ -598,9 +598,9 @@ describe('e2e esm tests', async () => {
assert(tokenCost > 0);
});

it('should be able to get token cost for buying a name using `Buy-Record` intent', async () => {
it('should be able to get token cost for buying a name using `Buy-Name` intent', async () => {
const tokenCost = await ario.getTokenCost({
intent: 'Buy-Record',
intent: 'Buy-Name',
name: 'new-name',
type: 'permabuy',
});
Expand All @@ -623,9 +623,9 @@ describe('e2e esm tests', async () => {
assert.equal(typeof costDetails.fundingPlan, 'undefined'); // no funding plan with absence of fundFrom
});

it('should be able to support `Buy-Record` intent for cost details', async () => {
it('should be able to support `Buy-Name` intent for cost details', async () => {
const costDetails = await ario.getCostDetails({
intent: 'Buy-Record',
intent: 'Buy-Name',
name: 'new-name',
type: 'permabuy',
fromAddress: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ',
Expand All @@ -639,7 +639,7 @@ describe('e2e esm tests', async () => {

it('should be able to get cost details for leasing a name', async () => {
const costDetails = await ario.getCostDetails({
intent: 'Buy-Record',
intent: 'Buy-Name',
name: 'new-name',
years: 1,
fromAddress: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ',
Expand Down

0 comments on commit 5585b4d

Please sign in to comment.