Skip to content

Commit 78ff6cd

Browse files
authored
chore: altvm interface additions (#7300)
1 parent b12c3e9 commit 78ff6cd

13 files changed

Lines changed: 275 additions & 64 deletions

File tree

.changeset/pink-beds-act.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@hyperlane-xyz/cosmos-sdk": minor
3+
"@hyperlane-xyz/radix-sdk": minor
4+
"@hyperlane-xyz/utils": minor
5+
"@hyperlane-xyz/cli": minor
6+
"@hyperlane-xyz/sdk": minor
7+
---
8+
9+
add new methods for altvm interface

typescript/cli/src/context/altvm.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,10 @@ export class AltVMSignerFactory
203203
for (const chain of chains) {
204204
const metadata = metadataManager.getChainMetadata(chain);
205205

206-
if (metadata.protocol === ProtocolType.Ethereum) {
207-
continue;
208-
}
209-
210-
if (metadata.protocol === ProtocolType.Sealevel) {
211-
continue;
212-
}
213-
214206
const protocol = ALT_VM_SUPPORTED_PROTOCOLS[metadata.protocol];
215207

216208
if (!protocol) {
217-
throw new Error(
218-
`Chain ${chain} with protocol type ${metadata.protocol} not supported in AltVM`,
219-
);
209+
continue;
220210
}
221211

222212
const privateKey = await AltVMSignerFactory.loadPrivateKey(
@@ -245,10 +235,7 @@ export class AltVMSignerFactory
245235

246236
const factories: ProtocolMap<Record<string, SubmitterFactory>> = {};
247237

248-
if (
249-
protocol === ProtocolType.Ethereum ||
250-
protocol === ProtocolType.Sealevel
251-
) {
238+
if (!ALT_VM_SUPPORTED_PROTOCOLS[protocol]) {
252239
return factories;
253240
}
254241

typescript/cosmos-sdk/src/clients/provider.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
import {
3737
MsgCreateIgpEncodeObject,
3838
MsgCreateMerkleTreeHookEncodeObject,
39+
MsgCreateNoopHookEncodeObject,
3940
MsgSetDestinationGasConfigEncodeObject,
4041
MsgSetIgpOwnerEncodeObject,
4142
} from '../hyperlane/post_dispatch/messages.js';
@@ -65,6 +66,9 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
6566
private readonly cometClient: CometClient;
6667
private readonly rpcUrls: string[];
6768

69+
private static NULL_ADDRESS =
70+
'0x0000000000000000000000000000000000000000000000000000000000000000';
71+
6872
static async connect(
6973
rpcUrls: string[],
7074
_chainId: string | number,
@@ -113,11 +117,15 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
113117
}
114118

115119
async getBalance(req: AltVM.ReqGetBalance): Promise<bigint> {
120+
assert(req.denom, `denom required by ${CosmosNativeProvider.name}`);
121+
116122
const coin = await this.query.bank.balance(req.address, req.denom);
117123
return BigInt(coin.amount);
118124
}
119125

120126
async getTotalSupply(req: AltVM.ReqGetTotalSupply): Promise<bigint> {
127+
assert(req.denom, `denom required by ${CosmosNativeProvider.name}`);
128+
121129
const coin = await this.query.bank.supplyOf(req.denom);
122130
return BigInt(coin.amount);
123131
}
@@ -174,6 +182,10 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
174182
});
175183
assert(mailbox, `found no mailbox for id ${req.mailboxAddress}`);
176184

185+
if (mailbox.default_ism === CosmosNativeProvider.NULL_ADDRESS) {
186+
mailbox.default_ism = '';
187+
}
188+
177189
return {
178190
address: mailbox.id,
179191
owner: mailbox.owner,
@@ -353,6 +365,17 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
353365
};
354366
}
355367

368+
async getNoopHook(req: AltVM.ReqGetNoopHook): Promise<AltVM.ResGetNoopHook> {
369+
const { noop_hook } = await this.query.postDispatch.NoopHook({
370+
id: req.hookAddress,
371+
});
372+
assert(noop_hook, `found no noop hook for id ${req.hookAddress}`);
373+
374+
return {
375+
address: noop_hook.id,
376+
};
377+
}
378+
356379
// ### QUERY WARP ###
357380

358381
async getToken(req: AltVM.ReqGetToken): Promise<AltVM.ResGetToken> {
@@ -447,7 +470,6 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
447470
typeUrl: R.MsgCreateMailbox.proto.type,
448471
value: R.MsgCreateMailbox.proto.converter.create({
449472
local_domain: req.domainId,
450-
default_ism: req.defaultIsmAddress,
451473
owner: req.signer,
452474
}),
453475
};
@@ -660,16 +682,41 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
660682
};
661683
}
662684

685+
async getRemoveDestinationGasConfigTransaction(
686+
_req: AltVM.ReqRemoveDestinationGasConfig,
687+
): Promise<EncodeObject> {
688+
throw new Error(
689+
`RemoveDestinationGasConfig is currently not supported on Cosmos Native`,
690+
);
691+
}
692+
693+
async getCreateNoopHookTransaction(
694+
req: AltVM.ReqCreateNoopHook,
695+
): Promise<MsgCreateNoopHookEncodeObject> {
696+
return {
697+
typeUrl: R.MsgCreateNoopHook.proto.type,
698+
value: R.MsgCreateNoopHook.proto.converter.create({
699+
owner: req.signer,
700+
}),
701+
};
702+
}
703+
663704
async getCreateValidatorAnnounceTransaction(
664705
_req: AltVM.ReqCreateValidatorAnnounce,
665-
): Promise<any> {
706+
): Promise<EncodeObject> {
666707
throw new Error(
667708
'Cosmos Native does not support populateCreateValidatorAnnounce',
668709
);
669710
}
670711

671712
// ### GET WARP TXS ###
672713

714+
async getCreateNativeTokenTransaction(
715+
_req: AltVM.ReqCreateNativeToken,
716+
): Promise<EncodeObject> {
717+
throw new Error(`Native Token is not supported on Cosmos Native`);
718+
}
719+
673720
async getCreateCollateralTokenTransaction(
674721
req: AltVM.ReqCreateCollateralToken,
675722
): Promise<MsgCreateCollateralTokenEncodeObject> {
@@ -755,6 +802,8 @@ export class CosmosNativeProvider implements AltVM.IProvider<EncodeObject> {
755802
async getTransferTransaction(
756803
req: AltVM.ReqTransfer,
757804
): Promise<MsgSendEncodeObject> {
805+
assert(req.denom, `denom required by ${CosmosNativeProvider.name}`);
806+
758807
return {
759808
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
760809
value: {

typescript/cosmos-sdk/src/clients/signer.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ export class CosmosNativeSigner
385385
async createInterchainGasPaymasterHook(
386386
req: Omit<AltVM.ReqCreateInterchainGasPaymasterHook, 'signer'>,
387387
): Promise<AltVM.ResCreateInterchainGasPaymasterHook> {
388+
assert(req.denom, `denom required by ${CosmosNativeSigner.name}`);
389+
388390
const msg = await this.getCreateInterchainGasPaymasterHookTransaction({
389391
...req,
390392
signer: this.account.address,
@@ -424,6 +426,28 @@ export class CosmosNativeSigner
424426
};
425427
}
426428

429+
async removeDestinationGasConfig(
430+
_req: Omit<AltVM.ReqRemoveDestinationGasConfig, 'signer'>,
431+
): Promise<AltVM.ResRemoveDestinationGasConfig> {
432+
throw new Error(
433+
`RemoveDestinationGasConfig is currently not supported on Cosmos Native`,
434+
);
435+
}
436+
437+
async createNoopHook(
438+
req: Omit<AltVM.ReqCreateNoopHook, 'signer'>,
439+
): Promise<AltVM.ResCreateNoopHook> {
440+
const msg = await this.getCreateNoopHookTransaction({
441+
...req,
442+
signer: this.account.address,
443+
});
444+
445+
const result = await this.submitTx(msg);
446+
return {
447+
hookAddress: result.id,
448+
};
449+
}
450+
427451
async createValidatorAnnounce(
428452
_req: Omit<AltVM.ReqCreateValidatorAnnounce, 'signer'>,
429453
): Promise<AltVM.ResCreateValidatorAnnounce> {
@@ -433,6 +457,12 @@ export class CosmosNativeSigner
433457

434458
// ### TX WARP ###
435459

460+
async createNativeToken(
461+
_req: Omit<AltVM.ReqCreateNativeToken, 'signer'>,
462+
): Promise<AltVM.ResCreateNativeToken> {
463+
throw new Error(`Native Token is not supported on Cosmos Native`);
464+
}
465+
436466
async createCollateralToken(
437467
req: Omit<AltVM.ReqCreateCollateralToken, 'signer'>,
438468
): Promise<AltVM.ResCreateCollateralToken> {
@@ -520,6 +550,8 @@ export class CosmosNativeSigner
520550
async transfer(
521551
req: Omit<AltVM.ReqTransfer, 'signer'>,
522552
): Promise<AltVM.ResTransfer> {
553+
assert(req.denom, `denom required by ${CosmosNativeSigner.name}`);
554+
523555
const msg = await this.getTransferTransaction({
524556
...req,
525557
signer: this.account.address,

typescript/cosmos-sdk/src/tests/2_core.e2e-test.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ describe('2. cosmos sdk core e2e tests', async function () {
2222

2323
step('create new mailbox', async () => {
2424
// ARRANGE
25-
const { ismAddress } = await signer.createNoopIsm({});
26-
2725
const domainId = 1234;
2826

2927
// ACT
3028
const txResponse = await signer.createMailbox({
3129
domainId: domainId,
32-
defaultIsmAddress: ismAddress,
3330
});
3431

3532
// ASSERT
@@ -45,20 +42,17 @@ describe('2. cosmos sdk core e2e tests', async function () {
4542
expect(mailbox.address).to.equal(txResponse.mailboxAddress);
4643
expect(mailbox.owner).to.equal(signer.getSignerAddress());
4744
expect(mailbox.localDomain).to.equal(domainId);
48-
expect(mailbox.defaultIsm).to.equal(ismAddress);
45+
expect(mailbox.defaultIsm).to.be.empty;
4946
expect(mailbox.defaultHook).to.be.empty;
5047
expect(mailbox.requiredHook).to.be.empty;
5148
});
5249

5350
step('set mailbox owner', async () => {
5451
// ARRANGE
55-
const { ismAddress } = await signer.createNoopIsm({});
56-
5752
const domainId = 1234;
5853

5954
const { mailboxAddress } = await signer.createMailbox({
6055
domainId: domainId,
61-
defaultIsmAddress: ismAddress,
6256
});
6357

6458
let mailbox = await signer.getMailbox({ mailboxAddress });
@@ -77,15 +71,36 @@ describe('2. cosmos sdk core e2e tests', async function () {
7771
expect(mailbox.owner).to.equal(bobSigner.getSignerAddress());
7872
});
7973

80-
step('set mailbox default hook', async () => {
74+
step('set mailbox default ism', async () => {
8175
// ARRANGE
8276
const { ismAddress } = await signer.createNoopIsm({});
8377

8478
const domainId = 1234;
8579

8680
const { mailboxAddress } = await signer.createMailbox({
8781
domainId: domainId,
88-
defaultIsmAddress: ismAddress,
82+
});
83+
84+
let mailbox = await signer.getMailbox({ mailboxAddress });
85+
expect(mailbox.defaultIsm).to.be.empty;
86+
87+
// ACT
88+
await signer.setDefaultIsm({
89+
mailboxAddress,
90+
ismAddress,
91+
});
92+
93+
// ASSERT
94+
mailbox = await signer.getMailbox({ mailboxAddress });
95+
expect(mailbox.defaultIsm).to.equal(ismAddress);
96+
});
97+
98+
step('set mailbox default hook', async () => {
99+
// ARRANGE
100+
const domainId = 1234;
101+
102+
const { mailboxAddress } = await signer.createMailbox({
103+
domainId: domainId,
89104
});
90105

91106
const { hookAddress } = await signer.createMerkleTreeHook({
@@ -108,13 +123,10 @@ describe('2. cosmos sdk core e2e tests', async function () {
108123

109124
step('set mailbox required hook', async () => {
110125
// ARRANGE
111-
const { ismAddress } = await signer.createNoopIsm({});
112-
113126
const domainId = 1234;
114127

115128
const { mailboxAddress } = await signer.createMailbox({
116129
domainId: domainId,
117-
defaultIsmAddress: ismAddress,
118130
});
119131

120132
const { hookAddress } = await signer.createMerkleTreeHook({

typescript/cosmos-sdk/src/tests/3_post_dispatch.e2e-test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ describe('3. cosmos sdk post dispatch e2e tests', async function () {
4444

4545
step('create new Merkle Tree hook', async () => {
4646
// ARRANGE
47-
const { ismAddress } = await signer.createNoopIsm({});
48-
4947
const domainId = 1234;
5048

5149
const { mailboxAddress } = await signer.createMailbox({
5250
domainId: domainId,
53-
defaultIsmAddress: ismAddress,
5451
});
5552

5653
// ACT

0 commit comments

Comments
 (0)