-
Notifications
You must be signed in to change notification settings - Fork 11
/
messages.ts
147 lines (134 loc) · 3.47 KB
/
messages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx"
import { Height } from "cosmjs-types/ibc/core/client/v1/client"
import { OsmosisRoute, SignerMessage } from "@/types"
import { Coin } from "@cosmjs/proto-signing"
import { MsgClaim as MerkleDropMsgClaim } from "./codec/bitsong/merkledrop/v1beta1/tx"
import { osmosis } from "osmojs"
import { Long } from "@osmonauts/helpers"
const { joinPool, exitPool, joinSwapExternAmountIn, swapExactAmountIn } =
osmosis.gamm.v1beta1.MessageComposer.withTypeUrl
const { beginUnlocking, lockTokens } =
osmosis.lockup.MessageComposer.withTypeUrl
export type messageTimestamp = string | number | Long.Long | undefined
export const SendIbcTokens = (
senderAddress: string,
recipientAddress: string,
transferAmount: Coin,
sourcePort: string,
sourceChannel: string,
timeoutHeight?: Height,
timeoutTimestamp?: number
): SignerMessage<MsgTransfer> => {
const timeoutTimestampNanoseconds: messageTimestamp = timeoutTimestamp
? Long.fromNumber(timeoutTimestamp).multiply(1_000_000_000)
: undefined
return {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
value: MsgTransfer.fromPartial({
sourcePort: sourcePort,
sourceChannel: sourceChannel,
sender: senderAddress,
receiver: recipientAddress,
token: transferAmount,
timeoutTimestamp: timeoutTimestampNanoseconds,
}),
}
}
export const LockTokens = (
senderAddress: string, // Owner
duration: number, // Duration's unit is expected to be the second.
coins: Coin[]
): SignerMessage<any> => {
const msgDuration = duration * 1_000_000_000
return lockTokens({
owner: senderAddress,
duration: {
seconds: Long.fromNumber(Math.floor(msgDuration / 1_000_000_000)),
nanos: msgDuration % 1_000_000_000,
},
coins,
})
}
export const BeginUnlocking = (
senderAddress: string, // Owner
id: string
): SignerMessage<any> => {
return beginUnlocking({
owner: senderAddress,
ID: Long.fromString(id),
coins: [],
})
}
export const JoinPool = (
senderAddress: string, // Owner
poolId: string,
shareOutAmount: string,
tokenInMaxs: Coin[]
): SignerMessage<any> => {
return joinPool({
sender: senderAddress,
poolId: Long.fromString(poolId),
shareOutAmount,
tokenInMaxs,
})
}
export const JoinSwapExternAmountIn = (
senderAddress: string, // Owner
poolId: string,
tokenIn: Coin,
shareOutMinAmount: string
): SignerMessage<any> => {
return joinSwapExternAmountIn({
sender: senderAddress,
poolId: Long.fromString(poolId),
tokenIn,
shareOutMinAmount,
})
}
export const ExitPool = (
senderAddress: string, // Owner
poolId: string,
shareInAmount: string,
tokenOutMins: Coin[]
): SignerMessage<any> => {
return exitPool({
sender: senderAddress,
poolId: Long.fromString(poolId),
shareInAmount,
tokenOutMins,
})
}
export const SwapExactAmountIn = (
senderAddress: string, // Owner
routes: OsmosisRoute[],
tokenIn: Coin,
tokenOutMinAmount: string
): SignerMessage<any> => {
return swapExactAmountIn({
sender: senderAddress,
routes: routes.map((route) => ({
...route,
poolId: Long.fromString(route.poolId),
})),
tokenIn,
tokenOutMinAmount,
})
}
export const MerkledropClaim = (
senderAddress: string, // Owner
merkledropId: number,
index: number,
amount: string,
proofs: string[]
): SignerMessage<any> => {
return {
typeUrl: "/bitsong.merkledrop.v1beta1.MsgClaim",
value: MerkleDropMsgClaim.fromJSON({
sender: senderAddress,
merkledropId: merkledropId.toString(),
index: index.toString(),
amount,
proofs,
}),
}
}