rango-sdk-basic 0.0.12 → 0.0.13
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 +0 -116
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
[](https://badge.fury.io/js/rango-sdk-basic)
|
|
4
4
|
[](https://github.com/rango-exchange/rango-sdk/blob/master/LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
This is the first phase of Rango SDK which only wraps Rest API calls. In the next phase, we will handle connecting to the wallet providers.
|
|
8
7
|
|
|
9
8
|
> **WARNING:** The Rango SDK is still beta. Please use it on your own risk.
|
|
10
9
|
|
|
11
10
|
> **WARNING:** The Rango SDK has not stabilized yet, and we might make some breaking changes.
|
|
12
11
|
|
|
13
|
-
|
|
14
12
|
## 2. Installation
|
|
15
13
|
|
|
16
14
|
```shell
|
|
@@ -23,117 +21,3 @@ Please checkout the examples' folder for sample usage of the SDK. We will add mo
|
|
|
23
21
|
|
|
24
22
|
- [Documents](https://docs.rango.exchange/integration/overview)
|
|
25
23
|
- [Examples](https://github.com/rango-exchange/rango-sdk/tree/master/examples/)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## 4. Message Passing API
|
|
29
|
-
|
|
30
|
-
When transferring tokens using Rango cross-chain API, you could pass a random message from the source chain to the destination and call your contract on the destination. In order to do so, you need to pass your contracts on source & destination chains plus an arbitrary hex message like this:
|
|
31
|
-
|
|
32
|
-
### 4.1. SDK usage
|
|
33
|
-
|
|
34
|
-
You should specify `sourceContract`, `destinationContract` and `imMessage` arguments in both `quote` and `swap` methods if you want to pass a message from the source contract to the destination.
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
const quoteResponse = await rangoClient.quote({
|
|
38
|
-
from: {
|
|
39
|
-
"blockchain": "FANTOM",
|
|
40
|
-
"symbol": "FTM",
|
|
41
|
-
"address": null
|
|
42
|
-
},
|
|
43
|
-
to: {
|
|
44
|
-
"blockchain": "BSC",
|
|
45
|
-
"symbol": "BNB",
|
|
46
|
-
"address": null
|
|
47
|
-
},
|
|
48
|
-
amount: "100000000000000000000",
|
|
49
|
-
messagingProtocols: ['cbridge'],
|
|
50
|
-
sourceContract: "<source contract address>",
|
|
51
|
-
destinationContract: "<destination contract address>",
|
|
52
|
-
imMessage: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000007E8A8b130272430008eCa062419ACD8B423d339D"
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
As you can see in the code above, you could also limit `messagingProtocols` used to a custom list like `['cbridge']`. (Please note that as message is relayed alongside with token in a single transaction, if you limit messaging protocols to celer bridge, we use same bridge (cbridge) for transerring tokens.
|
|
58
|
-
Here is list of all available options for `messagingProtocols`: `cbridge`, (soon: `anyswap`, `axelar`, `layer0`)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
const swapResponse = await rangoClient.swap({
|
|
63
|
-
from: {
|
|
64
|
-
"blockchain": "FANTOM",
|
|
65
|
-
"symbol": "FTM",
|
|
66
|
-
"address": null
|
|
67
|
-
},
|
|
68
|
-
to: {
|
|
69
|
-
"blockchain": "BSC",
|
|
70
|
-
"symbol": "BNB",
|
|
71
|
-
"address": null
|
|
72
|
-
},
|
|
73
|
-
amount: "100000000000000000000",
|
|
74
|
-
fromAddress: fromAddress,
|
|
75
|
-
toAddress: fromAddress,
|
|
76
|
-
disableEstimate: false,
|
|
77
|
-
referrerAddress: null,
|
|
78
|
-
referrerFee: null,
|
|
79
|
-
slippage: '1.0',
|
|
80
|
-
messagingProtocols: ['cbridge'],
|
|
81
|
-
sourceContract: "<source contract address>",
|
|
82
|
-
destinationContract: "<destination contract address>",
|
|
83
|
-
imMessage: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000007E8A8b130272430008eCa062419ACD8B423d339D"
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
if (!!swapResponse && !swapResponse.error && swapResponse.resultType === "OK" && swapResponse.tx?.type === TransactionType.EVM) {
|
|
87
|
-
const evmTx = swapResponse.tx as EvmTransaction
|
|
88
|
-
const value = evmTx.value
|
|
89
|
-
const txData = evmTx.value
|
|
90
|
-
console.log({value, txData})
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
You need to use `value` and `txData` if you want to call your own contract. (not calling Rango directly from the client side)
|
|
94
|
-
|
|
95
|
-
### 4.2. dApp Contracts
|
|
96
|
-
|
|
97
|
-
Both dApp contracts on the source and destination chains should implemenet `IRangoMessageReceiver` interface. Rango will call `handleRangoMessage` function in case of `SUCCESS`, `REFUND_IN_SOURCE` or `REFUND_IN_DESTINATION`.
|
|
98
|
-
```solidity
|
|
99
|
-
interface IRangoMessageReceiver {
|
|
100
|
-
enum ProcessStatus { SUCCESS, REFUND_IN_SOURCE, REFUND_IN_DESTINATION }
|
|
101
|
-
|
|
102
|
-
function handleRangoMessage(
|
|
103
|
-
address _token,
|
|
104
|
-
uint _amount,
|
|
105
|
-
ProcessStatus _status,
|
|
106
|
-
bytes memory _message
|
|
107
|
-
) external;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
And here is a sample dapp contract for the demo purpose. (The demo is very simple and you should consider adding security considerations yourself)
|
|
112
|
-
|
|
113
|
-
https://gist.github.com/RanGojo/1066ed2bf1556be7c2def69dbe2b3cb9
|
|
114
|
-
|
|
115
|
-
You need to deploy this contract on every chains needed and **ask us to white list them in Rango Contract**.
|
|
116
|
-
|
|
117
|
-
Here are some sample transaction for this contracts in action for swapping Fantom.FTM to BSC.BNB and relaying custom message:
|
|
118
|
-
|
|
119
|
-
- Inbound transaction:
|
|
120
|
-
https://ftmscan.com/tx/0x59a526e4376dc5b083b7876d47699b6c110fcba319c78553f3b8342674a68b3d
|
|
121
|
-
|
|
122
|
-
- Outbound transaction:
|
|
123
|
-
https://bscscan.com/tx/0x8e91d7c3baf914cad8190bba4d608149d093d059ef769f9ca7a01a3d90a9c5e9
|
|
124
|
-
|
|
125
|
-
Here is how dApp [call Rango](https://gist.github.com/RanGojo/1066ed2bf1556be7c2def69dbe2b3cb9#file-crosschainsampleapp-sol-L36) in the source chain:
|
|
126
|
-
|
|
127
|
-

|
|
128
|
-
|
|
129
|
-
And here is how dApp could [handle Rango message](https://gist.github.com/RanGojo/1066ed2bf1556be7c2def69dbe2b3cb9#file-crosschainsampleapp-sol-L45):
|
|
130
|
-
|
|
131
|
-

|
|
132
|
-
|
|
133
|
-
We emit a sample event in destination for debug and here you could check it:
|
|
134
|
-
|
|
135
|
-
[emit NFTPurchaseStatus(m.assetId, m.buyer, PurchaseType.BOUGHT);](https://gist.github.com/RanGojo/1066ed2bf1556be7c2def69dbe2b3cb9#file-crosschainsampleapp-sol-L64)
|
|
136
|
-
|
|
137
|
-

|
|
138
|
-
|
|
139
|
-
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,cAAc,SAAS,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.RangoClient = void 0;
|
|
18
18
|
var services_1 = require("./services");
|
|
19
19
|
Object.defineProperty(exports, "RangoClient", { enumerable: true, get: function () { return services_1.RangoClient; } });
|
|
20
|
-
__exportStar(require("./types
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAwC;AAA/B,uGAAA,WAAW,OAAA;AACpB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAwC;AAA/B,uGAAA,WAAW,OAAA;AACpB,0CAAuB"}
|