@ar.io/sdk 3.6.2-alpha.1 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -6
- package/bundles/web.bundle.min.js +53 -53
- package/lib/cjs/cli/cli.js +46 -14
- package/lib/cjs/cli/commands/antCommands.js +3 -3
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +4 -4
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +9 -9
- package/lib/cjs/cli/commands/transfer.js +6 -6
- package/lib/cjs/cli/utils.js +3 -3
- package/lib/cjs/common/io.js +21 -1
- package/lib/cjs/types/io.js +11 -1
- package/lib/cjs/utils/arweave.js +84 -1
- package/lib/cjs/utils/utils.test.js +98 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +47 -15
- package/lib/esm/cli/commands/antCommands.js +4 -4
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +5 -5
- package/lib/esm/cli/commands/gatewayWriteCommands.js +10 -10
- package/lib/esm/cli/commands/transfer.js +7 -7
- package/lib/esm/cli/utils.js +1 -1
- package/lib/esm/common/io.js +22 -2
- package/lib/esm/types/io.js +8 -0
- package/lib/esm/utils/arweave.js +81 -0
- package/lib/esm/utils/utils.test.js +99 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +1 -1
- package/lib/types/cli/utils.d.ts +1 -1
- package/lib/types/common/io.d.ts +2 -1
- package/lib/types/types/io.d.ts +37 -19
- package/lib/types/utils/arweave.d.ts +3 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/cli/cli.js
CHANGED
|
@@ -25,7 +25,7 @@ import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegat
|
|
|
25
25
|
import { getAllGatewayVaults, getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listAllDelegatesCLICommand, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
26
26
|
import { createVaultCLICommand, extendVaultCLICommand, increaseVaultCLICommand, revokeVaultCLICommand, transferCLICommand, vaultedTransferCLICommand, } from './commands/transfer.js';
|
|
27
27
|
import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, setAntBaseNameOptions, setAntUndernameOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, vaultedTransferOptions, writeActionOptions, } from './options.js';
|
|
28
|
-
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredProcessIdFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions,
|
|
28
|
+
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, customTagsFromOptions, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredProcessIdFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, } from './utils.js';
|
|
29
29
|
applyOptions(program
|
|
30
30
|
.name('ar.io')
|
|
31
31
|
.version(version)
|
|
@@ -51,6 +51,16 @@ makeCommand({
|
|
|
51
51
|
description: 'Get demand factor',
|
|
52
52
|
action: (options) => readARIOFromOptions(options).getDemandFactor(),
|
|
53
53
|
});
|
|
54
|
+
makeCommand({
|
|
55
|
+
name: 'get-demand-factor-settings',
|
|
56
|
+
description: 'Get current settings for demand factor',
|
|
57
|
+
action: (options) => readARIOFromOptions(options).getDemandFactorSettings(),
|
|
58
|
+
});
|
|
59
|
+
makeCommand({
|
|
60
|
+
name: 'get-epoch-settings',
|
|
61
|
+
description: 'Get current settings for epochs',
|
|
62
|
+
action: (options) => readARIOFromOptions(options).getEpochSettings(),
|
|
63
|
+
});
|
|
54
64
|
makeCommand({
|
|
55
65
|
name: 'get-gateway',
|
|
56
66
|
description: 'Get the gateway of an address',
|
|
@@ -162,6 +172,14 @@ makeCommand({
|
|
|
162
172
|
.getDistributions(epochInputFromOptions(o))
|
|
163
173
|
.then((result) => result ?? { message: 'No distributions found for epoch' }),
|
|
164
174
|
});
|
|
175
|
+
makeCommand({
|
|
176
|
+
name: 'get-eligible-rewards',
|
|
177
|
+
description: 'Get eligible rewards for an epoch',
|
|
178
|
+
options: [...epochOptions, ...paginationOptions],
|
|
179
|
+
action: (o) => readARIOFromOptions(o)
|
|
180
|
+
.getEligibleEpochRewards(epochInputFromOptions(o), paginationParamsFromOptions(o))
|
|
181
|
+
.then((result) => result ?? { message: 'No eligible distributions found for epoch' }),
|
|
182
|
+
});
|
|
165
183
|
makeCommand({
|
|
166
184
|
name: 'get-token-cost',
|
|
167
185
|
description: 'Get token cost for an intended action',
|
|
@@ -509,7 +527,7 @@ makeCommand({
|
|
|
509
527
|
await assertConfirmationPrompt(`Are you sure you want to transfer ANT ownership to ${target}?`, options);
|
|
510
528
|
return writeANTFromOptions(options).transfer({
|
|
511
529
|
target,
|
|
512
|
-
},
|
|
530
|
+
}, customTagsFromOptions(options));
|
|
513
531
|
},
|
|
514
532
|
});
|
|
515
533
|
makeCommand({
|
|
@@ -521,7 +539,7 @@ makeCommand({
|
|
|
521
539
|
await assertConfirmationPrompt(`Are you sure you want to add ${controller} as a controller?`, options);
|
|
522
540
|
return writeANTFromOptions(options).addController({
|
|
523
541
|
controller: requiredStringFromOptions(options, 'controller'),
|
|
524
|
-
},
|
|
542
|
+
}, customTagsFromOptions(options));
|
|
525
543
|
},
|
|
526
544
|
});
|
|
527
545
|
makeCommand({
|
|
@@ -531,7 +549,7 @@ makeCommand({
|
|
|
531
549
|
action: async (options) => {
|
|
532
550
|
return writeANTFromOptions(options).removeController({
|
|
533
551
|
controller: requiredStringFromOptions(options, 'controller'),
|
|
534
|
-
},
|
|
552
|
+
}, customTagsFromOptions(options));
|
|
535
553
|
},
|
|
536
554
|
});
|
|
537
555
|
makeCommand({
|
|
@@ -561,7 +579,7 @@ makeCommand({
|
|
|
561
579
|
await assertConfirmationPrompt(`Are you sure you want to remove the record with undername ${undername}?`, options);
|
|
562
580
|
return writeANTFromOptions(options).removeRecord({
|
|
563
581
|
undername,
|
|
564
|
-
},
|
|
582
|
+
}, customTagsFromOptions(options));
|
|
565
583
|
},
|
|
566
584
|
});
|
|
567
585
|
makeCommand({
|
|
@@ -573,7 +591,7 @@ makeCommand({
|
|
|
573
591
|
await assertConfirmationPrompt(`Are you sure you want to set the ticker to ${ticker}?`, options);
|
|
574
592
|
return writeANTFromOptions(options).setTicker({
|
|
575
593
|
ticker,
|
|
576
|
-
},
|
|
594
|
+
}, customTagsFromOptions(options));
|
|
577
595
|
},
|
|
578
596
|
});
|
|
579
597
|
makeCommand({
|
|
@@ -585,7 +603,7 @@ makeCommand({
|
|
|
585
603
|
await assertConfirmationPrompt(`Are you sure you want to set the name to ${requiredStringFromOptions(options, 'name')}?`, options);
|
|
586
604
|
return writeANTFromOptions(options).setName({
|
|
587
605
|
name,
|
|
588
|
-
},
|
|
606
|
+
}, customTagsFromOptions(options));
|
|
589
607
|
},
|
|
590
608
|
});
|
|
591
609
|
makeCommand({
|
|
@@ -597,7 +615,7 @@ makeCommand({
|
|
|
597
615
|
await assertConfirmationPrompt(`Are you sure you want to set the ANT description to ${description}?`, options);
|
|
598
616
|
return writeANTFromOptions(options).setDescription({
|
|
599
617
|
description,
|
|
600
|
-
},
|
|
618
|
+
}, customTagsFromOptions(options));
|
|
601
619
|
},
|
|
602
620
|
});
|
|
603
621
|
makeCommand({
|
|
@@ -609,7 +627,7 @@ makeCommand({
|
|
|
609
627
|
await assertConfirmationPrompt(`Are you sure you want to set the ANT keywords to ${keywords}?`, options);
|
|
610
628
|
return writeANTFromOptions(options).setKeywords({
|
|
611
629
|
keywords,
|
|
612
|
-
},
|
|
630
|
+
}, customTagsFromOptions(options));
|
|
613
631
|
},
|
|
614
632
|
});
|
|
615
633
|
makeCommand({
|
|
@@ -626,7 +644,7 @@ makeCommand({
|
|
|
626
644
|
return writeANTFromOptions(options).setLogo({
|
|
627
645
|
// TODO: Could take a logo file, upload it to Arweave, get transaction ID
|
|
628
646
|
txId,
|
|
629
|
-
},
|
|
647
|
+
}, customTagsFromOptions(options));
|
|
630
648
|
},
|
|
631
649
|
});
|
|
632
650
|
makeCommand({
|
|
@@ -639,7 +657,7 @@ makeCommand({
|
|
|
639
657
|
return writeANTFromOptions(options).releaseName({
|
|
640
658
|
name,
|
|
641
659
|
arioProcessId: arioProcessIdFromOptions(options),
|
|
642
|
-
},
|
|
660
|
+
}, customTagsFromOptions(options));
|
|
643
661
|
},
|
|
644
662
|
});
|
|
645
663
|
makeCommand({
|
|
@@ -659,7 +677,7 @@ makeCommand({
|
|
|
659
677
|
name,
|
|
660
678
|
arioProcessId: arioProcessIdFromOptions(options),
|
|
661
679
|
antProcessId: targetProcess,
|
|
662
|
-
},
|
|
680
|
+
}, customTagsFromOptions(options));
|
|
663
681
|
},
|
|
664
682
|
});
|
|
665
683
|
makeCommand({
|
|
@@ -679,7 +697,7 @@ makeCommand({
|
|
|
679
697
|
name,
|
|
680
698
|
address,
|
|
681
699
|
arioProcessId: arioProcessIdFromOptions(options),
|
|
682
|
-
},
|
|
700
|
+
}, customTagsFromOptions(options));
|
|
683
701
|
},
|
|
684
702
|
});
|
|
685
703
|
makeCommand({
|
|
@@ -692,7 +710,7 @@ makeCommand({
|
|
|
692
710
|
return writeANTFromOptions(options).removePrimaryNames({
|
|
693
711
|
names,
|
|
694
712
|
arioProcessId: arioProcessIdFromOptions(options),
|
|
695
|
-
},
|
|
713
|
+
}, customTagsFromOptions(options));
|
|
696
714
|
},
|
|
697
715
|
});
|
|
698
716
|
makeCommand({
|
|
@@ -705,11 +723,25 @@ makeCommand({
|
|
|
705
723
|
logger: getLoggerFromOptions(options),
|
|
706
724
|
});
|
|
707
725
|
return process.send({
|
|
708
|
-
tags:
|
|
726
|
+
tags: customTagsFromOptions(options).tags ?? [],
|
|
709
727
|
signer: requiredAoSignerFromOptions(options),
|
|
710
728
|
});
|
|
711
729
|
},
|
|
712
730
|
});
|
|
731
|
+
makeCommand({
|
|
732
|
+
name: 'read-action',
|
|
733
|
+
description: 'Send a dry-run read action to an AO Process',
|
|
734
|
+
options: [optionMap.processId, optionMap.tags],
|
|
735
|
+
action: async (options) => {
|
|
736
|
+
const process = new AOProcess({
|
|
737
|
+
processId: requiredProcessIdFromOptions(options),
|
|
738
|
+
logger: getLoggerFromOptions(options),
|
|
739
|
+
});
|
|
740
|
+
return process.read({
|
|
741
|
+
tags: customTagsFromOptions(options).tags ?? [],
|
|
742
|
+
});
|
|
743
|
+
},
|
|
744
|
+
});
|
|
713
745
|
if (process.argv[1].includes('bin/ar.io') || // Running from global .bin
|
|
714
746
|
process.argv[1].includes('cli/cli') // Running from source
|
|
715
747
|
) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertConfirmationPrompt, defaultTtlSecondsCLI, requiredStringFromOptions, writeANTFromOptions,
|
|
1
|
+
import { assertConfirmationPrompt, customTagsFromOptions, defaultTtlSecondsCLI, requiredStringFromOptions, writeANTFromOptions, } from '../utils.js';
|
|
2
2
|
/** @deprecated -- use set-ant-base-name and set-ant-undername */
|
|
3
3
|
export async function setAntRecordCLICommand(o) {
|
|
4
4
|
const ttlSeconds = +(o.ttlSeconds ?? defaultTtlSecondsCLI);
|
|
@@ -12,7 +12,7 @@ export async function setAntRecordCLICommand(o) {
|
|
|
12
12
|
undername,
|
|
13
13
|
transactionId,
|
|
14
14
|
ttlSeconds,
|
|
15
|
-
},
|
|
15
|
+
}, customTagsFromOptions(o));
|
|
16
16
|
}
|
|
17
17
|
export async function setAntBaseNameCLICommand(o) {
|
|
18
18
|
const ttlSeconds = +(o.ttlSeconds ?? defaultTtlSecondsCLI);
|
|
@@ -24,7 +24,7 @@ export async function setAntBaseNameCLICommand(o) {
|
|
|
24
24
|
return writeANTFromOptions(o).setBaseNameRecord({
|
|
25
25
|
transactionId,
|
|
26
26
|
ttlSeconds,
|
|
27
|
-
},
|
|
27
|
+
}, customTagsFromOptions(o));
|
|
28
28
|
}
|
|
29
29
|
export async function setAntUndernameCLICommand(o) {
|
|
30
30
|
const ttlSeconds = +(o.ttlSeconds ?? defaultTtlSecondsCLI);
|
|
@@ -38,5 +38,5 @@ export async function setAntUndernameCLICommand(o) {
|
|
|
38
38
|
undername,
|
|
39
39
|
transactionId,
|
|
40
40
|
ttlSeconds,
|
|
41
|
-
},
|
|
41
|
+
}, customTagsFromOptions(o));
|
|
42
42
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertConfirmationPrompt, assertEnoughBalanceForArNSPurchase, fundFromFromOptions, positiveIntegerFromOptions, recordTypeFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, writeARIOFromOptions,
|
|
1
|
+
import { assertConfirmationPrompt, assertEnoughBalanceForArNSPurchase, customTagsFromOptions, fundFromFromOptions, positiveIntegerFromOptions, recordTypeFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, writeARIOFromOptions, } from '../utils.js';
|
|
2
2
|
export async function buyRecordCLICommand(o) {
|
|
3
3
|
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
4
4
|
const name = requiredStringFromOptions(o, 'name');
|
|
@@ -37,7 +37,7 @@ export async function buyRecordCLICommand(o) {
|
|
|
37
37
|
type,
|
|
38
38
|
years,
|
|
39
39
|
fundFrom: fundFromFromOptions(o),
|
|
40
|
-
},
|
|
40
|
+
}, customTagsFromOptions(o));
|
|
41
41
|
}
|
|
42
42
|
export async function upgradeRecordCLICommand(o) {
|
|
43
43
|
const name = requiredStringFromOptions(o, 'name');
|
|
@@ -101,7 +101,7 @@ export async function extendLeaseCLICommand(o) {
|
|
|
101
101
|
return ario.extendLease({
|
|
102
102
|
name,
|
|
103
103
|
years,
|
|
104
|
-
},
|
|
104
|
+
}, customTagsFromOptions(o));
|
|
105
105
|
}
|
|
106
106
|
export async function increaseUndernameLimitCLICommand(o) {
|
|
107
107
|
const name = requiredStringFromOptions(o, 'name');
|
|
@@ -131,7 +131,7 @@ export async function increaseUndernameLimitCLICommand(o) {
|
|
|
131
131
|
return ario.increaseUndernameLimit({
|
|
132
132
|
name,
|
|
133
133
|
increaseCount,
|
|
134
|
-
},
|
|
134
|
+
}, customTagsFromOptions(o));
|
|
135
135
|
}
|
|
136
136
|
export async function requestPrimaryNameCLICommand(o) {
|
|
137
137
|
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
@@ -155,5 +155,5 @@ export async function requestPrimaryNameCLICommand(o) {
|
|
|
155
155
|
return ario.requestPrimaryName({
|
|
156
156
|
name,
|
|
157
157
|
fundFrom,
|
|
158
|
-
},
|
|
158
|
+
}, customTagsFromOptions(o));
|
|
159
159
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import prompts from 'prompts';
|
|
17
17
|
import { mARIOToken } from '../../node/index.js';
|
|
18
|
-
import { assertConfirmationPrompt, assertEnoughMARIOBalance, formatARIOWithCommas, gatewaySettingsFromOptions, redelegateParamsFromOptions, requiredAddressFromOptions, requiredMARIOFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, stringifyJsonForCLIDisplay, writeARIOFromOptions,
|
|
18
|
+
import { assertConfirmationPrompt, assertEnoughMARIOBalance, customTagsFromOptions, formatARIOWithCommas, gatewaySettingsFromOptions, redelegateParamsFromOptions, requiredAddressFromOptions, requiredMARIOFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, stringifyJsonForCLIDisplay, writeARIOFromOptions, } from '../utils.js';
|
|
19
19
|
export async function joinNetwork(options) {
|
|
20
20
|
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
21
21
|
const mARIOQuantity = requiredMARIOFromOptions(options, 'operatorStake');
|
|
@@ -41,7 +41,7 @@ export async function joinNetwork(options) {
|
|
|
41
41
|
});
|
|
42
42
|
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
|
|
43
43
|
}
|
|
44
|
-
const result = await ario.joinNetwork(settings,
|
|
44
|
+
const result = await ario.joinNetwork(settings, customTagsFromOptions(options));
|
|
45
45
|
const output = {
|
|
46
46
|
joinNetworkResult: result,
|
|
47
47
|
joinedAddress: signerAddress,
|
|
@@ -57,7 +57,7 @@ export async function updateGatewaySettings(options) {
|
|
|
57
57
|
throw new Error('No gateway settings provided');
|
|
58
58
|
}
|
|
59
59
|
await assertConfirmationPrompt(`Gateway Settings:\n\n${stringifyJsonForCLIDisplay(gatewaySettings)}\n\nYou are about to update your gateway settings to the above\nAre you sure?\n`, options);
|
|
60
|
-
const result = await ario.updateGatewaySettings(gatewaySettings,
|
|
60
|
+
const result = await ario.updateGatewaySettings(gatewaySettings, customTagsFromOptions(options));
|
|
61
61
|
const output = {
|
|
62
62
|
updateGatewaySettingsResult: result,
|
|
63
63
|
updatedGatewayAddress: signerAddress,
|
|
@@ -77,7 +77,7 @@ export async function leaveNetwork(options) {
|
|
|
77
77
|
'\n\n' +
|
|
78
78
|
'Are you sure you want to leave the AR.IO network?', options);
|
|
79
79
|
}
|
|
80
|
-
return writeARIOFromOptions(options).ario.leaveNetwork(
|
|
80
|
+
return writeARIOFromOptions(options).ario.leaveNetwork(customTagsFromOptions(options));
|
|
81
81
|
}
|
|
82
82
|
export async function saveObservations(o) {
|
|
83
83
|
const failedGateways = requiredStringArrayFromOptions(o, 'failedGateways');
|
|
@@ -86,7 +86,7 @@ export async function saveObservations(o) {
|
|
|
86
86
|
return writeARIOFromOptions(o).ario.saveObservations({
|
|
87
87
|
failedGateways: requiredStringArrayFromOptions(o, 'failedGateways'),
|
|
88
88
|
reportTxId: requiredStringFromOptions(o, 'transactionId'),
|
|
89
|
-
},
|
|
89
|
+
}, customTagsFromOptions(o));
|
|
90
90
|
}
|
|
91
91
|
export async function increaseOperatorStake(o) {
|
|
92
92
|
const increaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
@@ -94,7 +94,7 @@ export async function increaseOperatorStake(o) {
|
|
|
94
94
|
return (writeARIOFromOptions(o).ario.increaseOperatorStake({
|
|
95
95
|
increaseQty,
|
|
96
96
|
}),
|
|
97
|
-
|
|
97
|
+
customTagsFromOptions(o));
|
|
98
98
|
}
|
|
99
99
|
export async function decreaseOperatorStake(o) {
|
|
100
100
|
const decreaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
@@ -102,7 +102,7 @@ export async function decreaseOperatorStake(o) {
|
|
|
102
102
|
await assertConfirmationPrompt(`You are about to decrease your operator stake by ${formatARIOWithCommas(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
|
|
103
103
|
return writeARIOFromOptions(o).ario.decreaseOperatorStake({
|
|
104
104
|
decreaseQty,
|
|
105
|
-
},
|
|
105
|
+
}, customTagsFromOptions(o));
|
|
106
106
|
}
|
|
107
107
|
export async function instantWithdrawal(o) {
|
|
108
108
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
@@ -111,7 +111,7 @@ export async function instantWithdrawal(o) {
|
|
|
111
111
|
return writeARIOFromOptions(o).ario.instantWithdrawal({
|
|
112
112
|
vaultId,
|
|
113
113
|
gatewayAddress,
|
|
114
|
-
},
|
|
114
|
+
}, customTagsFromOptions(o));
|
|
115
115
|
}
|
|
116
116
|
export async function cancelWithdrawal(o) {
|
|
117
117
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
@@ -120,7 +120,7 @@ export async function cancelWithdrawal(o) {
|
|
|
120
120
|
return writeARIOFromOptions(o).ario.cancelWithdrawal({
|
|
121
121
|
vaultId,
|
|
122
122
|
gatewayAddress,
|
|
123
|
-
},
|
|
123
|
+
}, customTagsFromOptions(o));
|
|
124
124
|
}
|
|
125
125
|
export async function delegateStake(options) {
|
|
126
126
|
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
@@ -152,7 +152,7 @@ export async function delegateStake(options) {
|
|
|
152
152
|
const result = await ario.delegateStake({
|
|
153
153
|
target,
|
|
154
154
|
stakeQty: arioQuantity.toMARIO(),
|
|
155
|
-
},
|
|
155
|
+
}, customTagsFromOptions(options));
|
|
156
156
|
const output = {
|
|
157
157
|
senderAddress: signerAddress,
|
|
158
158
|
transferResult: result,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertEnoughMARIOBalance, assertLockLengthInRange, confirmationPrompt, formatARIOWithCommas, formatMARIOToARIOWithCommas, requiredMARIOFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, writeARIOFromOptions,
|
|
1
|
+
import { assertEnoughMARIOBalance, assertLockLengthInRange, confirmationPrompt, customTagsFromOptions, formatARIOWithCommas, formatMARIOToARIOWithCommas, requiredMARIOFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, writeARIOFromOptions, } from '../utils.js';
|
|
2
2
|
export async function transferCLICommand(options) {
|
|
3
3
|
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
4
4
|
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
@@ -16,7 +16,7 @@ export async function transferCLICommand(options) {
|
|
|
16
16
|
const result = await ario.transfer({
|
|
17
17
|
target,
|
|
18
18
|
qty: arioQuantity.toMARIO().valueOf(),
|
|
19
|
-
},
|
|
19
|
+
}, customTagsFromOptions(options));
|
|
20
20
|
const output = {
|
|
21
21
|
senderAddress: signerAddress,
|
|
22
22
|
transferResult: result,
|
|
@@ -46,7 +46,7 @@ export async function vaultedTransferCLICommand(o) {
|
|
|
46
46
|
quantity: mARIOQuantity,
|
|
47
47
|
lockLengthMs,
|
|
48
48
|
revokable: o.revokable,
|
|
49
|
-
},
|
|
49
|
+
}, customTagsFromOptions(o));
|
|
50
50
|
const output = {
|
|
51
51
|
senderAddress: signerAddress,
|
|
52
52
|
transferResult: result,
|
|
@@ -71,7 +71,7 @@ export async function revokeVaultCLICommand(o) {
|
|
|
71
71
|
const result = await ario.revokeVault({
|
|
72
72
|
vaultId,
|
|
73
73
|
recipient,
|
|
74
|
-
},
|
|
74
|
+
}, customTagsFromOptions(o));
|
|
75
75
|
const output = {
|
|
76
76
|
senderAddress: signerAddress,
|
|
77
77
|
transferResult: result,
|
|
@@ -98,7 +98,7 @@ export async function createVaultCLICommand(o) {
|
|
|
98
98
|
const result = await ario.createVault({
|
|
99
99
|
quantity: mARIOQuantity,
|
|
100
100
|
lockLengthMs,
|
|
101
|
-
},
|
|
101
|
+
}, customTagsFromOptions(o));
|
|
102
102
|
const output = {
|
|
103
103
|
senderAddress: signerAddress,
|
|
104
104
|
transferResult: result,
|
|
@@ -124,7 +124,7 @@ export async function extendVaultCLICommand(o) {
|
|
|
124
124
|
const result = await ario.extendVault({
|
|
125
125
|
vaultId,
|
|
126
126
|
extendLengthMs,
|
|
127
|
-
},
|
|
127
|
+
}, customTagsFromOptions(o));
|
|
128
128
|
const output = {
|
|
129
129
|
senderAddress: signerAddress,
|
|
130
130
|
transferResult: result,
|
|
@@ -149,7 +149,7 @@ export async function increaseVaultCLICommand(o) {
|
|
|
149
149
|
const result = await ario.increaseVault({
|
|
150
150
|
vaultId,
|
|
151
151
|
quantity: mARIOQuantity,
|
|
152
|
-
},
|
|
152
|
+
}, customTagsFromOptions(o));
|
|
153
153
|
const output = {
|
|
154
154
|
senderAddress: signerAddress,
|
|
155
155
|
transferResult: result,
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -204,7 +204,7 @@ export function requiredInitiatorFromOptions(options) {
|
|
|
204
204
|
}
|
|
205
205
|
return requiredAddressFromOptions(options);
|
|
206
206
|
}
|
|
207
|
-
export function
|
|
207
|
+
export function customTagsFromOptions(options) {
|
|
208
208
|
if (options.tags === undefined) {
|
|
209
209
|
return {};
|
|
210
210
|
}
|
package/lib/esm/common/io.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
2
2
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
|
|
3
3
|
import { createAoSigner } from '../utils/ao.js';
|
|
4
|
-
import { getEpochDataFromGql, paginationParamsToTags, pruneTags, } from '../utils/arweave.js';
|
|
4
|
+
import { getEpochDataFromGql, paginationParamsToTags, pruneTags, removeEligibleRewardsFromEpochData, sortAndPaginateEpochDataIntoEligibleDistributions, } from '../utils/arweave.js';
|
|
5
5
|
import { defaultArweave } from './arweave.js';
|
|
6
6
|
import { AOProcess } from './contracts/ao-process.js';
|
|
7
7
|
import { InvalidContractConfigurationError } from './error.js';
|
|
@@ -85,7 +85,7 @@ export class ARIOReadable {
|
|
|
85
85
|
epochIndex: epochIndex,
|
|
86
86
|
processId: this.process.processId,
|
|
87
87
|
});
|
|
88
|
-
return epochData;
|
|
88
|
+
return removeEligibleRewardsFromEpochData(epochData);
|
|
89
89
|
}
|
|
90
90
|
// go to the process epoch and fetch the epoch data
|
|
91
91
|
const allTags = [
|
|
@@ -294,6 +294,26 @@ export class ARIOReadable {
|
|
|
294
294
|
tags: pruneTags(allTags),
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
+
async getEligibleEpochRewards(epoch, params) {
|
|
298
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
299
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
300
|
+
if (epochIndex !== undefined && epochIndex < currentIndex) {
|
|
301
|
+
const epochData = await getEpochDataFromGql({
|
|
302
|
+
arweave: this.arweave,
|
|
303
|
+
epochIndex: epochIndex,
|
|
304
|
+
processId: this.process.processId,
|
|
305
|
+
});
|
|
306
|
+
return sortAndPaginateEpochDataIntoEligibleDistributions(epochData, params);
|
|
307
|
+
}
|
|
308
|
+
// on current epoch, go to process and fetch the distributions
|
|
309
|
+
const allTags = [
|
|
310
|
+
{ name: 'Action', value: 'Epoch-Eligible-Rewards' },
|
|
311
|
+
...paginationParamsToTags(params),
|
|
312
|
+
];
|
|
313
|
+
return this.process.read({
|
|
314
|
+
tags: pruneTags(allTags),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
297
317
|
async getTokenCost({ intent, type, years, name, quantity, fromAddress, }) {
|
|
298
318
|
const replacedBuyRecordWithBuyName = intent === 'Buy-Record' ? 'Buy-Name' : intent;
|
|
299
319
|
const allTags = [
|
package/lib/esm/types/io.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { validateArweaveId } from '../utils/arweave.js';
|
|
2
|
+
export const isDistributedEpochData = (data) => {
|
|
3
|
+
return data.distributedTimestamp !== undefined;
|
|
4
|
+
};
|
|
5
|
+
export const isDistributedEpoch = (data) => {
|
|
6
|
+
return (data !== undefined &&
|
|
7
|
+
data.distributions !== undefined &&
|
|
8
|
+
isDistributedEpochData(data.distributions));
|
|
9
|
+
};
|
|
2
10
|
export const validIntents = [
|
|
3
11
|
'Buy-Name',
|
|
4
12
|
'Buy-Record', // for backwards compatibility
|
package/lib/esm/utils/arweave.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ARIO_TESTNET_PROCESS_ID, ARWEAVE_TX_REGEX } from '../constants.js';
|
|
2
|
+
import { isDistributedEpoch, } from '../types/io.js';
|
|
2
3
|
import { parseAoEpochData } from './ao.js';
|
|
3
4
|
export const validateArweaveId = (id) => {
|
|
4
5
|
return ARWEAVE_TX_REGEX.test(id);
|
|
@@ -94,3 +95,83 @@ export const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = ARIO_T
|
|
|
94
95
|
});
|
|
95
96
|
return gqlQuery;
|
|
96
97
|
};
|
|
98
|
+
export function sortAndPaginateEpochDataIntoEligibleDistributions(epochData, params) {
|
|
99
|
+
const rewards = [];
|
|
100
|
+
const sortBy = params?.sortBy ?? 'eligibleReward';
|
|
101
|
+
const sortOrder = params?.sortOrder ?? 'desc';
|
|
102
|
+
const limit = params?.limit ?? 100;
|
|
103
|
+
if (!isDistributedEpoch(epochData)) {
|
|
104
|
+
return {
|
|
105
|
+
hasMore: false,
|
|
106
|
+
items: [],
|
|
107
|
+
totalItems: 0,
|
|
108
|
+
limit,
|
|
109
|
+
sortOrder,
|
|
110
|
+
sortBy,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const eligibleDistributions = epochData?.distributions.rewards.eligible;
|
|
114
|
+
for (const [gatewayAddress, reward] of Object.entries(eligibleDistributions)) {
|
|
115
|
+
rewards.push({
|
|
116
|
+
type: 'operatorReward',
|
|
117
|
+
recipient: gatewayAddress,
|
|
118
|
+
eligibleReward: reward.operatorReward,
|
|
119
|
+
cursorId: gatewayAddress + '_' + gatewayAddress,
|
|
120
|
+
gatewayAddress,
|
|
121
|
+
});
|
|
122
|
+
for (const [delegateAddress, delegateRewardQty] of Object.entries(reward.delegateRewards)) {
|
|
123
|
+
rewards.push({
|
|
124
|
+
type: 'delegateReward',
|
|
125
|
+
recipient: delegateAddress,
|
|
126
|
+
eligibleReward: delegateRewardQty,
|
|
127
|
+
cursorId: gatewayAddress + '_' + delegateAddress,
|
|
128
|
+
gatewayAddress,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// sort the rewards by the sortBy
|
|
133
|
+
rewards.sort((a, b) => {
|
|
134
|
+
const aSort = a[sortBy];
|
|
135
|
+
const bSort = b[sortBy];
|
|
136
|
+
if (aSort === bSort || aSort === undefined || bSort === undefined) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
if (sortOrder === 'asc') {
|
|
140
|
+
return aSort > bSort ? 1 : -1;
|
|
141
|
+
}
|
|
142
|
+
return aSort < bSort ? 1 : -1;
|
|
143
|
+
});
|
|
144
|
+
// paginate the rewards
|
|
145
|
+
const start = params?.cursor !== undefined
|
|
146
|
+
? rewards.findIndex((r) => r.cursorId === params.cursor) + 1
|
|
147
|
+
: 0;
|
|
148
|
+
const end = limit ? start + limit : rewards.length;
|
|
149
|
+
return {
|
|
150
|
+
hasMore: end < rewards.length,
|
|
151
|
+
items: rewards.slice(start, end),
|
|
152
|
+
totalItems: rewards.length,
|
|
153
|
+
limit,
|
|
154
|
+
sortOrder,
|
|
155
|
+
nextCursor: rewards[end]?.cursorId,
|
|
156
|
+
sortBy,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function removeEligibleRewardsFromEpochData(epochData) {
|
|
160
|
+
if (epochData === undefined) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
if (!isDistributedEpoch(epochData)) {
|
|
164
|
+
return epochData;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...epochData,
|
|
168
|
+
distributions: {
|
|
169
|
+
...epochData.distributions,
|
|
170
|
+
rewards: {
|
|
171
|
+
...epochData.distributions.rewards,
|
|
172
|
+
// @ts-expect-error -- remove eligible rewards
|
|
173
|
+
eligible: undefined,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { strict as assert } from 'node:assert';
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
|
-
import { pruneTags } from './arweave.js';
|
|
3
|
+
import { pruneTags, sortAndPaginateEpochDataIntoEligibleDistributions, } from './arweave.js';
|
|
4
4
|
import { errorMessageFromOutput } from './index.js';
|
|
5
5
|
describe('pruneTags', () => {
|
|
6
6
|
it('should remove tags with undefined values', () => {
|
|
@@ -102,3 +102,101 @@ describe('errorMessageFromOutput', () => {
|
|
|
102
102
|
assert.equal(errorMessage, 'Already registered (line 128)');
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
|
+
describe('sortAndPaginateEpochDataIntoEligibleDistributions', () => {
|
|
106
|
+
const mockEpochData = {
|
|
107
|
+
distributions: {
|
|
108
|
+
distributedTimestamp: 1234567890,
|
|
109
|
+
rewards: {
|
|
110
|
+
eligible: {
|
|
111
|
+
gateway1: {
|
|
112
|
+
operatorReward: 50,
|
|
113
|
+
delegateRewards: {
|
|
114
|
+
delegate1: 20,
|
|
115
|
+
delegate2: 30,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
gateway2: {
|
|
119
|
+
operatorReward: 70,
|
|
120
|
+
delegateRewards: {
|
|
121
|
+
delegate3: 40,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
it('returns empty results when epochData is undefined', () => {
|
|
129
|
+
assert.deepEqual(sortAndPaginateEpochDataIntoEligibleDistributions(undefined), {
|
|
130
|
+
hasMore: false,
|
|
131
|
+
items: [],
|
|
132
|
+
totalItems: 0,
|
|
133
|
+
limit: 100,
|
|
134
|
+
sortOrder: 'desc',
|
|
135
|
+
sortBy: 'eligibleReward',
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
it('sorts rewards in descending order by eligibleReward', () => {
|
|
139
|
+
const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData);
|
|
140
|
+
assert.deepEqual(result.items, [
|
|
141
|
+
{
|
|
142
|
+
type: 'operatorReward',
|
|
143
|
+
recipient: 'gateway2',
|
|
144
|
+
eligibleReward: 70,
|
|
145
|
+
cursorId: 'gateway2_gateway2',
|
|
146
|
+
gatewayAddress: 'gateway2',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'operatorReward',
|
|
150
|
+
recipient: 'gateway1',
|
|
151
|
+
eligibleReward: 50,
|
|
152
|
+
cursorId: 'gateway1_gateway1',
|
|
153
|
+
gatewayAddress: 'gateway1',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
type: 'delegateReward',
|
|
157
|
+
recipient: 'delegate3',
|
|
158
|
+
eligibleReward: 40,
|
|
159
|
+
cursorId: 'gateway2_delegate3',
|
|
160
|
+
gatewayAddress: 'gateway2',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: 'delegateReward',
|
|
164
|
+
recipient: 'delegate2',
|
|
165
|
+
eligibleReward: 30,
|
|
166
|
+
cursorId: 'gateway1_delegate2',
|
|
167
|
+
gatewayAddress: 'gateway1',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: 'delegateReward',
|
|
171
|
+
recipient: 'delegate1',
|
|
172
|
+
eligibleReward: 20,
|
|
173
|
+
cursorId: 'gateway1_delegate1',
|
|
174
|
+
gatewayAddress: 'gateway1',
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
177
|
+
});
|
|
178
|
+
it('supports sorting in ascending order', () => {
|
|
179
|
+
const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
|
|
180
|
+
sortOrder: 'asc',
|
|
181
|
+
});
|
|
182
|
+
assert.equal(result.items[0].eligibleReward, 20);
|
|
183
|
+
assert.equal(result.items[result.items.length - 1].eligibleReward, 70);
|
|
184
|
+
});
|
|
185
|
+
it('paginates results correctly', () => {
|
|
186
|
+
const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
|
|
187
|
+
limit: 2,
|
|
188
|
+
});
|
|
189
|
+
assert.equal(result.items.length, 2);
|
|
190
|
+
assert.equal(result.hasMore, true);
|
|
191
|
+
assert.equal(result.nextCursor, 'gateway2_delegate3');
|
|
192
|
+
});
|
|
193
|
+
it('resumes pagination from cursor', () => {
|
|
194
|
+
const firstPage = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, { limit: 2 });
|
|
195
|
+
const secondPage = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
|
|
196
|
+
limit: 2,
|
|
197
|
+
cursor: firstPage.nextCursor,
|
|
198
|
+
});
|
|
199
|
+
assert.equal(secondPage.items.length, 2);
|
|
200
|
+
assert.equal(secondPage.items[0].cursorId, 'gateway1_delegate2');
|
|
201
|
+
});
|
|
202
|
+
});
|
package/lib/esm/version.js
CHANGED