@interest-protocol/blast-migrators-sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/bluefin-pool.d.ts +57 -0
- package/dist/bluefin-pool.d.ts.map +1 -0
- package/dist/bluefin-pool.js +102 -0
- package/dist/bluefin-pool.js.map +1 -0
- package/dist/cetus-pool.d.ts +44 -0
- package/dist/cetus-pool.d.ts.map +1 -0
- package/dist/cetus-pool.js +57 -0
- package/dist/cetus-pool.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +34 -0
- package/dist/client.js.map +1 -0
- package/dist/events.d.ts +168 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +180 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/reducer.d.ts +139 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +376 -0
- package/dist/reducer.js.map +1 -0
- package/dist/state.d.ts +166 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +187 -0
- package/dist/state.js.map +1 -0
- package/dist/transactions.d.ts +314 -0
- package/dist/transactions.d.ts.map +1 -0
- package/dist/transactions.js +604 -0
- package/dist/transactions.js.map +1 -0
- package/package.json +68 -4
- package/src/bluefin-pool.ts +180 -0
- package/src/cetus-pool.ts +107 -0
- package/src/client.ts +76 -0
- package/src/events.ts +285 -0
- package/src/index.ts +8 -0
- package/src/reducer.ts +562 -0
- package/src/state.ts +316 -0
- package/src/transactions.ts +1068 -0
package/src/events.ts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {
|
|
2
|
+
moveTypeNameBcs,
|
|
3
|
+
suiObjectIdBcs,
|
|
4
|
+
} from "@interest-protocol/blast-core/bcs";
|
|
5
|
+
import type { SuiEventPosition } from "@interest-protocol/blast-core/events";
|
|
6
|
+
import {
|
|
7
|
+
normalizeSuiEventPosition,
|
|
8
|
+
suiEventId,
|
|
9
|
+
} from "@interest-protocol/blast-core/events";
|
|
10
|
+
import {
|
|
11
|
+
requireU64,
|
|
12
|
+
requireU128,
|
|
13
|
+
} from "@interest-protocol/blast-core/integers";
|
|
14
|
+
import type { FeeSplit } from "@interest-protocol/blast-launchpad-sdk/allocation";
|
|
15
|
+
import { feeSplitBcs } from "@interest-protocol/blast-launchpad-sdk/allocation";
|
|
16
|
+
import type { BcsType } from "@mysten/sui/bcs";
|
|
17
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
18
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
19
|
+
import { normalizeSuiAddress, parseStructTag } from "@mysten/sui/utils";
|
|
20
|
+
|
|
21
|
+
type MigratorEventFieldDescriptor =
|
|
22
|
+
| "id"
|
|
23
|
+
| "typeName"
|
|
24
|
+
| "address"
|
|
25
|
+
| "u64"
|
|
26
|
+
| "u128"
|
|
27
|
+
| "u32"
|
|
28
|
+
| "bytes"
|
|
29
|
+
| "u64Vector"
|
|
30
|
+
| "optionAddress"
|
|
31
|
+
| "optionTypeName"
|
|
32
|
+
| "optionU64"
|
|
33
|
+
| "feeSplit";
|
|
34
|
+
|
|
35
|
+
export const migratorEventSpecs = {
|
|
36
|
+
AutoLiquidityAdded: {
|
|
37
|
+
vault_id: "id",
|
|
38
|
+
meme_amount: "u64",
|
|
39
|
+
quote_amount: "u64",
|
|
40
|
+
meme_pending: "u64",
|
|
41
|
+
quote_pending: "u64",
|
|
42
|
+
},
|
|
43
|
+
AutoLpPositionOpened: {
|
|
44
|
+
vault_id: "id",
|
|
45
|
+
position_id: "id",
|
|
46
|
+
},
|
|
47
|
+
BuybackBurned: {
|
|
48
|
+
vault_id: "id",
|
|
49
|
+
quote_spent: "u64",
|
|
50
|
+
meme_burned: "u64",
|
|
51
|
+
quote_pending: "u64",
|
|
52
|
+
},
|
|
53
|
+
CetusPoolReserved: {
|
|
54
|
+
meme: "typeName",
|
|
55
|
+
quote: "typeName",
|
|
56
|
+
pool_creation_cap_id: "id",
|
|
57
|
+
tick_spacing: "u32",
|
|
58
|
+
},
|
|
59
|
+
CreatorFeesClaimed: {
|
|
60
|
+
vault_id: "id",
|
|
61
|
+
meme_amount: "u64",
|
|
62
|
+
quote_amount: "u64",
|
|
63
|
+
},
|
|
64
|
+
FeeSplitChanged: {
|
|
65
|
+
vault_id: "id",
|
|
66
|
+
old_fee_split: "feeSplit",
|
|
67
|
+
new_fee_split: "feeSplit",
|
|
68
|
+
},
|
|
69
|
+
FeesCollected: {
|
|
70
|
+
vault_id: "id",
|
|
71
|
+
gross_meme: "u64",
|
|
72
|
+
gross_quote: "u64",
|
|
73
|
+
protocol_destination: "optionAddress",
|
|
74
|
+
protocol_meme: "u64",
|
|
75
|
+
protocol_quote: "u64",
|
|
76
|
+
creator_meme: "u64",
|
|
77
|
+
creator_quote: "u64",
|
|
78
|
+
auto_lp_meme: "u64",
|
|
79
|
+
auto_lp_quote: "u64",
|
|
80
|
+
rewards_meme: "u64",
|
|
81
|
+
rewards_quote: "u64",
|
|
82
|
+
burn_meme: "u64",
|
|
83
|
+
burn_quote: "u64",
|
|
84
|
+
recipient_meme: "u64Vector",
|
|
85
|
+
recipient_quote: "u64Vector",
|
|
86
|
+
},
|
|
87
|
+
LpFeeDestinationChanged: {
|
|
88
|
+
old_destination: "address",
|
|
89
|
+
new_destination: "address",
|
|
90
|
+
},
|
|
91
|
+
LpFeePolicyChanged: {
|
|
92
|
+
meme: "optionTypeName",
|
|
93
|
+
old_meme_bps: "optionU64",
|
|
94
|
+
old_quote_bps: "optionU64",
|
|
95
|
+
new_meme_bps: "optionU64",
|
|
96
|
+
new_quote_bps: "optionU64",
|
|
97
|
+
},
|
|
98
|
+
ProtocolFeesClaimed: {
|
|
99
|
+
vault_id: "id",
|
|
100
|
+
meme: "typeName",
|
|
101
|
+
quote: "typeName",
|
|
102
|
+
claimant: "address",
|
|
103
|
+
meme_amount: "u64",
|
|
104
|
+
quote_amount: "u64",
|
|
105
|
+
},
|
|
106
|
+
ProtocolLpFeesClaimed: {
|
|
107
|
+
vault_id: "id",
|
|
108
|
+
protocol_destination: "address",
|
|
109
|
+
protocol_meme: "u64",
|
|
110
|
+
protocol_quote: "u64",
|
|
111
|
+
partner_meme: "u64",
|
|
112
|
+
partner_quote: "u64",
|
|
113
|
+
},
|
|
114
|
+
RewardPaid: {
|
|
115
|
+
round_id: "id",
|
|
116
|
+
index: "u64",
|
|
117
|
+
beneficiary: "address",
|
|
118
|
+
meme_amount: "u64",
|
|
119
|
+
quote_amount: "u64",
|
|
120
|
+
meme_remaining: "u64",
|
|
121
|
+
quote_remaining: "u64",
|
|
122
|
+
},
|
|
123
|
+
RoundPublished: {
|
|
124
|
+
vault_id: "id",
|
|
125
|
+
round_id: "id",
|
|
126
|
+
number: "u64",
|
|
127
|
+
start_checkpoint: "u64",
|
|
128
|
+
end_checkpoint: "u64",
|
|
129
|
+
root: "bytes",
|
|
130
|
+
manifest_digest: "bytes",
|
|
131
|
+
leaf_count: "u64",
|
|
132
|
+
meme_amount: "u64",
|
|
133
|
+
quote_amount: "u64",
|
|
134
|
+
meme_unallocated: "u64",
|
|
135
|
+
quote_unallocated: "u64",
|
|
136
|
+
},
|
|
137
|
+
VaultCreated: {
|
|
138
|
+
vault_id: "id",
|
|
139
|
+
pool_id: "id",
|
|
140
|
+
position_id: "id",
|
|
141
|
+
venue: "typeName",
|
|
142
|
+
meme: "typeName",
|
|
143
|
+
quote: "typeName",
|
|
144
|
+
residual_meme: "u64",
|
|
145
|
+
residual_quote: "u64",
|
|
146
|
+
liquidity: "u128",
|
|
147
|
+
fee_split: "feeSplit",
|
|
148
|
+
},
|
|
149
|
+
} as const satisfies Record<
|
|
150
|
+
string,
|
|
151
|
+
Record<string, MigratorEventFieldDescriptor>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
export type MigratorEventKind = keyof typeof migratorEventSpecs;
|
|
155
|
+
|
|
156
|
+
type DescriptorOutputs = {
|
|
157
|
+
id: string;
|
|
158
|
+
typeName: string;
|
|
159
|
+
address: string;
|
|
160
|
+
u64: bigint;
|
|
161
|
+
u128: bigint;
|
|
162
|
+
u32: number;
|
|
163
|
+
bytes: Uint8Array;
|
|
164
|
+
u64Vector: bigint[];
|
|
165
|
+
/** Null when a partnered vault holds Blast's share for the partner claim. */
|
|
166
|
+
optionAddress: string | null;
|
|
167
|
+
optionTypeName: string | null;
|
|
168
|
+
optionU64: bigint | null;
|
|
169
|
+
feeSplit: FeeSplit;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type MigratorEventPayloads = {
|
|
173
|
+
[Kind in MigratorEventKind]: {
|
|
174
|
+
[Field in keyof (typeof migratorEventSpecs)[Kind]]: DescriptorOutputs[Extract<
|
|
175
|
+
(typeof migratorEventSpecs)[Kind][Field],
|
|
176
|
+
MigratorEventFieldDescriptor
|
|
177
|
+
>];
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const U64Bcs = bcs.u64().transform({
|
|
182
|
+
input: (value: bigint) => requireU64("event u64", value),
|
|
183
|
+
output: (value) => BigInt(value),
|
|
184
|
+
});
|
|
185
|
+
const U128Bcs = bcs.u128().transform({
|
|
186
|
+
input: (value: bigint) => requireU128("event u128", value),
|
|
187
|
+
output: (value) => BigInt(value),
|
|
188
|
+
});
|
|
189
|
+
const BytesBcs = bcs.vector(bcs.u8()).transform({
|
|
190
|
+
input: (value: Uint8Array) => Array.from(value),
|
|
191
|
+
output: (value) => Uint8Array.from(value),
|
|
192
|
+
});
|
|
193
|
+
const AddressBcs = bcs.Address.transform({
|
|
194
|
+
input: (value: string) => normalizeSuiAddress(value),
|
|
195
|
+
output: (value) => normalizeSuiAddress(value),
|
|
196
|
+
});
|
|
197
|
+
const MIGRATOR_EVENT_FIELD_BCS: Record<
|
|
198
|
+
MigratorEventFieldDescriptor,
|
|
199
|
+
BcsType<unknown, unknown>
|
|
200
|
+
> = {
|
|
201
|
+
id: suiObjectIdBcs as BcsType<unknown, unknown>,
|
|
202
|
+
typeName: moveTypeNameBcs as BcsType<unknown, unknown>,
|
|
203
|
+
address: AddressBcs as BcsType<unknown, unknown>,
|
|
204
|
+
u64: U64Bcs as BcsType<unknown, unknown>,
|
|
205
|
+
u128: U128Bcs as BcsType<unknown, unknown>,
|
|
206
|
+
u32: bcs.u32() as BcsType<unknown, unknown>,
|
|
207
|
+
bytes: BytesBcs as BcsType<unknown, unknown>,
|
|
208
|
+
u64Vector: bcs.vector(U64Bcs) as BcsType<unknown, unknown>,
|
|
209
|
+
optionAddress: bcs.option(AddressBcs) as BcsType<unknown, unknown>,
|
|
210
|
+
optionTypeName: bcs.option(moveTypeNameBcs) as BcsType<unknown, unknown>,
|
|
211
|
+
optionU64: bcs.option(U64Bcs) as BcsType<unknown, unknown>,
|
|
212
|
+
feeSplit: feeSplitBcs as BcsType<unknown, unknown>,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
type MigratorEventBcsMap = {
|
|
216
|
+
[Kind in MigratorEventKind]: BcsType<
|
|
217
|
+
MigratorEventPayloads[Kind],
|
|
218
|
+
MigratorEventPayloads[Kind]
|
|
219
|
+
>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const migratorEventBcs = Object.fromEntries(
|
|
223
|
+
Object.entries(migratorEventSpecs).map(([name, spec]) => [
|
|
224
|
+
name,
|
|
225
|
+
bcs.struct(
|
|
226
|
+
name,
|
|
227
|
+
Object.fromEntries(
|
|
228
|
+
Object.entries(spec).map(([field, descriptor]) => [
|
|
229
|
+
field,
|
|
230
|
+
MIGRATOR_EVENT_FIELD_BCS[descriptor],
|
|
231
|
+
]),
|
|
232
|
+
),
|
|
233
|
+
),
|
|
234
|
+
]),
|
|
235
|
+
) as unknown as MigratorEventBcsMap;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Migrator events are authenticated by their type, which names the original
|
|
239
|
+
* package's `blast_events` module; Sui records only the transaction's called
|
|
240
|
+
* package and module on each event.
|
|
241
|
+
*/
|
|
242
|
+
export type MigratorEventPackageIdentity = {
|
|
243
|
+
originalPackageId: string;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
type DecodedMigratorEventBase = {
|
|
247
|
+
source: "migrators";
|
|
248
|
+
sender: string;
|
|
249
|
+
position: SuiEventPosition;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export type DecodedMigratorEvent = {
|
|
253
|
+
[Kind in MigratorEventKind]: DecodedMigratorEventBase & {
|
|
254
|
+
kind: Kind;
|
|
255
|
+
payload: MigratorEventPayloads[Kind];
|
|
256
|
+
};
|
|
257
|
+
}[MigratorEventKind];
|
|
258
|
+
|
|
259
|
+
export function decodeMigratorEvent(
|
|
260
|
+
event: SuiClientTypes.EventEntry,
|
|
261
|
+
packages: MigratorEventPackageIdentity,
|
|
262
|
+
): DecodedMigratorEvent {
|
|
263
|
+
const originalPackageId = normalizeSuiAddress(packages.originalPackageId);
|
|
264
|
+
const tag = parseStructTag(event.eventType);
|
|
265
|
+
if (
|
|
266
|
+
tag.address !== originalPackageId ||
|
|
267
|
+
tag.module !== "blast_events" ||
|
|
268
|
+
tag.typeParams.length !== 0 ||
|
|
269
|
+
!Object.hasOwn(migratorEventSpecs, tag.name)
|
|
270
|
+
) {
|
|
271
|
+
throw new TypeError("migrator event has an unexpected event package");
|
|
272
|
+
}
|
|
273
|
+
const kind = tag.name as MigratorEventKind;
|
|
274
|
+
return {
|
|
275
|
+
source: "migrators",
|
|
276
|
+
kind,
|
|
277
|
+
payload: migratorEventBcs[kind].parse(event.bcs),
|
|
278
|
+
sender: normalizeSuiAddress(event.sender),
|
|
279
|
+
position: normalizeSuiEventPosition(event),
|
|
280
|
+
} as DecodedMigratorEvent;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function migratorEventId(event: DecodedMigratorEvent): string {
|
|
284
|
+
return suiEventId(event.position);
|
|
285
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "@interest-protocol/blast-core/migration-math";
|
|
2
|
+
export * from "./bluefin-pool.ts";
|
|
3
|
+
export * from "./cetus-pool.ts";
|
|
4
|
+
export * from "./client.ts";
|
|
5
|
+
export * from "./events.ts";
|
|
6
|
+
export * from "./reducer.ts";
|
|
7
|
+
export * from "./state.ts";
|
|
8
|
+
export * from "./transactions.ts";
|