Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdk-coin-xrp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"lodash": "^4.18.0",
"ripple-binary-codec": "2.1.0",
"ripple-keypairs": "2.0.0",
"xrpl": "4.0.0"
"xrpl": "4.6.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.80.1",
Expand Down
15 changes: 5 additions & 10 deletions modules/sdk-coin-xrp/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as querystring from 'querystring';
import * as rippleKeypairs from 'ripple-keypairs';
import * as url from 'url';
import * as xrpl from 'xrpl';
import { Amount, IssuedCurrencyAmount } from 'xrpl';
import { Amount, IssuedCurrencyAmount, MPTAmount } from 'xrpl';
import { VALID_ACCOUNT_SET_FLAGS } from './constants';
import { Address, SignerDetails } from './iface';
import { KeyPair as XrpKeyPair } from './keyPair';
Expand Down Expand Up @@ -221,16 +221,11 @@ class Utils implements BaseUtils {
}

/**
* Determines if the provided `amount` is for a token payment
* Determines if the provided `amount` is for a trust-line token payment (IssuedCurrencyAmount).
* Uses `in` narrowing — safe for Amount | MPTAmount without unsafe casts.
*/
public isIssuedCurrencyAmount(amount: Amount): amount is IssuedCurrencyAmount {
return (
!!amount &&
typeof amount === 'object' &&
typeof amount.currency === 'string' &&
typeof amount.issuer === 'string' &&
typeof amount.value === 'string'
);
public isIssuedCurrencyAmount(amount: Amount | MPTAmount): amount is IssuedCurrencyAmount {
return typeof amount === 'object' && 'currency' in amount && 'issuer' in amount && 'value' in amount;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions modules/sdk-coin-xrp/test/unit/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,32 @@ describe('Utils', () => {
});
});

describe('isIssuedCurrencyAmount', () => {
it('should return true for a valid trust-line IssuedCurrencyAmount', () => {
const amount = { currency: 'USD', issuer: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', value: '100' };
XrpUtils.isIssuedCurrencyAmount(amount).should.be.true();
});

it('should return false for native XRP string amount', () => {
XrpUtils.isIssuedCurrencyAmount('1000000' as any).should.be.false();
});

it('should return false for an MPTAmount (mpt_issuance_id + value, no currency/issuer)', () => {
const amount = { mpt_issuance_id: '00F633BCDD435DCB9EE57E47809EDE01BBB050679C488A97', value: '1000' };
XrpUtils.isIssuedCurrencyAmount(amount as any).should.be.false();
});

it('should return false if currency field is missing', () => {
const amount = { issuer: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', value: '100' };
XrpUtils.isIssuedCurrencyAmount(amount as any).should.be.false();
});

it('should return false if issuer field is missing', () => {
const amount = { currency: 'USD', value: '100' };
XrpUtils.isIssuedCurrencyAmount(amount as any).should.be.false();
});
});

describe('validateAccountSetFlag', () => {
it('should throw an error if the flag is not a valid number', () => {
const invalidFlag = 'invalid';
Expand Down
113 changes: 113 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export interface XrpCoinConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
}

export interface XrpMptCoinConstructorOptions extends AccountConstructorOptions {
mptIssuanceId: string; // 48-char hex MPTokenIssuanceID — stored as contractAddress
canTransfer: boolean; // immutable lsfMPTCanTransfer (0x0008) flag
assetScale: number; // immutable AssetScale from MPTokenIssuanceCreate
}

export interface SuiCoinConstructorOptions extends AccountConstructorOptions {
packageId: string;
module: string;
Expand Down Expand Up @@ -607,6 +613,34 @@ export class XrpCoin extends AccountCoinToken {
}
}

/**
* XRP Ledger Multi-Purpose Token (MPT) — MPTokensV1 amendment.
* Identified by a 48-char hex MPTokenIssuanceID stored as contractAddress.
* Uses account_objects (not account_lines). No issuer::currency pattern.
* Named xrp:<token_name> — same pattern as trust-line tokens.
*/
export class XrpMptCoin extends AccountCoinToken {
public readonly contractAddress: string; // MPTokenIssuanceID
public readonly canTransfer: boolean; // immutable — set at MPTokenIssuanceCreate

constructor(options: XrpMptCoinConstructorOptions) {
super({ ...options });

if (!/^[0-9a-fA-F]{48}$/.test(options.mptIssuanceId)) {
throw new InvalidContractAddressError(options.name, options.mptIssuanceId);
}

if (!Number.isInteger(options.assetScale) || options.assetScale < 0 || options.assetScale > 255) {
throw new Error(
`invalid assetScale '${options.assetScale}' for coin '${options.name}': must be an integer between 0 and 255 (uint8)`
);
}

this.contractAddress = options.mptIssuanceId;
Comment thread
HimanshuS2212 marked this conversation as resolved.
this.canTransfer = options.canTransfer;
Comment thread
mullapudipruthvik marked this conversation as resolved.
Comment thread
mullapudipruthvik marked this conversation as resolved.
}
}

export class SuiCoin extends AccountCoinToken {
public packageId: string;
public module: string;
Expand Down Expand Up @@ -3313,6 +3347,85 @@ export function txrpToken(
);
}

/**
* Factory function for mainnet XRP MPT token instances.
*
* @param id uuid v4
* @param name unique identifier of the token, e.g. "xrp:my_mpt"
* @param fullName Complete human-readable name of the token
* @param mptIssuanceId 48-char hex MPTokenIssuanceID
* @param canTransfer immutable lsfMPTCanTransfer flag from MPTokenIssuanceCreate
* @param assetScale immutable display decimal places from MPTokenIssuanceCreate (also used as decimalPlaces)
* @param asset UnderlyingAsset enum value
* @param features Optional coin features
* @param network Optional network override (defaults to mainnet XRP)
*/
export function xrpMptToken(
id: string,
name: string,
fullName: string,
mptIssuanceId: string,
canTransfer: boolean,
assetScale: number,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.xrp,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new XrpMptCoin({
id,
name,
fullName,
network,
mptIssuanceId,
canTransfer,
assetScale,
prefix,
suffix,
features,
decimalPlaces: assetScale, // assetScale IS the display decimal places — same concept as decimalPlaces elsewhere
Comment thread
HimanshuS2212 marked this conversation as resolved.
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.XRP,
})
);
}

/**
* Factory function for testnet XRP MPT token instances.
*/
export function txrpMptToken(
id: string,
name: string,
fullName: string,
mptIssuanceId: string,
canTransfer: boolean,
assetScale: number,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.test.xrp
) {
return xrpMptToken(
id,
name,
fullName,
mptIssuanceId,
canTransfer,
assetScale,
asset,
features,
prefix,
suffix,
network
);
}

/**
* Factory function for sui token instances.
*
Expand Down
3 changes: 3 additions & 0 deletions modules/statics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export {
TaoCoin,
PolyxCoin,
XrpCoin,
XrpMptCoin,
xrpMptToken,
txrpMptToken,
Comment thread
mullapudipruthvik marked this conversation as resolved.
AptCoin,
AptNFTCollection,
Sip10Token,
Expand Down
32 changes: 31 additions & 1 deletion modules/statics/src/tokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
VetToken,
WorldERC20Token,
XrpCoin,
XrpMptCoin,
ZkethERC20Token,
VetNFTCollection,
AdaToken,
Expand Down Expand Up @@ -106,6 +107,11 @@ export type XrpTokenConfig = BaseNetworkConfig & {
contractAddress: string;
};

export type XrpMptTokenConfig = BaseNetworkConfig & {
contractAddress: string; // MPTokenIssuanceID (48-char hex)
canTransfer: boolean; // immutable lsfMPTCanTransfer flag
};

export type SuiTokenConfig = BaseNetworkConfig & {
packageId: string;
module: string;
Expand Down Expand Up @@ -180,6 +186,7 @@ export type TokenConfig =
| AlgoTokenConfig
| TrxTokenConfig
| XrpTokenConfig
| XrpMptTokenConfig
| SuiTokenConfig
| AptTokenConfig
| AptNFTCollectionConfig
Expand Down Expand Up @@ -225,7 +232,7 @@ export interface TokenNetwork {
hbar: { tokens: HbarTokenConfig[] };
ada: { tokens: AdaTokenConfig[] };
trx: { tokens: TrxTokenConfig[] };
xrp: { tokens: XrpTokenConfig[] };
xrp: { tokens: XrpTokenConfig[]; mptTokens: XrpMptTokenConfig[] };
zketh: { tokens: EthLikeTokenConfig[] };
sui: { tokens: SuiTokenConfig[] };
tao: { tokens: TaoTokenConfig[] };
Expand Down Expand Up @@ -932,6 +939,26 @@ const getFormattedXrpTokens = (customCoinMap = coins) =>
return acc;
}, []);

function getXrpMptTokenConfig(coin: XrpMptCoin): XrpMptTokenConfig {
return {
type: coin.name,
coin: coin.network.type === NetworkType.MAINNET ? 'xrp' : 'txrp',
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
name: coin.fullName,
decimalPlaces: coin.decimalPlaces, // set from assetScale in factory (same concept)
contractAddress: coin.contractAddress,
canTransfer: coin.canTransfer,
};
}

const getFormattedXrpMptTokens = (customCoinMap = coins) =>
customCoinMap.reduce((acc: XrpMptTokenConfig[], coin) => {
if (coin instanceof XrpMptCoin) {
acc.push(getXrpMptTokenConfig(coin));
}
return acc;
}, []);

function getSuiTokenConfig(coin: SuiCoin): SuiTokenConfig {
return {
type: coin.name,
Expand Down Expand Up @@ -1373,6 +1400,7 @@ export const getFormattedTokensByNetwork = (network: 'Mainnet' | 'Testnet', coin
},
xrp: {
tokens: getFormattedXrpTokens(coinMap).filter((token) => token.network === network),
mptTokens: getFormattedXrpMptTokens(coinMap).filter((token) => token.network === network),
},
sui: {
tokens: getFormattedSuiTokens(coinMap).filter((token) => token.network === network),
Expand Down Expand Up @@ -1552,6 +1580,8 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
return getAdaTokenConfig(coin);
} else if (coin instanceof TronErc20Coin) {
return getTrxTokenConfig(coin);
} else if (coin instanceof XrpMptCoin) {
return getXrpMptTokenConfig(coin);
} else if (coin instanceof XrpCoin) {
return getXrpTokenConfig(coin);
} else if (coin instanceof SuiCoin) {
Expand Down
31 changes: 16 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6998,12 +6998,12 @@
eventemitter3 "5.0.1"
ws "^8.13.0"

"@xrplf/secret-numbers@^1.0.0":
version "1.0.0"
resolved "https://registry.npmjs.org/@xrplf/secret-numbers/-/secret-numbers-1.0.0.tgz"
integrity sha512-qsCLGyqe1zaq9j7PZJopK+iGTGRbk6akkg6iZXJJgxKwck0C5x5Gnwlb1HKYGOwPKyrXWpV6a2YmcpNpUFctGg==
"@xrplf/secret-numbers@^2.0.0":
version "2.0.0"
resolved "https://registry.npmjs.org/@xrplf/secret-numbers/-/secret-numbers-2.0.0.tgz#36ffa45c41e78efc6179ca4fe9d950260103dbce"
integrity sha512-z3AOibRTE9E8MbjgzxqMpG1RNaBhQ1jnfhNCa1cGf2reZUJzPMYs4TggQTc7j8+0WyV3cr7y/U8Oz99SXIkN5Q==
dependencies:
"@xrplf/isomorphic" "^1.0.0"
"@xrplf/isomorphic" "^1.0.1"
ripple-keypairs "^2.0.0"

"@xtuc/ieee754@^1.2.0":
Expand Down Expand Up @@ -18352,10 +18352,10 @@ ripple-binary-codec@2.1.0:
bignumber.js "^9.0.0"
ripple-address-codec "^5.0.0"

ripple-binary-codec@^2.1.0:
version "2.5.0"
resolved "https://registry.npmjs.org/ripple-binary-codec/-/ripple-binary-codec-2.5.0.tgz"
integrity sha512-n2EPs3YRX0/XE6zO8Mav/XFmI1wWmWraCRyCSb0fQ0Fkpv4kJ1tMhQXfX9E/DbLtyXbeogcoxYsQZtAmG8u+Ww==
ripple-binary-codec@^2.7.0:
version "2.7.0"
resolved "https://registry.npmjs.org/ripple-binary-codec/-/ripple-binary-codec-2.7.0.tgz#987448c14e3734f4161b0ccd9ff97624c25973f3"
integrity sha512-gEBqan5muVp+q7jgZ6aUniSyN+e4FKRzn9uFAeFSIW7IgvkezP1cUolNtpahQ+jvaSK/33hxZA7wNmn1mc330g==
dependencies:
"@xrplf/isomorphic" "^1.0.1"
bignumber.js "^9.0.0"
Expand Down Expand Up @@ -21428,19 +21428,20 @@ xmlbuilder@~11.0.0:
resolved "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz"
integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==

xrpl@4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/xrpl/-/xrpl-4.0.0.tgz"
integrity sha512-VZm1lQWHQ6PheAAFGdH+ISXKvqB2hZDQ0w4ZcdAEtmqZQXtSIVQHOKPz95rEgGANbos7+XClxJ73++joPhA8Cw==
xrpl@4.6.0:
version "4.6.0"
resolved "https://registry.npmjs.org/xrpl/-/xrpl-4.6.0.tgz#1df29a1f0157b115d9c8788d94b222d154d01154"
integrity sha512-0nXZfqDHRJ6bsDv1WtA9MdCYalMtXuxVa9mtLdqT3xypRKf2LwT5DbuGL/kHcVfuqk3B+ly+SFARlrnX+LHtRQ==
dependencies:
"@scure/bip32" "^1.3.1"
"@scure/bip39" "^1.2.1"
"@xrplf/isomorphic" "^1.0.1"
"@xrplf/secret-numbers" "^1.0.0"
"@xrplf/secret-numbers" "^2.0.0"
bignumber.js "^9.0.0"
eventemitter3 "^5.0.1"
fast-json-stable-stringify "^2.1.0"
ripple-address-codec "^5.0.0"
ripple-binary-codec "^2.1.0"
ripple-binary-codec "^2.7.0"
ripple-keypairs "^2.0.0"

xss@1.0.13:
Expand Down
Loading