Skip to content

Commit e034c61

Browse files
authored
[SOF-1481] Add matic support (#55)
* wip * wip * jpp * wip * matic unstake * matic withdraw * matic restake rewards * nit * better commentS
1 parent c9a6fe6 commit e034c61

File tree

19 files changed

+359
-72
lines changed

19 files changed

+359
-72
lines changed

examples/matic.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Kiln } from "../src/kiln";
2+
3+
const fs = require('fs');
4+
5+
const apiSecret = fs.readFileSync(__dirname + '/fireblocks_secret.key', 'utf8');
6+
7+
const f = async () => {
8+
const k = new Kiln({
9+
testnet: true,
10+
apiToken: 'kiln_Q3VFTHU0WW85Q2Z1dXJqMUFYSmtFYnFIZElpM3dwbFE6WWhxNGlobEJEbzktMm1zUm4tdUJhUDdPZml0NTdxdTIxVEVYczZlaDVQVTlEVk9TM1B5N0J6UV9xSFJVRzJKTg',
11+
integrations: [
12+
{
13+
name: 'vault1',
14+
provider: 'fireblocks',
15+
fireblocksApiKey: '53aee35e-04b7-9314-8f28-135a66c8af2c',
16+
fireblocksSecretKey: apiSecret,
17+
vaultAccountId: '7'
18+
}
19+
],
20+
});
21+
22+
try {
23+
const amountWei = k.matic.maticToWei('0.4');
24+
console.log('crafting...');
25+
// const txApprove = await k.matic.craftApproveTx(
26+
// '0x296a8F811Af114f43db2Bdb2cFB595Cc1Dc4176D',
27+
// '0x00200eA4Ee292E253E6Ca07dBA5EdC07c8Aa37A3',
28+
// amountWei,
29+
// );
30+
// const txStake = await k.matic.craftBuyVoucherTx(
31+
// 'd3f1b917-72b1-4982-a4dd-93fce579a708',
32+
// '0x296a8F811Af114f43db2Bdb2cFB595Cc1Dc4176D',
33+
// amountWei,
34+
// );
35+
// const txStake = await k.matic.craftSellVoucherTx(
36+
// '0x9ce658155a6f05fe4aef83b7fa8f431d5e8ccb55',
37+
// amountWei,
38+
// );
39+
// const txStake = await k.matic.craftUnstakeClaimTokensTx(
40+
// '0x9ce658155a6f05fe4aef83b7fa8f431d5e8ccb55',
41+
// );
42+
// const txStake = await k.matic.craftWithdrawRewardsTx(
43+
// '0x9ce658155a6f05fe4aef83b7fa8f431d5e8ccb55',
44+
// );
45+
const txStake = await k.matic.craftRestakeRewardsTx(
46+
'0x9ce658155a6f05fe4aef83b7fa8f431d5e8ccb55',
47+
);
48+
console.log('signing...');
49+
const txSigned2 = await k.matic.sign('vault1', txStake);
50+
console.log('broadcasting...');
51+
const hash2 = await k.matic.broadcast(txSigned2);
52+
console.log(hash2);
53+
} catch (err) {
54+
console.log(err);
55+
}
56+
};
57+
58+
f();

src/integrations/fb_signer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export class FbSigner {
5656
},
5757
note,
5858
extraParameters: payloadToSign,
59-
6059
}
6160
);
6261
return (await this.waitForTxCompletion(fbTx));

src/kiln.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { AdaService } from "./services/ada";
88
import { NearService } from "./services/near";
99
import { DotService } from "./services/dot";
1010
import { XtzService } from "./services/xtz";
11+
import { MaticService } from './services/matic';
1112

1213
type Config = {
1314
apiToken: string;
@@ -24,6 +25,7 @@ export class Kiln {
2425
near: NearService;
2526
dot: DotService;
2627
xtz: XtzService;
28+
matic: MaticService;
2729

2830
constructor({ testnet, apiToken, integrations }: Config) {
2931
api.defaults.headers.common.Authorization = `Bearer ${apiToken}`;
@@ -41,5 +43,6 @@ export class Kiln {
4143
this.near = new NearService({ testnet, integrations });
4244
this.dot = new DotService({ testnet, integrations });
4345
this.xtz = new XtzService({ testnet, integrations });
46+
this.matic = new MaticService({ testnet, integrations });
4447
}
4548
}

src/services/ada.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
AdaTx,
99
AdaTxHash,
1010
AdaTxStatus,
11-
InternalAdaConfig,
1211
} from '../types/ada';
1312
import api from '../api';
13+
import { ServiceProps } from '../types/service';
1414

1515
export class AdaService extends Service {
16-
constructor({ testnet, integrations }: InternalAdaConfig) {
16+
constructor({ testnet, integrations }: ServiceProps) {
1717
super({ testnet, integrations });
1818
}
1919

src/services/atom.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import {
77
StargateClient,
88
StdFee,
99
} from '@cosmjs/stargate';
10-
import {
11-
AtomStakeOptions,
12-
AtomTx,
13-
AtomTxStatus,
14-
InternalAtomConfig,
15-
} from '../types/atom';
10+
import { AtomStakeOptions, AtomTx, AtomTxStatus } from '../types/atom';
1611
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
1712
import { Coin, OfflineSigner } from '@cosmjs/proto-signing';
1813
import {
@@ -21,13 +16,14 @@ import {
2116
} from 'cosmjs-types/cosmos/staking/v1beta1/tx';
2217
import { AtomFbSigner } from '../integrations/atom_fb_signer';
2318
import { ADDRESSES } from '../globals';
19+
import { ServiceProps } from '../types/service';
2420

2521
const UATOM_TO_ATOM = 1000000;
2622

2723
export class AtomService extends Service {
2824
private rpc: string;
2925

30-
constructor({ testnet, integrations }: InternalAtomConfig) {
26+
constructor({ testnet, integrations }: ServiceProps) {
3127
super({ testnet, integrations });
3228
const kilnRpc = this.testnet ? 'https://rpc.sentry-02.theta-testnet.polypore.xyz' : 'https://rpc.atomscan.com';
3329
this.rpc = kilnRpc;

src/services/dot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Service } from './service';
22
import { ApiPromise, HttpProvider } from '@polkadot/api';
33
import {
4+
DotRewardDestination,
45
DotStakeOptions,
56
DotTx,
67
DotTxStatus,
7-
InternalDotConfig,
8-
DotRewardDestination,
98
SubmittedDotTx,
109
} from '../types/dot';
1110
import { DotFbSigner } from '../integrations/dot_fb_signer';
1211
import { Signer } from '@polkadot/api/types';
1312
import { SignerOptions } from '@polkadot/api/submittable/types';
1413
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
1514
import { ADDRESSES } from '../globals';
15+
import { ServiceProps } from '../types/service';
1616

1717
const DOT_TO_PLANCK = 1000000000000;
1818

@@ -23,7 +23,7 @@ const DOT_TO_PLANCK = 1000000000000;
2323
export class DotService extends Service {
2424
private rpc: string;
2525

26-
constructor({ testnet, integrations }: InternalDotConfig) {
26+
constructor({ testnet, integrations }: ServiceProps) {
2727
super({ testnet, integrations });
2828
const kilnRpc = this.testnet ? 'https://westend-rpc.polkadot.io' : 'https://rpc.polkadot.io';
2929
this.rpc = kilnRpc;

src/services/eth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import {
88
EthTx,
99
EthTxHash,
1010
EthTxStatus,
11-
InternalEthereumConfig,
1211
} from '../types/eth';
1312
import { Service } from './service';
1413
import { utils } from 'ethers';
14+
import { ServiceProps } from '../types/service';
1515

1616
export class EthService extends Service {
17-
constructor({ testnet, integrations }: InternalEthereumConfig) {
17+
constructor({ testnet, integrations }: ServiceProps) {
1818
super({ testnet, integrations });
1919
}
2020

0 commit comments

Comments
 (0)