Skip to content

Commit

Permalink
feat: the cosmoswasm contract compiles the ts execution library (#34)
Browse files Browse the repository at this point in the history
* feat: the cosmoswasm contract compiles the ts execution library

* feat: codegen dir

* build: rm cosmoswasm-codegen

* cleanup

---------

Co-authored-by: Amit Yadav <amy29981@gmail.com>
  • Loading branch information
muniz-side and amityadav0 authored Aug 21, 2023
1 parent 41ddd20 commit 014013a
Show file tree
Hide file tree
Showing 17 changed files with 2,683 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Cargo.lock
/.DS_Store
contracts/.DS_Store
contracts/ics100/.DS_Store
contracts/ics101/.DS_Store
contracts/ics101/.DS_Store
node_modules
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@ ibcswap-wasm is a Cosmwasm implementation of the ICS 100 and ICS 101 specificati
# Documentation

- [ICS100](./docs/ics100.md)
- [ICS101](./docs/ics101.md)
- [ICS101](./docs/ics101.md)




# run ts-codegen

[TS-Codegen](https://github.com/CosmWasm/ts-codegen#readme)

```bash
cd codegen
yarn
yarn ts-codegen
```
310 changes: 310 additions & 0 deletions codegen/cosmoswasm-codegen/Ics100.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
/**
* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { StdFee } from "@cosmjs/amino";
import { Timestamp, Uint64, Uint128, Status, DetailsResponse, MakeSwapMsg, Coin, Height, TakeSwapMsg, ExecuteMsg, CancelSwapMsg, HeightOutput, InstantiateMsg, ListResponse, AtomicSwapOrder, QueryMsg } from "./Ics100.types";
export interface Ics100ReadOnlyInterface {
contractAddress: string;
list: ({
limit,
startAfter
}: {
limit?: number;
startAfter?: string;
}) => Promise<ListResponse>;
listByDesiredTaker: ({
desiredTaker,
limit,
startAfter
}: {
desiredTaker: string;
limit?: number;
startAfter?: string;
}) => Promise<ListByDesiredTakerResponse>;
listByMaker: ({
limit,
maker,
startAfter
}: {
limit?: number;
maker: string;
startAfter?: string;
}) => Promise<ListByMakerResponse>;
listByTaker: ({
limit,
startAfter,
taker
}: {
limit?: number;
startAfter?: string;
taker: string;
}) => Promise<ListByTakerResponse>;
details: ({
id
}: {
id: string;
}) => Promise<DetailsResponse>;
}
export class Ics100QueryClient implements Ics100ReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.list = this.list.bind(this);
this.listByDesiredTaker = this.listByDesiredTaker.bind(this);
this.listByMaker = this.listByMaker.bind(this);
this.listByTaker = this.listByTaker.bind(this);
this.details = this.details.bind(this);
}

list = async ({
limit,
startAfter
}: {
limit?: number;
startAfter?: string;
}): Promise<ListResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list: {
limit,
start_after: startAfter
}
});
};
listByDesiredTaker = async ({
desiredTaker,
limit,
startAfter
}: {
desiredTaker: string;
limit?: number;
startAfter?: string;
}): Promise<ListByDesiredTakerResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list_by_desired_taker: {
desired_taker: desiredTaker,
limit,
start_after: startAfter
}
});
};
listByMaker = async ({
limit,
maker,
startAfter
}: {
limit?: number;
maker: string;
startAfter?: string;
}): Promise<ListByMakerResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list_by_maker: {
limit,
maker,
start_after: startAfter
}
});
};
listByTaker = async ({
limit,
startAfter,
taker
}: {
limit?: number;
startAfter?: string;
taker: string;
}): Promise<ListByTakerResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list_by_taker: {
limit,
start_after: startAfter,
taker
}
});
};
details = async ({
id
}: {
id: string;
}): Promise<DetailsResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
details: {
id
}
});
};
}
export interface Ics100Interface extends Ics100ReadOnlyInterface {
contractAddress: string;
sender: string;
makeSwap: ({
buyToken,
createTimestamp,
desiredTaker,
expirationTimestamp,
makerAddress,
makerReceivingAddress,
sellToken,
sourceChannel,
sourcePort,
timeoutHeight,
timeoutTimestamp
}: {
buyToken: Coin;
createTimestamp: number;
desiredTaker: string;
expirationTimestamp: number;
makerAddress: string;
makerReceivingAddress: string;
sellToken: Coin;
sourceChannel: string;
sourcePort: string;
timeoutHeight: Height;
timeoutTimestamp: number;
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
takeSwap: ({
createTimestamp,
orderId,
sellToken,
takerAddress,
takerReceivingAddress,
timeoutHeight,
timeoutTimestamp
}: {
createTimestamp: number;
orderId: string;
sellToken: Coin;
takerAddress: string;
takerReceivingAddress: string;
timeoutHeight: Height;
timeoutTimestamp: number;
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
cancelSwap: ({
createTimestamp,
makerAddress,
orderId,
timeoutHeight,
timeoutTimestamp
}: {
createTimestamp: string;
makerAddress: string;
orderId: string;
timeoutHeight: HeightOutput;
timeoutTimestamp: string;
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}
export class Ics100Client extends Ics100QueryClient implements Ics100Interface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
this.makeSwap = this.makeSwap.bind(this);
this.takeSwap = this.takeSwap.bind(this);
this.cancelSwap = this.cancelSwap.bind(this);
}

makeSwap = async ({
buyToken,
createTimestamp,
desiredTaker,
expirationTimestamp,
makerAddress,
makerReceivingAddress,
sellToken,
sourceChannel,
sourcePort,
timeoutHeight,
timeoutTimestamp
}: {
buyToken: Coin;
createTimestamp: number;
desiredTaker: string;
expirationTimestamp: number;
makerAddress: string;
makerReceivingAddress: string;
sellToken: Coin;
sourceChannel: string;
sourcePort: string;
timeoutHeight: Height;
timeoutTimestamp: number;
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
MakeSwap: {
buy_token: buyToken,
create_timestamp: createTimestamp,
desired_taker: desiredTaker,
expiration_timestamp: expirationTimestamp,
maker_address: makerAddress,
maker_receiving_address: makerReceivingAddress,
sell_token: sellToken,
source_channel: sourceChannel,
source_port: sourcePort,
timeout_height: timeoutHeight,
timeout_timestamp: timeoutTimestamp
}
}, fee, memo, _funds);
};
takeSwap = async ({
createTimestamp,
orderId,
sellToken,
takerAddress,
takerReceivingAddress,
timeoutHeight,
timeoutTimestamp
}: {
createTimestamp: number;
orderId: string;
sellToken: Coin;
takerAddress: string;
takerReceivingAddress: string;
timeoutHeight: Height;
timeoutTimestamp: number;
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
TakeSwap: {
create_timestamp: createTimestamp,
order_id: orderId,
sell_token: sellToken,
taker_address: takerAddress,
taker_receiving_address: takerReceivingAddress,
timeout_height: timeoutHeight,
timeout_timestamp: timeoutTimestamp
}
}, fee, memo, _funds);
};
cancelSwap = async ({
createTimestamp,
makerAddress,
orderId,
timeoutHeight,
timeoutTimestamp
}: {
createTimestamp: string;
makerAddress: string;
orderId: string;
timeoutHeight: HeightOutput;
timeoutTimestamp: string;
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
CancelSwap: {
create_timestamp: createTimestamp,
maker_address: makerAddress,
order_id: orderId,
timeout_height: timeoutHeight,
timeout_timestamp: timeoutTimestamp
}
}, fee, memo, _funds);
};
}
18 changes: 18 additions & 0 deletions codegen/cosmoswasm-codegen/Ics100.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This file was automatically generated by @cosmwasm/ts-codegen@0.35.3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { ContractBase, IContractConstructor, IEmptyClient } from "./contractContextBase";
import { Ics100Client, Ics100QueryClient } from "./Ics100.client";
export class Ics100 extends ContractBase<Ics100Client, Ics100QueryClient, IEmptyClient> {
constructor({
address,
cosmWasmClient,
signingCosmWasmClient
}: IContractConstructor) {
super(address, cosmWasmClient, signingCosmWasmClient, Ics100Client, Ics100QueryClient, undefined);
}

}
Loading

0 comments on commit 014013a

Please sign in to comment.