|
1 | 1 | import { getAppMetadata } from "@walletconnect/utils";
|
| 2 | +import { |
| 3 | + PartialTezosDelegationOperation, |
| 4 | + PartialTezosIncreasePaidStorageOperation, |
| 5 | + PartialTezosOriginationOperation as PartialTezosOriginationOperationOriginal, |
| 6 | + PartialTezosTransactionOperation, |
| 7 | + TezosOperationType } |
| 8 | + from "@airgap/beacon-types"; |
| 9 | +import { ScriptedContracts } from "@taquito/rpc"; |
2 | 10 |
|
3 | 11 | if (!process.env.NEXT_PUBLIC_PROJECT_ID)
|
4 | 12 | throw new Error("`NEXT_PUBLIC_PROJECT_ID` env variable is missing.");
|
@@ -244,11 +252,125 @@ export enum DEFAULT_TRON_EVENTS {}
|
244 | 252 | /**
|
245 | 253 | * TEZOS
|
246 | 254 | */
|
| 255 | +// Can be removed when the fix for Origination is released: |
| 256 | +// https://github.com/airgap-it/beacon-sdk/pull/806 |
| 257 | +interface PartialTezosOriginationOperation |
| 258 | + extends Omit<PartialTezosOriginationOperationOriginal, "script"> { |
| 259 | + script: ScriptedContracts; |
| 260 | +} |
| 261 | + |
247 | 262 | export enum DEFAULT_TEZOS_METHODS {
|
248 | 263 | TEZOS_GET_ACCOUNTS = "tezos_getAccounts",
|
249 | 264 | TEZOS_SEND = "tezos_send",
|
250 | 265 | TEZOS_SIGN = "tezos_sign",
|
251 | 266 | }
|
| 267 | + |
| 268 | +export enum TEZOS_SAMPLE_KINDS { |
| 269 | + GET_ACCOUNTS = "tezos_getAccounts", |
| 270 | + SEND = "tezos_send", |
| 271 | + SEND_TRANSACTION = "tezos_send:transaction", |
| 272 | + SEND_ORGINATION = "tezos_send:origination", |
| 273 | + SEND_CONTRACT_CALL = "tezos_send:contract_call", |
| 274 | + SEND_DELEGATION = "tezos_send:delegation", |
| 275 | + SEND_UNDELEGATION = "tezos_send:undelegation", |
| 276 | + SEND_STAKE = "tezos_send:stake", |
| 277 | + SEND_UNSTAKE = "tezos_send:unstake", |
| 278 | + SEND_FINALIZE = "tezos_send:finalize", |
| 279 | + SEND_INCREASE_PAID_STORAGE = "tezos_send:increase_paid_storage", |
| 280 | + SIGN = "tezos_sign", |
| 281 | +} |
| 282 | + |
| 283 | +const tezosTransactionOperation: PartialTezosTransactionOperation = { |
| 284 | + kind: TezosOperationType.TRANSACTION, |
| 285 | + destination: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve", // Tezos Foundation Ghost Baker |
| 286 | + amount: "100000" |
| 287 | +}; |
| 288 | + |
| 289 | +const tezosOriginationOperation: PartialTezosOriginationOperation = { |
| 290 | + kind: TezosOperationType.ORIGINATION, |
| 291 | + balance: '1', |
| 292 | + script: { // This contract adds the parameter to the storage value |
| 293 | + code: [ |
| 294 | + { prim: "parameter", args: [{ prim: "int" }] }, |
| 295 | + { prim: "storage", args: [{ prim: "int" }] }, |
| 296 | + { prim: "code", |
| 297 | + args: [[ |
| 298 | + { prim: "DUP" }, // Duplicate the parameter (parameter is pushed onto the stack) |
| 299 | + { prim: "CAR" }, // Access the parameter from the stack (parameter is on top) |
| 300 | + { prim: "DIP", args: [[{ prim: "CDR" }]] }, // Access the storage value (storage is on the stack) |
| 301 | + { prim: "ADD" }, // Add the parameter to the storage value |
| 302 | + { prim: "NIL", args: [{ prim: "operation" }] }, // Create an empty list of operations |
| 303 | + { prim: "PAIR" } // Pair the updated storage with the empty list of operations |
| 304 | + ]] |
| 305 | + } |
| 306 | + ], |
| 307 | + storage: { int: "10" } |
| 308 | + }, |
| 309 | +}; |
| 310 | + |
| 311 | +const tezosContractCallOperation: PartialTezosTransactionOperation = { |
| 312 | + kind: TezosOperationType.TRANSACTION, |
| 313 | + destination: "[contract address]", |
| 314 | + amount: "0", |
| 315 | + parameters: { entrypoint: "default", value: { int: "20" } } // Add 20 to the current storage value |
| 316 | +}; |
| 317 | + |
| 318 | +const tezosDelegationOperation: PartialTezosDelegationOperation = { |
| 319 | + kind: TezosOperationType.DELEGATION, |
| 320 | + delegate: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve" // Tezos Foundation Ghost Baker. Cannot delegate to ourself as that would block undelegation |
| 321 | +}; |
| 322 | + |
| 323 | +const tezosUndelegationOperation: PartialTezosDelegationOperation = { |
| 324 | + kind: TezosOperationType.DELEGATION |
| 325 | +}; |
| 326 | + |
| 327 | +const tezosStakeOperation: PartialTezosTransactionOperation = { |
| 328 | + kind: TezosOperationType.TRANSACTION, |
| 329 | + destination:"[own adress]", |
| 330 | + amount: "1000000", |
| 331 | + parameters: { |
| 332 | + entrypoint: "stake", |
| 333 | + value: { prim: "Unit" }, |
| 334 | + }, |
| 335 | +}; |
| 336 | + |
| 337 | +const tezosUnstakeOperation: PartialTezosTransactionOperation = { |
| 338 | + kind: TezosOperationType.TRANSACTION, |
| 339 | + destination:"[own adress]", |
| 340 | + amount: "1000000", |
| 341 | + parameters: { |
| 342 | + entrypoint: "unstake", |
| 343 | + value: { prim: "Unit" }, |
| 344 | + }, |
| 345 | +}; |
| 346 | + |
| 347 | +const tezosFinalizeOperation: PartialTezosTransactionOperation = { |
| 348 | + kind: TezosOperationType.TRANSACTION, |
| 349 | + destination:"[own adress]", |
| 350 | + amount: "0", |
| 351 | + parameters: { |
| 352 | + entrypoint: "finalize_unstake", |
| 353 | + value: { prim: "Unit" }, |
| 354 | + }, |
| 355 | +}; |
| 356 | + |
| 357 | +const TezosIncreasePaidStorageOperation: PartialTezosIncreasePaidStorageOperation = { |
| 358 | + kind: TezosOperationType.INCREASE_PAID_STORAGE, |
| 359 | + amount: "10", |
| 360 | + destination: "[contract address]" |
| 361 | +}; |
| 362 | + |
| 363 | +export const TEZOS_SAMPLES = { |
| 364 | + "tezos_send:transaction": tezosTransactionOperation, |
| 365 | + "tezos_send:origination": tezosOriginationOperation, |
| 366 | + "tezos_send:contract_call": tezosContractCallOperation, |
| 367 | + "tezos_send:delegation": tezosDelegationOperation, |
| 368 | + "tezos_send:undelegation": tezosUndelegationOperation, |
| 369 | + "tezos_send:stake": tezosStakeOperation, |
| 370 | + "tezos_send:unstake": tezosUnstakeOperation, |
| 371 | + "tezos_send:finalize": tezosFinalizeOperation, |
| 372 | + "tezos_send:increase_paid_storage": TezosIncreasePaidStorageOperation, |
| 373 | +}; |
252 | 374 |
|
253 | 375 | export enum DEFAULT_TEZOS_EVENTS {}
|
254 | 376 |
|
|
0 commit comments