Skip to content
Draft
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
6 changes: 6 additions & 0 deletions modules/sdk-coin-polyx/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export { NominateBuilder } from './nominateBuilder';
export { BatchUnstakingBuilder } from './batchUnstakingBuilder';
export { UnbondBuilder } from './unbondBuilder';
export { WithdrawUnbondedBuilder } from './withdrawUnbondedBuilder';
export { V8TransferBuilder } from './v8TransferBuilder';
export { V8HexTransferBuilder } from './v8HexTransferBuilder';
export { V8RegisterDidWithCDDBuilder } from './v8RegisterDidWithCDDBuilder';
export { V8TokenTransferBuilder } from './v8TokenTransferBuilder';
export { V8HexTokenTransferBuilder } from './v8HexTokenTransferBuilder';
export { V8PreApproveAssetBuilder } from './v8PreApproveAssetBuilder';
import polyxUtils from './utils';
export { Utils, default as utils } from './utils';
export * from './iface';
Expand Down
1 change: 0 additions & 1 deletion modules/sdk-coin-polyx/src/lib/preApproveAssetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class PreApproveAssetBuilder extends PolyxBaseBuilder<TxMethod, Transacti
* @returns {UnsignedTransaction} an unsigned transaction for asset pre-approval
*/
private preApproveAsset(args: PreApproveAssetArgs, info: Interface.CreateBaseTxInfo): UnsignedTransaction {
console.log(`PreApproveAssetBuilder: preApproveAsset called with args: ${JSON.stringify(args)}`);
return defineMethod(
{
method: {
Expand Down
30 changes: 30 additions & 0 deletions modules/sdk-coin-polyx/src/lib/transactionBuilderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import { TokenTransferBuilder } from './tokenTransferBuilder';
import { HexTokenTransferBuilder } from './hexTokenTransferBuilder';
import { RejectInstructionBuilder } from './rejectInstructionBuilder';
import { NominateBuilder } from './nominateBuilder';
import { V8TransferBuilder } from './v8TransferBuilder';
import { V8HexTransferBuilder } from './v8HexTransferBuilder';
import { V8RegisterDidWithCDDBuilder } from './v8RegisterDidWithCDDBuilder';
import { V8TokenTransferBuilder } from './v8TokenTransferBuilder';
import { V8HexTokenTransferBuilder } from './v8HexTokenTransferBuilder';
import { V8PreApproveAssetBuilder } from './v8PreApproveAssetBuilder';

export type SupportedTransaction = BaseTransaction | PolyxTransaction;

Expand Down Expand Up @@ -82,6 +88,30 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory {
return new NominateBuilder(this._coinConfig).material(this._material);
}

getV8TransferBuilder(): V8TransferBuilder {
return new V8TransferBuilder(this._coinConfig);
}

getV8HexTransferBuilder(): V8HexTransferBuilder {
return new V8HexTransferBuilder(this._coinConfig);
}

getV8RegisterDidWithCDDBuilder(): V8RegisterDidWithCDDBuilder {
return new V8RegisterDidWithCDDBuilder(this._coinConfig);
}

getV8TokenTransferBuilder(): V8TokenTransferBuilder {
return new V8TokenTransferBuilder(this._coinConfig);
}

getV8HexTokenTransferBuilder(): V8HexTokenTransferBuilder {
return new V8HexTokenTransferBuilder(this._coinConfig);
}

getV8PreApproveAssetBuilder(): V8PreApproveAssetBuilder {
return new V8PreApproveAssetBuilder(this._coinConfig);
}

getWalletInitializationBuilder(): void {
throw new NotImplementedError(`walletInitialization for ${this._coinConfig.name} not implemented`);
}
Expand Down
8 changes: 7 additions & 1 deletion modules/sdk-coin-polyx/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Utils as SubstrateUtils, Interface } from '@bitgo/abstract-substrate';
import { NetworkType } from '@bitgo/statics';
import { TypeRegistry } from '@substrate/txwrapper-core/lib/types';
import { mainnetMaterial, testnetMaterial } from '../resources';
import { mainnetMaterial, testnetMaterial, mainnetV8Material, testnetV8Material } from '../resources';
import { BatchCallObject } from './iface';
import { MEMO_HEX_REGEX, MEMO_MAX_BYTES, POLYX_DID_REGEX } from './constants';

Expand Down Expand Up @@ -77,6 +77,12 @@ export class Utils extends SubstrateUtils {
return (networkType === NetworkType.MAINNET ? mainnetMaterial : testnetMaterial) as unknown as Interface.Material;
}

getV8Material(networkType: NetworkType): Interface.Material {
return (networkType === NetworkType.MAINNET
? mainnetV8Material
: testnetV8Material) as unknown as Interface.Material;
}

decodeMethodName(call: BatchCallObject, registry: TypeRegistry): string {
// Handle both callIndex and method formats
const callWithIndex = call as BatchCallObject & { callIndex?: string };
Expand Down
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8HexTokenTransferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { HexTokenTransferBuilder } from './hexTokenTransferBuilder';
import utils from './utils';

/**
* Builds a Polymesh settlement.addAndAffirmWithMediators transaction using
* the hex (NEW) memo encoding against Polymesh v8 chain metadata. Identical
* behaviour to HexTokenTransferBuilder; only the material differs.
*/
export class V8HexTokenTransferBuilder extends HexTokenTransferBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8HexTransferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { HexTransferBuilder } from './hexTransferBuilder';
import utils from './utils';

/**
* Builds a POLYX balances.transferWithMemo transaction using the hex
* (NEW) memo encoding against Polymesh v8 chain metadata. Identical
* behaviour to HexTransferBuilder; only the material differs.
*/
export class V8HexTransferBuilder extends HexTransferBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8PreApproveAssetBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { PreApproveAssetBuilder } from './preApproveAssetBuilder';
import utils from './utils';

/**
* Builds a Polymesh asset.preApproveAsset transaction against Polymesh v8
* chain metadata. Identical behaviour to PreApproveAssetBuilder; only the
* material differs.
*/
export class V8PreApproveAssetBuilder extends PreApproveAssetBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8RegisterDidWithCDDBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { RegisterDidWithCDDBuilder } from './registerDidWithCDDBuilder';
import utils from './utils';

/**
* Builds a Polymesh identity.cddRegisterDidWithCdd transaction against
* Polymesh v8 chain metadata. Identical behaviour to
* RegisterDidWithCDDBuilder; only the material differs.
*/
export class V8RegisterDidWithCDDBuilder extends RegisterDidWithCDDBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8TokenTransferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { TokenTransferBuilder } from './tokenTransferBuilder';
import utils from './utils';

/**
* Builds a Polymesh settlement.addAndAffirmWithMediators transaction against
* Polymesh v8 chain metadata. Identical behaviour to TokenTransferBuilder;
* only the material differs.
*/
export class V8TokenTransferBuilder extends TokenTransferBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
15 changes: 15 additions & 0 deletions modules/sdk-coin-polyx/src/lib/v8TransferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { TransferBuilder } from './transferBuilder';
import utils from './utils';

/**
* Builds a POLYX balances.transferWithMemo transaction against Polymesh v8
* chain metadata. Identical behaviour to TransferBuilder; only the material
* (specVersion / txVersion) differs.
*/
export class V8TransferBuilder extends TransferBuilder {
constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this.material(utils.getV8Material(_coinConfig.network.type));
}
}
2 changes: 2 additions & 0 deletions modules/sdk-coin-polyx/src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './mainnet';
export * from './testnet';
export * from './mainnetV8';
export * from './testnetV8';
13 changes: 13 additions & 0 deletions modules/sdk-coin-polyx/src/resources/mainnetV8.ts

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions modules/sdk-coin-polyx/src/resources/testnetV8.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import should from 'should';
import { V8HexTokenTransferBuilder, TransactionBuilderFactory } from '../../../src/lib';
import { accounts, mockTssSignature } from '../../resources';
import { testnetV8Material } from '../../../src/resources';
import { buildTestConfig } from './base';

const FROM_DID = '0x1208d7851e6698249aea40742701ee1ef6cdcced260a7c49c1cca1a9db836342';
const TO_DID = '0xbc6f7ec808f361c1353ab9dc88c3cc54b98d9eb60fed9c063e67a40925b8ef61';
const ASSET_ID = '0x780602887b358cf48989d0d9aa6c8d28';

describe('V8HexTokenTransferBuilder', () => {
describe('v8 material', () => {
it('carries v8 specVersion and txVersion', () => {
const builder = new V8HexTokenTransferBuilder(buildTestConfig());
const material = (builder as any)._material;
should.equal(material.specVersion, testnetV8Material.specVersion);
should.equal(material.txVersion, testnetV8Material.txVersion);
});
});

describe('factory method', () => {
it('getV8HexTokenTransferBuilder returns a V8HexTokenTransferBuilder', () => {
const factory = new TransactionBuilderFactory(buildTestConfig());
should.ok(factory.getV8HexTokenTransferBuilder() instanceof V8HexTokenTransferBuilder);
});
});

describe('memo encoding', () => {
it('encodes memo in NEW (hex) format', () => {
const builder = new V8HexTokenTransferBuilder(buildTestConfig());
builder.memo('56594');
const memo = (builder as any)._memo as string;
should.ok(memo.startsWith('0x'), `expected 0x-prefixed hex memo, got: ${memo}`);
should.equal(memo.length, 66);
});
});

describe('build transaction', () => {
const sender = accounts.account1;

it('should build a v8 hex token transfer transaction with v8 specVersion in output', async () => {
const builder = new V8HexTokenTransferBuilder(buildTestConfig())
.assetId(ASSET_ID)
.amount('1000000')
.fromDID(FROM_DID)
.toDID(TO_DID)
.memo('56594')
.sender({ address: sender.address })
.validity({ firstValid: 3933, maxDuration: 64 })
.referenceBlock('0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d')
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: 1 })
.fee({ amount: 0, type: 'tip' });
builder.addSignature({ pub: sender.publicKey }, Buffer.from(mockTssSignature, 'hex'));
const tx = await builder.build();

const txJson = tx.toJson();
should.deepEqual(txJson.specVersion, testnetV8Material.specVersion);
should.deepEqual(txJson.transactionVersion, testnetV8Material.txVersion);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import should from 'should';
import { V8HexTransferBuilder, TransactionBuilderFactory } from '../../../src/lib';
import { accounts, mockTssSignature } from '../../resources';
import { testnetV8Material } from '../../../src/resources';
import { buildTestConfig } from './base';

describe('V8HexTransferBuilder', () => {
describe('v8 material', () => {
it('carries v8 specVersion and txVersion', () => {
const builder = new V8HexTransferBuilder(buildTestConfig());
const material = (builder as any)._material;
should.equal(material.specVersion, testnetV8Material.specVersion);
should.equal(material.txVersion, testnetV8Material.txVersion);
});
});

describe('factory method', () => {
it('getV8HexTransferBuilder returns a V8HexTransferBuilder', () => {
const factory = new TransactionBuilderFactory(buildTestConfig());
should.ok(factory.getV8HexTransferBuilder() instanceof V8HexTransferBuilder);
});
});

describe('memo encoding', () => {
it('encodes memo in NEW (hex) format', () => {
const builder = new V8HexTransferBuilder(buildTestConfig());
builder.memo('56594');
const memo = (builder as any)._memo as string;
should.ok(memo.startsWith('0x'), `expected 0x-prefixed hex memo, got: ${memo}`);
should.equal(memo.length, 66);
});

it('stores an already-encoded hex memo as-is', () => {
const builder = new V8HexTransferBuilder(buildTestConfig());
const encoded = '0x3536353934000000000000000000000000000000000000000000000000000000';
builder.memo(encoded);
should.equal((builder as any)._memo, encoded);
});
});

describe('build transaction', () => {
const sender = accounts.account1;
const receiver = accounts.account2;

it('should build a v8 hex transfer transaction', async () => {
const builder = new V8HexTransferBuilder(buildTestConfig())
.amount('1000000')
.to({ address: receiver.address })
.sender({ address: sender.address })
.memo('56594')
.validity({ firstValid: 3933, maxDuration: 64 })
.referenceBlock('0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d')
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: 1 })
.fee({ amount: 0, type: 'tip' });
builder.addSignature({ pub: sender.publicKey }, Buffer.from(mockTssSignature, 'hex'));
const tx = await builder.build();

const txJson = tx.toJson();
should.deepEqual(txJson.specVersion, testnetV8Material.specVersion);
should.deepEqual(txJson.transactionVersion, testnetV8Material.txVersion);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import should from 'should';
import { V8PreApproveAssetBuilder, TransactionBuilderFactory } from '../../../src/lib';
import { accounts, mockTssSignature } from '../../resources';
import { testnetV8Material } from '../../../src/resources';
import { buildTestConfig } from './base';

const ASSET_ID = '0x780602887b358cf48989d0d9aa6c8d28';

describe('V8PreApproveAssetBuilder', () => {
describe('v8 material', () => {
it('carries v8 specVersion and txVersion', () => {
const builder = new V8PreApproveAssetBuilder(buildTestConfig());
const material = (builder as any)._material;
should.equal(material.specVersion, testnetV8Material.specVersion);
should.equal(material.txVersion, testnetV8Material.txVersion);
});
});

describe('factory method', () => {
it('getV8PreApproveAssetBuilder returns a V8PreApproveAssetBuilder', () => {
const factory = new TransactionBuilderFactory(buildTestConfig());
should.ok(factory.getV8PreApproveAssetBuilder() instanceof V8PreApproveAssetBuilder);
});
});

describe('build transaction', () => {
const sender = accounts.account1;

it('should build a v8 pre-approve asset transaction with v8 specVersion in output', async () => {
const builder = new V8PreApproveAssetBuilder(buildTestConfig())
.assetId(ASSET_ID)
.sender({ address: sender.address })
.validity({ firstValid: 3933, maxDuration: 64 })
.referenceBlock('0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d')
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: 1 })
.fee({ amount: 0, type: 'tip' });
builder.addSignature({ pub: sender.publicKey }, Buffer.from(mockTssSignature, 'hex'));
const tx = await builder.build();

const txJson = tx.toJson();
should.deepEqual(txJson.specVersion, testnetV8Material.specVersion);
should.deepEqual(txJson.transactionVersion, testnetV8Material.txVersion);
});
});
});
Loading
Loading