Skip to content

Commit 5631f3d

Browse files
Merge pull request #80 from smartcontractkit/link-token-jetton-go-bindings
[NONEVM-2181] Jetton Go bindings
2 parents 1507e9b + c7ff655 commit 5631f3d

File tree

38 files changed

+1692
-101
lines changed

38 files changed

+1692
-101
lines changed

contracts/contracts/examples/jetton/onramp_mock.tolk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ fun OnrampMock.handleJettonTransferNotification(
4848

4949
// Handle the jetton transfer
5050
if (msg.jettonAmount < FEE) {
51-
emit(JETTON_TOPIC, InsufficientFee { queryId: msg.queryId, sender: sender });
51+
emit(JETTON_TOPIC, InsufficientFee { queryId: msg.queryId, sender: msg.transferInitiator });
5252
} else {
5353
emit(
5454
JETTON_TOPIC,
5555
AcceptedRequest {
5656
queryId: msg.queryId,
57-
sender: sender,
57+
sender: msg.transferInitiator,
5858
payload: forwardPayloadCell!,
5959
}
6060
);

contracts/contracts/examples/jetton/sender.tolk

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "@stdlib/common.tolk"
22
import "../../lib/jetton/jetton_client.tolk"
3+
import "../../lib/jetton/messages.tolk"
34

45
// JettonSender contract in Tolk
56
// Allows sending jettons to other addresses
@@ -8,14 +9,16 @@ struct JettonSender {
89
}
910

1011
// Send jettons fast message (basic transfer)
11-
struct (0x6984f9bb) SendJettonsFast {
12+
// 0x4C169F42 == crc32('SendJettonsFast')
13+
struct (0x4C169F42) SendJettonsFast {
1214
queryId: uint64
1315
amount: coins
1416
destination: address
1517
}
1618

1719
// Send jettons extended message (with additional parameters)
18-
struct (0xe815f1d0) SendJettonsExtended {
20+
// 0x7FDA8110 == crc32('SendJettonsExtended')
21+
struct (0x7FDA8110) SendJettonsExtended {
1922
queryId: uint64
2023
amount: coins
2124
destination: address
@@ -24,7 +27,7 @@ struct (0xe815f1d0) SendJettonsExtended {
2427
forwardPayload: cell
2528
}
2629

27-
type IncomingMessage = SendJettonsFast | SendJettonsExtended
30+
type IncomingMessage = SendJettonsFast | SendJettonsExtended | ReturnExcessesBack
2831

2932
fun JettonSender.load(): JettonSender {
3033
return JettonSender.fromCell(contract.getData());
@@ -77,5 +80,9 @@ fun onInternalMessage(in: InMessage) {
7780
SendJettonsExtended => {
7881
this.sendJettonsExtended(msg);
7982
}
83+
ReturnExcessesBack => {
84+
// Accept excess ton
85+
return;
86+
}
8087
}
8188
}

contracts/contracts/examples/jetton/simple_receiver.tolk

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "@stdlib/common.tolk"
22
import "../../lib/jetton/jetton_client.tolk"
33
import "../../lib/jetton/messages.tolk"
4+
import "../../lib/utils"
45

56
// SimpleJettonReceiver contract in Tolk
67
// Simple receiver that just tracks amounts and payloads
@@ -23,23 +24,22 @@ fun SimpleJettonReceiver.store(self) {
2324
type IncomingMessage = TransferNotificationForRecipient
2425

2526
fun onInternalMessage(in: InMessage) {
26-
if (in.body.isEmpty()) {
27-
// ignore all empty messages
28-
return;
29-
}
30-
31-
val msg = IncomingMessage.fromSlice(in.body);
27+
val msg = lazy IncomingMessage.fromSlice(in.body);
3228

3329
var this = SimpleJettonReceiver.load();
3430

3531
match (msg) {
3632
TransferNotificationForRecipient => {
3733
this.handleJettonTransferNotification(msg, in.senderAddress);
3834
}
35+
else => {
36+
// ignore empty messages, "wrong opcode" for others
37+
assert (in.body.isEmpty()) throw 0xFFFF;
38+
}
3939
}
4040
}
4141

42-
fun JettonReceiver.handleJettonTransferNotification(
42+
fun SimpleJettonReceiver.handleJettonTransferNotification(
4343
mutate self,
4444
msg: TransferNotificationForRecipient,
4545
sender: address,
@@ -50,6 +50,7 @@ fun JettonReceiver.handleJettonTransferNotification(
5050
// Handle the jetton transfer - simple implementation just updates trackers
5151
self.amountChecker += msg.jettonAmount;
5252
self.payloadChecker = loadMaybeForwardPayloadAsCell(msg.forwardPayload);
53+
self.store();
5354
}
5455

5556
get fun amountChecker(): coins {

contracts/wrappers/examples/jetton/JettonSender.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SendMode,
1010
} from '@ton/core'
1111
import { JettonClientConfig, jettonClientConfigToCell, JettonOpcodes } from './types'
12+
import { crc32 } from 'zlib'
1213

1314
export type JettonSenderConfig = {
1415
jettonClient: JettonClientConfig
@@ -19,8 +20,8 @@ export function jettonSenderConfigToCell(config: JettonSenderConfig): Cell {
1920
}
2021

2122
export const SenderOpcodes = {
22-
SEND_JETTONS_FAST: JettonOpcodes.SEND_JETTONS_FAST,
23-
SEND_JETTONS_EXTENDED: JettonOpcodes.SEND_JETTONS_EXTENDED,
23+
SEND_JETTONS_FAST: crc32('SendJettonsFast'),
24+
SEND_JETTONS_EXTENDED: crc32('SendJettonsExtended'),
2425
}
2526

2627
export type SendJettonsFastMessage = {

contracts/wrappers/examples/jetton/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export const JettonOpcodes = {
3030
CHANGE_METADATA_URL: 0xcb862902,
3131
UPGRADE: 0x2508d66a,
3232
// TOP_UP: 0x8,
33-
34-
// Custom contract opcodes
35-
SEND_JETTONS_FAST: 0x6984f9bb,
36-
SEND_JETTONS_EXTENDED: 0xe815f1d0,
3733
}
3834

3935
export const ErrorCodes = {

docs/contracts/overview/jetton/jetton.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Jettons - TON Tokens
22

3+
Jettons is the TON standard for Fungible Tokens.
4+
35
## Basic workflow
46

57
![Flow diagram](./simple-transfer.png)
@@ -34,9 +36,33 @@ sequenceDiagram
3436
end
3537
```
3638

37-
## Onramp Mock
39+
## Usage
40+
41+
The [func implementation of Jettons](https://github.com/ton-blockchain/jetton-contract/tree/3d24b419f2ce49c09abf6b8703998187fe358ec9/contracts) is made available throguh nix.
42+
The minter and wallet contracts can be built by running
43+
44+
```bash
45+
nix build .#contracts-jetton-func
46+
```
47+
48+
appending `--print-out-paths` at the end displays the directory where they can be located.
3849

39-
Implements a mock of an Onramp implementation that receives the instruction as the forwardPayload and operates if it covers the fee.
50+
```bash
51+
$ nix build .#contracts-jetton-func --print-out-paths
52+
/nix/store/s3rsxlqskan6ripf2sii9njrzv1mhbxz-contracts-jetton-func-1.2.0
53+
```
54+
55+
Furthermore, the `#contracts` nix shell compiles and exposes the build directory through the environment variable `PATH_CONTRACTS_JETTON`.
56+
57+
```bash
58+
$ nix develop .#contracts -c ls -lca $PATH_CONTRACTS_JETTON
59+
Jetton contracts located here: /nix/store/s3rsxlqskan6ripf2sii9njrzv1mhbxz-contracts-jetton-func-1.2.0/lib/node_modules/jetton/build/
60+
total 16
61+
dr-xr-xr-x 6 root wheel 192 Jul 8 14:47 .
62+
dr-xr-xr-x 15 root wheel 480 Jul 8 14:47 ..
63+
-r--r--r-- 1 root wheel 2386 Jul 8 14:47 JettonMinter.compiled.json
64+
-r--r--r-- 1 root wheel 1834 Jul 8 14:47 JettonWallet.compiled.json
65+
```
4066

4167
## Docs
4268

flake.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
# Output a set of dev environments (shells)
3939
devShells =
4040
{
41-
default = pkgs.callPackage ./shell.nix {inherit pkgs;};
41+
default = pkgs.callPackage ./shell.nix {
42+
inherit pkgs;
43+
chainlink-ton = chainlink-ton;
44+
jetton-contracts = contracts.packages.contracts-jetton-func;
45+
};
4246
# Development shell for dependency analyzer
4347
dependency-analyzer = pkgs.callPackage ./tools/dependency_analyzer/shell.nix {inherit pkgs;};
4448
}

integration-tests/default.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
pkgs,
33
rev,
44
}: let
5-
# Any integration-test specific configuration
5+
# Import contracts to get jetton-contracts
6+
contracts = pkgs.callPackage ../contracts {inherit pkgs rev;};
7+
# Import chainlink-ton package
8+
chainlink-ton = pkgs.callPackage ../cmd/chainlink-ton {inherit pkgs rev;};
69
in {
710
devShells = {
8-
ccip-e2e = pkgs.callPackage ./shell-ccip-e2e.nix {inherit pkgs;};
11+
ccip-e2e = pkgs.callPackage ./shell-ccip-e2e.nix {
12+
inherit pkgs;
13+
chainlink-ton = chainlink-ton;
14+
jetton-contracts = contracts.packages.contracts-jetton-func;
15+
};
916
# Note: other integration test environments could go here
1017
};
1118

0 commit comments

Comments
 (0)