ecash-agora
Version:
Library for interacting with the eCash Agora protocol
73 lines • 3.29 kB
JavaScript
;
// Copyright (c) 2025 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAgoraPaymentAction = void 0;
const ecash_lib_1 = require("ecash-lib");
const getAgoraPaymentAction = (action, dustSats = ecash_lib_1.DEFAULT_DUST_SATS) => {
const { type, tokenType, variant } = action;
switch (tokenType.protocol) {
case 'SLP': {
throw new Error('SLP is not currently supported.');
}
case 'ALP': {
switch (type) {
case 'LIST': {
/**
* Handle an ALP list action
*
* An ALP list action requires a data action and a send action
* Unlike SLP list actions, it can be completed in a single tx
*/
if (variant.type === 'ONESHOT') {
throw new Error('ALP ONESHOT listings are not currently supported');
}
/**
* We only support AgoraPartial listings for ALP
*
* An AgoraPartial listing requires
* - A data tokenAction of agoraPartial.adPushdata() at the beginning of the EMPP OP_RETURN
* - A SEND tokenAction to send the listed tokens to the p2sh output
* - A blank OP_RETURN template output at index 0
* - A p2sh output to hold the listed tokens
*
* ecash-wallet can handle token change and XEC change, so we do not need to build it here
*/
return {
outputs: [
{ sats: 0n },
{
sats: dustSats,
script: ecash_lib_1.Script.p2sh((0, ecash_lib_1.shaRmd160)(variant.params.script().bytecode)),
tokenId: variant.params.tokenId,
atoms: variant.params.offeredAtoms(),
isMintBaton: false,
},
],
tokenActions: [
{
type: 'DATA',
data: variant.params.adPushdata(),
},
{
type: 'SEND',
tokenId: variant.params.tokenId,
tokenType: tokenType,
},
],
};
}
default: {
// Cannot get here with valid typed input
throw new Error(`Unsupported agora action: ${type}`);
}
}
}
default: {
throw new Error(`Unsupported token protocol: ${tokenType.protocol}`);
}
}
};
exports.getAgoraPaymentAction = getAgoraPaymentAction;
//# sourceMappingURL=actions.js.map